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

