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