os161.kernel.mk 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. #
  2. # OS/161 build environment: build a kernel
  3. #
  4. # Note that kernels build in kernel build directories and not into
  5. # $(BUILDDIR).
  6. #
  7. #
  8. # The makefile stub generated by the kernel config script looks like this:
  9. # KTOP=../.. # top of the kernel tree
  10. # TOP=$(KTOP)/.. # top of the whole tree
  11. # KDEBUG=-g # debug vs. optimize
  12. # CONFNAME=GENERIC # name of the kernel config file
  13. # .include "$(TOP)/mk/os161.config.mk"
  14. # .include "files.mk"
  15. # .include "$(TOP)/mk/os161.kernel.mk"
  16. #
  17. # files.mk is also generated by the kernel config script.
  18. #
  19. #
  20. # Additional defs for building a kernel.
  21. #
  22. # All sources.
  23. ALLSRCS=$(SRCS) $(SRCS.MACHINE.$(MACHINE)) $(SRCS.PLATFORM.$(PLATFORM))
  24. # Filename for the kernel.
  25. KERNEL=kernel
  26. # Don't use headers and libraries that don't belong to the kernel.
  27. # Kernels have to be standalone.
  28. KCFLAGS+=-nostdinc
  29. KLDFLAGS+=-nostdlib
  30. # Do use the kernel's header files.
  31. KCFLAGS+=-I$(KTOP)/include -I$(KTOP)/dev -I. -Iincludelinks
  32. # Tell gcc that we're building something other than an ordinary
  33. # application, so it makes fewer assumptions about standard library
  34. # functions.
  35. KCFLAGS+=-ffreestanding
  36. # Define _KERNEL so code in src/common can tell which header files
  37. # it should use.
  38. KCFLAGS+=-D_KERNEL
  39. # Added for local UW modifications
  40. KCFLAGS+=-DUW
  41. # Provide the linker with a "linker script". This is a piece of
  42. # obscure mumble that tells the linker how to put together the output
  43. # program. We need it because a kernel needs (in general) to be linked
  44. # to run at a different virtual address from an ordinary program.
  45. #
  46. # Traditionally all you need to do is pass -Ttext to set the address
  47. # for the text (code), but this doesn't work with the GNU linker by
  48. # default because of a silly design bug.
  49. #
  50. # Look for a linker script for the PLATFORM first, and if not that try
  51. # MACHINE, and if neither of those exists assume we don't actually
  52. # need one.
  53. .if exists($(KTOP)/arch/$(PLATFORM)/conf/ldscript)
  54. KLDFLAGS+=-T $(KTOP)/arch/$(PLATFORM)/conf/ldscript
  55. .elif exists($(KTOP)/arch/$(MACHINE)/conf/ldscript)
  56. KLDFLAGS+=-T $(KTOP)/arch/$(MACHINE)/conf/ldscript
  57. .endif
  58. #
  59. # This should expand to all the header files in the kernel so they can
  60. # be fed to tags.
  61. #
  62. TAGS_HEADERS=\
  63. $(KTOP)/*/*.h \
  64. $(KTOP)/include/kern/*.h \
  65. $(KTOP)/dev/*/*.h \
  66. $(KTOP)/arch/$(MACHINE)/*/*.h \
  67. $(KTOP)/arch/$(MACHINE)/include/kern/*.h \
  68. $(KTOP)/arch/$(PLATFORM)/*/*.h
  69. #
  70. # Rules.
  71. #
  72. # Default rule: link the kernel.
  73. all: includelinks .WAIT $(KERNEL)
  74. #
  75. # Here's how we link the kernel.
  76. #
  77. # vers.c/.o is generated on every build. It contains a numeric serial
  78. # number incremented every time newvers.sh is run. These values are
  79. # printed out by newvers.sh and are also displayed at boot time. This
  80. # makes it possible to tell at a glance whether you're actually
  81. # running the same kernel you just compiled.
  82. #
  83. # The version number is kept in the file called "version" in the build
  84. # directory.
  85. #
  86. # By immemorial tradition, "size" is run on the kernel after it's linked.
  87. #
  88. $(KERNEL):
  89. $(KTOP)/conf/newvers.sh $(CONFNAME)
  90. $(CC) $(KCFLAGS) -c vers.c
  91. $(LD) $(KLDFLAGS) $(OBJS) vers.o -o $(KERNEL)
  92. $(SIZE) $(KERNEL)
  93. #
  94. # Use the -M argument to gcc to get it to output dependency information.
  95. # Note that we use -M, which includes deps for #include <...> files,
  96. # rather than -MM, which doesn't. This is because we are the operating
  97. # system: the #include <...> files are part of our project -- in fact, in
  98. # the kernel they're the kernel's own include files -- and they will be
  99. # changing!
  100. #
  101. depend:
  102. $(MAKE) includelinks
  103. $(CC) $(KCFLAGS) -M $(ALLSRCS) > .depend
  104. # our make does this implicitly
  105. #.-include ".depend"
  106. #
  107. # This allows includes of the forms
  108. # <machine/foo.h>
  109. # <kern/machine/foo.h>
  110. # <platform/foo.h>
  111. # and also (for this platform/machine)
  112. # <mips/foo.h>
  113. # <kern/mips/foo.h>
  114. # <sys161/foo.h>
  115. # to go to the right place.
  116. #
  117. includelinks:
  118. mkdir includelinks
  119. mkdir includelinks/kern
  120. ln -s ../../../arch/$(MACHINE)/include includelinks/$(MACHINE)
  121. ln -s ../../../../arch/$(MACHINE)/include/kern \
  122. includelinks/kern/$(MACHINE)
  123. ln -s ../../../arch/$(PLATFORM)/include includelinks/$(PLATFORM)
  124. ln -s $(MACHINE) includelinks/machine
  125. ln -s $(MACHINE) includelinks/kern/machine
  126. ln -s $(PLATFORM) includelinks/platform
  127. #
  128. # Remove everything generated during the compile.
  129. # (To remove absolutely everything automatically generated, you can just
  130. # blow away the whole compile directory.)
  131. #
  132. clean:
  133. rm -f *.o *.a tags $(KERNEL)
  134. rm -r includelinks
  135. distclean cleandir: clean
  136. rm -f .depend
  137. #
  138. # Rerun config for this configuration.
  139. #
  140. reconfig:
  141. (cd $(KTOP)/conf && ./config $(CONFNAME))
  142. #
  143. # [ -d $(OSTREE) ] succeeds if $(OSTREE) is a directory.
  144. # (See test(1).) Thus, if $(OSTREE) doesn't exist, it will be created.
  145. #
  146. # The kernel gets installed at the top of the installed system tree.
  147. # Since with OS/161 it's relatively likely that you'll be working with
  148. # several configurations at once, it gets installed under the name of
  149. # this config, and a symbolic link with the "real" name is set up to
  150. # point to the last kernel installed.
  151. #
  152. install:
  153. [ -d $(OSTREE) ] || mkdir $(OSTREE)
  154. cp $(KERNEL) $(OSTREE)/$(KERNEL)-$(CONFNAME)
  155. -rm -f $(OSTREE)/$(KERNEL)
  156. ln -s $(KERNEL)-$(CONFNAME) $(OSTREE)/$(KERNEL)
  157. #
  158. # Run tags on all the sources and header files. This is probably not
  159. # the most useful way to do this and may need attention. (XXX?)
  160. #
  161. tags:
  162. ctags -wtd $(ALLSRCS) $(TAGS_HEADERS)
  163. #
  164. # This tells make that these rules are not files so it (hopefully)
  165. # won't become confused if files by those names appear.
  166. #
  167. .PHONY: all depend clean reconfig install tags
  168. #
  169. # Compilation rules.
  170. #
  171. .for _S_ in $(ALLSRCS)
  172. OBJS+=$(_S_:T:R).o
  173. $(_S_:T:R).o: $(_S_)
  174. $(CC) $(KCFLAGS) -c $(_S_)
  175. .endfor
  176. # Make the kernel depend on all the object files.
  177. $(KERNEL): $(OBJS)
  178. # End.