Rules.make
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:9k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. #
  2. # This file contains rules which are shared between multiple Makefiles.
  3. #
  4. #
  5. # False targets.
  6. #
  7. .PHONY: dummy
  8. #
  9. # Special variables which should not be exported
  10. #
  11. unexport EXTRA_AFLAGS
  12. unexport EXTRA_CFLAGS
  13. unexport EXTRA_LDFLAGS
  14. unexport EXTRA_ARFLAGS
  15. unexport SUBDIRS
  16. unexport SUB_DIRS
  17. unexport ALL_SUB_DIRS
  18. unexport MOD_SUB_DIRS
  19. unexport O_TARGET
  20. unexport ALL_MOBJS
  21. unexport obj-y
  22. unexport obj-m
  23. unexport obj-n
  24. unexport obj-
  25. unexport export-objs
  26. unexport subdir-y
  27. unexport subdir-m
  28. unexport subdir-n
  29. unexport subdir-
  30. comma := ,
  31. EXTRA_CFLAGS_nostdinc := $(EXTRA_CFLAGS) $(kbuild_2_4_nostdinc)
  32. #
  33. # Get things started.
  34. #
  35. first_rule: sub_dirs
  36. $(MAKE) all_targets
  37. both-m          := $(filter $(mod-subdirs), $(subdir-y))
  38. SUB_DIRS := $(subdir-y)
  39. MOD_SUB_DIRS := $(sort $(subdir-m) $(both-m))
  40. ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-m) $(subdir-n) $(subdir-))
  41. #
  42. # Common rules
  43. #
  44. %.s: %.c
  45. $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -S $< -o $@
  46. %.i: %.c
  47. $(CPP) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) $< > $@
  48. %.o: %.c
  49. $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -c -o $@ $<
  50. @ ( 
  51.     echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@))))' ; 
  52.     echo 'FILES_FLAGS_UP_TO_DATE += $@' ; 
  53.     echo 'endif' 
  54. ) > $(dir $@)/.$(notdir $@).flags
  55. %.o: %.s
  56. $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
  57. # Old makefiles define their own rules for compiling .S files,
  58. # but these standard rules are available for any Makefile that
  59. # wants to use them.  Our plan is to incrementally convert all
  60. # the Makefiles to these standard rules.  -- rmk, mec
  61. ifdef USE_STANDARD_AS_RULE
  62. %.s: %.S
  63. $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
  64. %.o: %.S
  65. $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
  66. endif
  67. %.lst: %.c
  68. $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -g -c -o $*.o $<
  69. $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
  70. #
  71. #
  72. #
  73. all_targets: $(O_TARGET) $(L_TARGET)
  74. #
  75. # Rule to compile a set of .o files into one .o file
  76. #
  77. ifdef O_TARGET
  78. $(O_TARGET): $(obj-y)
  79. rm -f $@
  80.     ifneq "$(strip $(obj-y))" ""
  81. $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
  82.     else
  83. $(AR) rcs $@
  84.     endif
  85. @ ( 
  86.     echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; 
  87.     echo 'FILES_FLAGS_UP_TO_DATE += $@' ; 
  88.     echo 'endif' 
  89. ) > $(dir $@)/.$(notdir $@).flags
  90. endif # O_TARGET
  91. #
  92. # Rule to compile a set of .o files into one .a file
  93. #
  94. ifdef L_TARGET
  95. $(L_TARGET): $(obj-y)
  96. rm -f $@
  97. $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
  98. @ ( 
  99.     echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; 
  100.     echo 'FILES_FLAGS_UP_TO_DATE += $@' ; 
  101.     echo 'endif' 
  102. ) > $(dir $@)/.$(notdir $@).flags
  103. endif
  104. #
  105. # This make dependencies quickly
  106. #
  107. fastdep: dummy
  108. $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -- $(wildcard *.[chS]) > .depend
  109. ifdef ALL_SUB_DIRS
  110. $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
  111. endif
  112. ifdef _FASTDEP_ALL_SUB_DIRS
  113. $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
  114. $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
  115. endif
  116. #
  117. # A rule to make subdirectories
  118. #
  119. subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
  120. sub_dirs: dummy $(subdir-list)
  121. ifdef SUB_DIRS
  122. $(subdir-list) : dummy
  123. $(MAKE) -C $(patsubst _subdir_%,%,$@)
  124. endif
  125. #
  126. # A rule to make modules
  127. #
  128. ALL_MOBJS = $(filter-out $(obj-y), $(obj-m))
  129. ifneq "$(strip $(ALL_MOBJS))" ""
  130. MOD_DESTDIR := $(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh)
  131. endif
  132. unexport MOD_DIRS
  133. MOD_DIRS := $(MOD_SUB_DIRS) $(MOD_IN_SUB_DIRS)
  134. ifneq "$(strip $(MOD_DIRS))" ""
  135. .PHONY: $(patsubst %,_modsubdir_%,$(MOD_DIRS))
  136. $(patsubst %,_modsubdir_%,$(MOD_DIRS)) : dummy
  137. $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules
  138. .PHONY: $(patsubst %,_modinst_%,$(MOD_DIRS))
  139. $(patsubst %,_modinst_%,$(MOD_DIRS)) : dummy
  140. $(MAKE) -C $(patsubst _modinst_%,%,$@) modules_install
  141. endif
  142. .PHONY: modules
  143. modules: $(ALL_MOBJS) dummy 
  144.  $(patsubst %,_modsubdir_%,$(MOD_DIRS))
  145. .PHONY: _modinst__
  146. _modinst__: dummy
  147. ifneq "$(strip $(ALL_MOBJS))" ""
  148. mkdir -p $(MODLIB)/kernel/$(MOD_DESTDIR)
  149. cp $(sort $(ALL_MOBJS)) $(MODLIB)/kernel/$(MOD_DESTDIR)
  150. endif
  151. .PHONY: modules_install
  152. modules_install: _modinst__ 
  153.  $(patsubst %,_modinst_%,$(MOD_DIRS))
  154. #
  155. # A rule to do nothing
  156. #
  157. dummy:
  158. #
  159. # This is useful for testing
  160. #
  161. script:
  162. $(SCRIPT)
  163. #
  164. # This sets version suffixes on exported symbols
  165. # Separate the object into "normal" objects and "exporting" objects
  166. # Exporting objects are: all objects that define symbol tables
  167. #
  168. ifdef CONFIG_MODULES
  169. multi-used := $(filter $(list-multi), $(obj-y) $(obj-m))
  170. multi-objs := $(foreach m, $(multi-used), $($(basename $(m))-objs))
  171. active-objs := $(sort $(multi-objs) $(obj-y) $(obj-m))
  172. ifdef CONFIG_MODVERSIONS
  173. ifneq "$(strip $(export-objs))" ""
  174. MODINCL = $(TOPDIR)/include/linux/modules
  175. # The -w option (enable warnings) for genksyms will return here in 2.1
  176. # So where has it gone?
  177. #
  178. # Added the SMP separator to stop module accidents between uniprocessor
  179. # and SMP Intel boxes - AC - from bits by Michael Chastain
  180. #
  181. ifdef CONFIG_SMP
  182. genksyms_smp_prefix := -p smp_
  183. else
  184. genksyms_smp_prefix := 
  185. endif
  186. $(MODINCL)/%.ver: %.c
  187. @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then 
  188. echo '$(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $<'; 
  189. echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; 
  190. $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $< 
  191. | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; 
  192. if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; 
  193. else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; 
  194. fi; touch $(MODINCL)/$*.stamp
  195. $(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
  196. # updates .ver files but not modversions.h
  197. fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
  198. # updates .ver files and modversions.h like before (is this needed?)
  199. dep: fastdep update-modverfile
  200. endif # export-objs 
  201. # update modversions.h, but only if it would change
  202. update-modverfile:
  203. @(echo "#ifndef _LINUX_MODVERSIONS_H";
  204.   echo "#define _LINUX_MODVERSIONS_H"; 
  205.   echo "#include <linux/modsetver.h>"; 
  206.   cd $(TOPDIR)/include/linux/modules; 
  207.   for f in *.ver; do 
  208.     if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; 
  209.   done; 
  210.   echo "#endif"; 
  211. ) > $(TOPDIR)/include/linux/modversions.h.tmp
  212. @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then 
  213. echo $(TOPDIR)/include/linux/modversions.h was not updated; 
  214. rm -f $(TOPDIR)/include/linux/modversions.h.tmp; 
  215. else 
  216. echo $(TOPDIR)/include/linux/modversions.h was updated; 
  217. mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; 
  218. fi
  219. $(active-objs): $(TOPDIR)/include/linux/modversions.h
  220. else
  221. $(TOPDIR)/include/linux/modversions.h:
  222. @echo "#include <linux/modsetver.h>" > $@
  223. endif # CONFIG_MODVERSIONS
  224. ifneq "$(strip $(export-objs))" ""
  225. $(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
  226. $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
  227. @ ( 
  228.     echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; 
  229.     echo 'FILES_FLAGS_UP_TO_DATE += $@' ; 
  230.     echo 'endif' 
  231. ) > $(dir $@)/.$(notdir $@).flags
  232. endif
  233. endif # CONFIG_MODULES
  234. #
  235. # include dependency files if they exist
  236. #
  237. ifneq ($(wildcard .depend),)
  238. include .depend
  239. endif
  240. ifneq ($(wildcard $(TOPDIR)/.hdepend),)
  241. include $(TOPDIR)/.hdepend
  242. endif
  243. #
  244. # Find files whose flags have changed and force recompilation.
  245. # For safety, this works in the converse direction:
  246. #   every file is forced, except those whose flags are positively up-to-date.
  247. #
  248. FILES_FLAGS_UP_TO_DATE :=
  249. # For use in expunging commas from flags, which mung our checking.
  250. comma = ,
  251. FILES_FLAGS_EXIST := $(wildcard .*.flags)
  252. ifneq ($(FILES_FLAGS_EXIST),)
  253. include $(FILES_FLAGS_EXIST)
  254. endif
  255. FILES_FLAGS_CHANGED := $(strip 
  256.     $(filter-out $(FILES_FLAGS_UP_TO_DATE), 
  257. $(O_TARGET) $(L_TARGET) $(active-objs) 
  258. ))
  259. # A kludge: .S files don't get flag dependencies (yet),
  260. #   because that will involve changing a lot of Makefiles.  Also
  261. #   suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
  262. #   This allows handling of assembly files that get translated into
  263. #   multiple object files (see arch/ia64/lib/idiv.S, for example).
  264. FILES_FLAGS_CHANGED := $(strip 
  265.     $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), 
  266.     $(FILES_FLAGS_CHANGED)))
  267. ifneq ($(FILES_FLAGS_CHANGED),)
  268. $(FILES_FLAGS_CHANGED): dummy
  269. endif