2 # This file contains rules which are shared between multiple Makefiles.
11 # Special variables which should not be exported
15 unexport EXTRA_LDFLAGS
16 unexport EXTRA_ARFLAGS
36 SUB_DIRS := $(subdir-y)
37 ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-n) $(subdir-))
45 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@
48 $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@
51 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $<
53 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \
54 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
56 ) > $(dir $@)/.$(notdir $@).flags
59 $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $<
61 # Old makefiles define their own rules for compiling .S files,
62 # but these standard rules are available for any Makefile that
63 # wants to use them. Our plan is to incrementally convert all
64 # the Makefiles to these standard rules. -- rmk, mec
65 ifdef USE_STANDARD_AS_RULE
68 $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@
71 $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $<
76 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
77 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
81 all_targets: $(O_TARGET) $(L_TARGET)
84 # Rule to compile a set of .o files into one .o file
89 ifneq "$(strip $(obj-y))" ""
90 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
95 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \
96 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
98 ) > $(dir $@)/.$(notdir $@).flags
102 # Rule to compile a set of .o files into one .a file
105 $(L_TARGET): $(obj-y)
107 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y)
109 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \
110 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
112 ) > $(dir $@)/.$(notdir $@).flags
117 # This make dependencies quickly
120 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend
122 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
125 ifdef _FASTDEP_ALL_SUB_DIRS
126 $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
127 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
132 # A rule to make subdirectories
134 subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
135 sub_dirs: dummy $(subdir-list)
138 $(subdir-list) : dummy
139 $(MAKE) -C $(patsubst _subdir_%,%,$@)
143 # A rule to do nothing
148 # This is useful for testing
154 # include dependency files if they exist
156 ifneq ($(wildcard .depend),)
160 ifneq ($(wildcard $(TOPDIR)/.hdepend),)
161 include $(TOPDIR)/.hdepend
165 # Find files whose flags have changed and force recompilation.
166 # For safety, this works in the converse direction:
167 # every file is forced, except those whose flags are positively up-to-date.
169 FILES_FLAGS_UP_TO_DATE :=
171 # For use in expunging commas from flags, which mung our checking.
174 FILES_FLAGS_EXIST := $(wildcard .*.flags)
175 ifneq ($(FILES_FLAGS_EXIST),)
176 include $(FILES_FLAGS_EXIST)
179 FILES_FLAGS_CHANGED := $(strip \
180 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
181 $(O_TARGET) $(L_TARGET) $(active-objs) \
184 # A kludge: .S files don't get flag dependencies (yet),
185 # because that will involve changing a lot of Makefiles. Also
186 # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
187 # This allows handling of assembly files that get translated into
188 # multiple object files (see arch/ia64/lib/idiv.S, for example).
189 FILES_FLAGS_CHANGED := $(strip \
190 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
191 $(FILES_FLAGS_CHANGED)))
193 ifneq ($(FILES_FLAGS_CHANGED),)
194 $(FILES_FLAGS_CHANGED): dummy