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#
  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 $@
  76ifneq "$(strip $(ALL_O))" ""
  77        $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(ALL_O)
  78else
  79        $(AR) rcs $@
  80endif
  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#
 207#       Differ 1 and 2Gig kernels to avoid module misload errors
 208#
 209
 210ifdef CONFIG_2GB
 211ifdef CONFIG_SMP
 212        genksyms_smp_prefix := -p smp2gig_
 213else
 214        genksyms_smp_prefix := -p 2gig_
 215endif
 216endif
 217
 218$(MODINCL)/%.ver: %.c
 219        @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
 220                echo '$(CC) $(CFLAGS) -E -D__GENKSYMS__ $<'; \
 221                echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
 222                $(CC) $(CFLAGS) -E -D__GENKSYMS__ $< \
 223                | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
 224                if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
 225                else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
 226        fi; touch $(MODINCL)/$*.stamp
 227        
 228$(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
 229
 230$(TOPDIR)/include/linux/modversions.h: $(addprefix $(MODINCL)/,$(SYMTAB_OBJS:.o=.ver))
 231        @echo updating $(TOPDIR)/include/linux/modversions.h
 232        @(echo "#ifndef _LINUX_MODVERSIONS_H";\
 233          echo "#define _LINUX_MODVERSIONS_H"; \
 234          echo "#include <linux/modsetver.h>"; \
 235          cd $(TOPDIR)/include/linux/modules; \
 236          for f in *.ver; do \
 237            if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
 238          done; \
 239          echo "#endif"; \
 240        ) > $@
 241
 242dep fastdep: $(TOPDIR)/include/linux/modversions.h
 243
 244endif # SYMTAB_OBJS 
 245
 246$(M_OBJS): $(TOPDIR)/include/linux/modversions.h
 247ifdef MAKING_MODULES
 248$(O_OBJS) $(L_OBJS): $(TOPDIR)/include/linux/modversions.h
 249endif
 250
 251else
 252
 253$(TOPDIR)/include/linux/modversions.h:
 254        @echo "#include <linux/modsetver.h>" > $@
 255
 256endif # CONFIG_MODVERSIONS
 257
 258ifneq "$(strip $(SYMTAB_OBJS))" ""
 259$(SYMTAB_OBJS): $(TOPDIR)/include/linux/modversions.h $(SYMTAB_OBJS:.o=.c)
 260        $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
 261        @ ( \
 262            echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
 263            echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
 264            echo 'endif' \
 265        ) > $(dir $@)/.$(notdir $@).flags
 266endif
 267
 268endif # CONFIG_MODULES
 269
 270
 271#
 272# include dependency files if they exist
 273#
 274ifneq ($(wildcard .depend),)
 275include .depend
 276endif
 277
 278ifneq ($(wildcard $(TOPDIR)/.hdepend),)
 279include $(TOPDIR)/.hdepend
 280endif
 281
 282#
 283# Find files whose flags have changed and force recompilation.
 284# For safety, this works in the converse direction:
 285#   every file is forced, except those whose flags are positively up-to-date.
 286#
 287FILES_FLAGS_UP_TO_DATE :=
 288
 289# For use in expunging commas from flags, which mung our checking.
 290comma = ,
 291
 292FILES_FLAGS_EXIST := $(wildcard .*.flags)
 293ifneq ($(FILES_FLAGS_EXIST),)
 294include $(FILES_FLAGS_EXIST)
 295endif
 296
 297FILES_FLAGS_CHANGED := $(strip \
 298    $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
 299        $(O_TARGET) $(O_OBJS) $(OX_OBJS) \
 300        $(L_TARGET) $(L_OBJS) $(LX_OBJS) \
 301        $(M_OBJS) $(MX_OBJS) \
 302        $(MI_OBJS) $(MIX_OBJS) \
 303        ))
 304
 305# A kludge: .S files don't get flag dependencies (yet),
 306#   because that will involve changing a lot of Makefiles.
 307FILES_FLAGS_CHANGED := $(strip \
 308    $(filter-out $(patsubst %.S, %.o, $(wildcard *.S)), \
 309    $(FILES_FLAGS_CHANGED)))
 310
 311ifneq ($(FILES_FLAGS_CHANGED),)
 312$(FILES_FLAGS_CHANGED): dummy
 313endif
 314
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.