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