makefile.common

  1. # This is part of a GNU Makefile, included by the Makefiles in
  2. # each of the subdirectories.  
  3. #
  4. # The dependency graph between assignments is:
  5. #   1. THREADS before everything else
  6. #   2. USERPROG must come before VM
  7. #   3. USERPROG can come before or after FILESYS, but if USERPROG comes 
  8. # before (as in this distribution), then it must define FILESYS_STUB
  9. #
  10. # Other than that, you have complete flexibility.
  11. # The Makefiles for nachos have been pretty much completely re-worked
  12. # for the Waterloo environment.  The re-work centers around supporting
  13. # multiple architectures (MIPS and SPARC) simultaneously and automatically,
  14. # and completely automatic dependency generation; both of which make 
  15. # heavy use of advanced features of GNU Make.
  16. # To build nachos, you should only have to type 'make' in the appropriate
  17. # directory.  You can type make in the toplevel nachos/code directory and
  18. # build all versions of nachos, but this will probably blow your diskquota.
  19. # To build nachos user programs, you should just have to type 'make' in
  20. # the nachos/code/test directory.
  21. # See the files */Makefile and */Makefile.local for how to re-order the
  22. # assignments, and how to add new source files.
  23. # You might want to play with the CFLAGS, but if you use -O it may
  24. # break the thread system.  You might want to use -fno-inline if
  25. # you need to call some inline functions from the debugger.
  26. # Copyright (c) 1992 The Regents of the University of California.
  27. # All rights reserved. See copyright.h for copyright notice and limitation 
  28. # of liability and disclaimer of warranty provisions.
  29. ifndef MAKEFILE_COMMON
  30. define MAKEFILE_COMMON
  31. yes
  32. endef
  33. # Makefile.dep is where most machine/architecture dependent stuff
  34. # should go.
  35. include ../Makefile.dep
  36. # vpath tells gnu make where to look for certain files, as determined
  37. # by the target pattern, if it cannot find them in the current directory.
  38. vpath %.cc  ../network:../filesys:../vm:../userprog:../threads:../machine
  39. vpath %.h   ../network:../filesys:../vm:../userprog:../threads:../machine
  40. vpath %.s   ../network:../filesys:../vm:../userprog:../threads:../machine
  41. CFLAGS = -g -Wall -Wshadow -fwritable-strings $(INCPATH) $(DEFINES) $(HOST) -DCHANGED
  42. # The variables {C,S,CC}FILES should be initialized by the Makefile
  43. # that invokes this makefile.  The ofiles variable is used in building
  44. # the different versions of nachos corresponding to each assignment; it
  45. # is not used by the Makefiles for the bin or test directories.
  46.  
  47. s_ofiles = $(SFILES:%.s=$(obj_dir)/%.o)
  48. c_ofiles = $(CFILES:%.c=$(obj_dir)/%.o)
  49. cc_ofiles = $(CCFILES:%.cc=$(obj_dir)/%.o)
  50. ofiles = $(cc_ofiles) $(c_ofiles) $(s_ofiles) 
  51. program = $(bin_dir)/nachos
  52. # Unless the invoking Makefile defines a target before including
  53. # Makefile.common (this file), then the following target will be the
  54. # default.
  55. $(program): $(ofiles)
  56. #
  57. # rules for building various sorts of files
  58. #
  59. # Executables: We know a file is an executable by the file prefix
  60. # $(bin_dir).  This rule specifies how to build the executable, but it 
  61. # does not specify the dependencies.  The dependencies are specified
  62. # elsewhere.  When gmake has multiple rules for a given target, it
  63. # combines the dependencies as if they all came from one rule; thus,
  64. # the $^ macro in the command below refers to dependencies of this target
  65. # as specified by the other rules.  Also note that only one of the rules
  66. # for a given target may include commands to build the target.
  67. $(bin_dir)/% :
  68. @echo ">>> Linking" $@ "<<<"
  69. $(LD) $^ $(LDFLAGS) -o $@
  70. ln -sf $@ $(notdir $@)
  71. # Building object files (.o) from C++ source (.cc) files.
  72. # See the comment above for executables regarding multiple rules.
  73. $(obj_dir)/%.o: %.cc
  74. @echo ">>> Compiling" $< "<<<"
  75. $(CC) $(CFLAGS) -c -o $@ $<
  76. # Building object files (.o) from C source (.c) files.
  77. # See the comment above for executables regarding multiple rules.
  78. $(obj_dir)/%.o: %.c
  79. @echo ">>> Compiling" $< "<<<"
  80. $(CC) $(CFLAGS) -c -o $@ $<
  81. # Building object files (.o) from assembly source (.s) files.
  82. #
  83. # We run assembly files through the C pre-processor, before passing
  84. # them on to the assembler.
  85. #
  86. # See the comment above for executables regarding multiple rules.
  87. $(obj_dir)/%.o: %.s
  88. @echo ">>> Assembling" $< "<<<"
  89. $(CPP) $(CPPFLAGS) $< > $(obj_dir)/tmp.s
  90. $(AS) -o $@ $(obj_dir)/tmp.s
  91. rm $(obj_dir)/tmp.s
  92. # Automatic dependency generation: see gmake info documentation for
  93. # full details.  This stuff supercedes the old make depend stuff.
  94. # We want to build a .d file for every source file (.s, .c, .cc), which
  95. # contains make rules generated automatically by gcc/cpp.  The .d files
  96. # are to be included later in this Makefile.
  97. s_dfiles = $(SFILES:%.s=$(depends_dir)/%.d)
  98. c_dfiles = $(CFILES:%.c=$(depends_dir)/%.d)
  99. cc_dfiles = $(CCFILES:%.cc=$(depends_dir)/%.d)
  100. dfiles = $(cc_dfiles) $(c_dfiles) $(s_dfiles) 
  101. # The following set of rules define how to build dependency files
  102. # automatically from various source files.  These rules have been
  103. # taken from the gmake documentation with minor modifications.
  104. $(depends_dir)/%.d: %.cc
  105. @echo ">>> Building dependency file for " $< "<<<"
  106. @$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< 
  107. | sed '''s@$*.o[ ]*:@$(depends_dir)/$(notdir $@) $(obj_dir)/&@g''' > $@'
  108. $(depends_dir)/%.d: %.c
  109. @echo ">>> Building dependency file for" $< "<<<"
  110. @$(SHELL) -ec '$(CC) -MM $(CFLAGS) $< 
  111. | sed '''s@$*.o[ ]*:@$(depends_dir)/$(notdir $@) $(obj_dir)/&@g''' > $@'
  112. $(depends_dir)/%.d: %.s
  113. @echo ">>> Building dependency file for" $< "<<<"
  114. @$(SHELL) -ec '$(CPP) -MM $(CPPFLAGS) $< 
  115. | sed '''s@$*.o[ ]*:@$(depends_dir)/$(notdir $@) $(obj_dir)/&@g''' > $@'
  116. # Include the generated dependency files.  Note gnu make treats these
  117. # files in a special way.  Each of them is treated as a sort of
  118. # target.  If for example, one of the .d files in $(dfiles) depends on
  119. # a .c file that has been re-compiled, the above rules will cause the
  120. # .d file to be re-generated.  GNU make will detect this, and re-read
  121. # the makefiles again so that any changes from the .c file are
  122. # correctly reflected by the dependency graph.
  123. # The short of it is that this Makefile will automatically infer the complete
  124. # up-to-date dependencies between .{c,cc,s} files and .h files.
  125. include $(dfiles)
  126. # Clean out all generated files.  Note: this only cleans the files
  127. # corresponding to the current architecture.  
  128. # Also note, there is quirk when you do two make clean's in a row, or 
  129. # rather, make clean on an already clean directory.
  130. # Because of the way the dependency stuff above works, before doing the
  131. # second clean, GNU make will regenerate dependency information, which
  132. # was removed by the first clean.  Finally, the second clean will remove
  133. # the dependency information it just created... blech.
  134. clean:
  135. rm -f `find $(arch_dir) -type f -print | egrep -v '(CVS|cvsignore)'`
  136. rm -f nachos coff2noff coff2flat
  137. rm -f *.noff *.flat
  138. tmpclean:
  139. rm -f tmp*
  140. endif # MAKEFILE_COMMON
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值