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_ASFLAGS 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 O_OBJS 23unexport L_OBJS 24unexport M_OBJS 25# intermediate objects that form part of a module 26unexport MI_OBJS 27unexport ALL_MOBJS 28# objects that export symbol tables 29unexport OX_OBJS 30unexport LX_OBJS 31unexport MX_OBJS 32unexport MIX_OBJS 33unexport SYMTAB_OBJS 34 35unexport MOD_LIST_NAME 36 37# 38# Get things started. 39# 40first_rule: sub_dirs 41 $(MAKE) all_targets 42 43# 44# Common rules 45# 46 47%.s: %.c 48 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@ 49 50%.i: %.c 51 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -E $< > $@ 52 53%.o: %.c 54 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $< 55 @ ( \ 56 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \ 57 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ 58 echo 'endif' \ 59 ) > $(dir $@)/.$(notdir $@).flags 60 61%.o: %.s 62 $(AS) $(ASFLAGS) $(EXTRA_CFLAGS) -o $@ $< 63 64# 65# 66# 67all_targets: $(O_TARGET) $(L_TARGET) 68 69# 70# Rule to compile a set of .o files into one .o file 71# 72ifdef O_TARGET 73ALL_O = $(OX_OBJS) $(O_OBJS) 74$(O_TARGET): $(ALL_O) 75 rm -f $@ 76 ifneq "$(strip $(ALL_O))" "" 77 $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(ALL_O), $^) 78 else 79 $(AR) rcs $@ $(filter $(ALL_O), $^) 80 endif 81 @ ( \ 82 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(ALL_O))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(ALL_O))))' ; \ 83 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ 84 echo 'endif' \ 85 ) > $(dir $@)/.$(notdir $@).flags 86endif # O_TARGET 87 88# 89# Rule to compile a set of .o files into one .a file 90# 91ifdef L_TARGET 92$(L_TARGET): $(LX_OBJS) $(L_OBJS) 93 rm -f $@ 94 $(AR) $(EXTRA_ARFLAGS) rcs $@ $(LX_OBJS) $(L_OBJS) 95 @ ( \ 96 echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(LX_OBJS) $(L_OBJS))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(LX_OBJS) $$(L_OBJS))))' ; \ 97 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ 98 echo 'endif' \ 99 ) > $(dir $@)/.$(notdir $@).flags 100endif 101 102# 103# This make dependencies quickly 104# 105fastdep: dummy 106 $(TOPDIR)/scripts/mkdep $(wildcard *.[chS] local.h.master) > .depend 107ifdef ALL_SUB_DIRS 108 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)" 109endif 110 111ifdef _FASTDEP_ALL_SUB_DIRS 112$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)): 113 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep 114endif 115 116 117# 118# A rule to make subdirectories 119# 120sub_dirs: dummy $(patsubst %,_subdir_%,$(SUB_DIRS)) 121 122ifdef SUB_DIRS 123$(patsubst %,_subdir_%,$(SUB_DIRS)) : dummy 124 $(MAKE) -C $(patsubst _subdir_%,%,$@) 125endif 126 127# 128# A rule to make modules 129# 130ALL_MOBJS = $(MX_OBJS) $(M_OBJS) 131ifneq "$(strip $(ALL_MOBJS))" "" 132PDWN=$(shell $(CONFIG_SHELL) $(TOPDIR)/scripts/pathdown.sh) 133endif 134 135ifdef MOD_SUB_DIRS 136$(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) : dummy 137 $(MAKE) -C $(patsubst _modsubdir_%,%,$@) modules 138endif 139 140ifdef MOD_IN_SUB_DIRS 141$(patsubst %,_modinsubdir_%,$(MOD_IN_SUB_DIRS)) : dummy 142 $(MAKE) -C $(patsubst _modinsubdir_%,%,$@) modules 143endif 144 145modules: $(ALL_MOBJS) $(MIX_OBJS) $(MI_OBJS) dummy \ 146 $(patsubst %,_modsubdir_%,$(MOD_SUB_DIRS)) \ 147 $(patsubst %,_modinsubdir_%,$(MOD_IN_SUB_DIRS)) 148ifneq "$(strip $(MOD_LIST_NAME))" "" 149 rm -f $$TOPDIR/modules/$(MOD_LIST_NAME) 150ifdef MOD_SUB_DIRS 151 for i in $(MOD_SUB_DIRS); do \ 152 echo `basename $$i`.o >> $$TOPDIR/modules/$(MOD_LIST_NAME); done 153endif 154ifneq "$(strip $(ALL_MOBJS))" "" 155 echo $(ALL_MOBJS) >> $$TOPDIR/modules/$(MOD_LIST_NAME) 156endif 157ifneq "$(strip $(MOD_TO_LIST))" "" 158 echo $(MOD_TO_LIST) >> $$TOPDIR/modules/$(MOD_LIST_NAME) 159endif 160endif 161ifneq "$(strip $(ALL_MOBJS))" "" 162 echo $(PDWN) 163 cd $$TOPDIR/modules; for i in $(ALL_MOBJS); do \ 164 ln -sf ../$(PDWN)/$$i $$i; done 165endif 166 167# 168# A rule to do nothing 169# 170dummy: 171 172# 173# This is useful for testing 174# 175script: 176 $(SCRIPT) 177 178# 179# This sets version suffixes on exported symbols 180# Uses SYMTAB_OBJS 181# Separate the object into "normal" objects and "exporting" objects 182# Exporting objects are: all objects that define symbol tables 183# 184ifdef CONFIG_MODULES 185 186SYMTAB_OBJS = $(LX_OBJS) $(OX_OBJS) $(MX_OBJS) $(MIX_OBJS) 187 188ifdef CONFIG_MODVERSIONS 189ifneq "$(strip $(SYMTAB_OBJS))" "" 190 191MODINCL = $(TOPDIR)/include/linux/modules 192 193# The -w option (enable warnings) for genksyms will return here in 2.1 194# So where has it gone? 195# 196# Added the SMP separator to stop module accidents between uniprocessor 197# and SMP Intel boxes - AC - from bits by Michael Chastain 198# 199 200ifdef CONFIG_SMP 201 genksyms_smp_prefix := -p smp_ 202else 203 genksyms_smp_prefix := 204endif 205 206$(MODINCL)/%.ver: %.c 207 @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \ 208 echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \ 209 echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \ 210 $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \ 211 | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \ 212 if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \ 213 else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \ 214 fi; touch $(MODINCL)/$*.stamp 215 216$(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h 217 218$(TOPDIR)/include/linux/modversions.h: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)) 219 @echo updating $(TOPDIR)/include/linux/modversions.h 220 @(echo "#ifndef _LINUX_MODVERSIONS_H";\ 221 echo "#define _LINUX_MODVERSIONS_H"; \ 222 echo "#include <linux/modsetver.h>"; \ 223 cd $(TOPDIR)/include/linux/modules; \ 224 for f in *.ver; do \ 225 if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \ 226 done; \ 227 echo "#endif"; \ 228 ) > $@ 229 230dep fastdep: $(TOPDIR)/include/linux/modversions.h 231 232endif # SYMTAB_OBJS 233 234$(M_OBJS): $(TOPDIR)/include/linux/modversions.h 235ifdef MAKING_MODULES 236$(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h 237endif 238 239else 240 241$(TOPDIR)/include/linux/modversions.h: 242 @echo "#include <linux/modsetver.h>" > $@ 243 244endif # CONFIG_MODVERSIONS 245 246ifneq "$(strip $(SYMTAB_OBJS))" "" 247$(SYMTAB_OBJS): $(TOPDIR)/include/linux/modversions.h $(SYMTAB_OBJS:.o=.c) 248 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c) 249 @ ( \ 250 echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \ 251 echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ 252 echo 'endif' \ 253 ) > $(dir $@)/.$(notdir $@).flags 254endif 255 256endif # CONFIG_MODULES 257 258 259# 260# include dependency files if they exist 261# 262ifneq ($(wildcard .depend),) 263include .depend 264endif 265 266ifneq ($(wildcard $(TOPDIR)/.hdepend),) 267include $(TOPDIR)/.hdepend 268endif 269 270# 271# Find files whose flags have changed and force recompilation. 272# For safety, this works in the converse direction: 273# every file is forced, except those whose flags are positively up-to-date. 274# 275FILES_FLAGS_UP_TO_DATE := 276 277# For use in expunging commas from flags, which mung our checking. 278comma = , 279 280FILES_FLAGS_EXIST := $(wildcard .*.flags) 281ifneq ($(FILES_FLAGS_EXIST),) 282include $(FILES_FLAGS_EXIST) 283endif 284 285FILES_FLAGS_CHANGED := $(strip \ 286 $(filter-out $(FILES_FLAGS_UP_TO_DATE), \ 287 $(O_TARGET) $(O_OBJS) $(OX_OBJS) \ 288 $(L_TARGET) $(L_OBJS) $(LX_OBJS) \ 289 $(M_OBJS) $(MX_OBJS) \ 290 $(MI_OBJS) $(MIX_OBJS) \ 291 )) 292 293# A kludge: .S files don't get flag dependencies (yet), 294# because that will involve changing a lot of Makefiles. 295FILES_FLAGS_CHANGED := $(strip \ 296 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S)), \ 297 $(FILES_FLAGS_CHANGED))) 298 299ifneq ($(FILES_FLAGS_CHANGED),) 300$(FILES_FLAGS_CHANGED): dummy 301endif 302

