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

