RHEL3/Rules.make History
<<
>>
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_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) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^)
 100    else
 101        $(AR) rcs $@
 102    endif
 103        @ ( \
 104            echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(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#
 219ifdef CONFIG_SMP
 220        genksyms_smp_prefix := -p smp_
 221else
 222        genksyms_smp_prefix := 
 223endif
 224
 225# Override separator for different PAGE_OFFSET memory models - Ingo.
 226ifdef CONFIG_2GB
 227ifdef CONFIG_SMP
 228        genksyms_smp_prefix := -p smp_2gig_
 229else
 230        genksyms_smp_prefix := -p 2gig_
 231endif
 232endif
 233ifdef CONFIG_1GB
 234ifdef CONFIG_SMP
 235        genksyms_smp_prefix := -p smp_1gig_
 236else
 237        genksyms_smp_prefix := -p 1gig_
 238endif
 239endif
 240
 241$(MODINCL)/%.ver: %.c
 242        @if [ ! -r $(MODINCL)/$*.stamp -o $(MODINCL)/$*.stamp -ot $< ]; then \
 243                echo '$(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $<'; \
 244                echo '| $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp'; \
 245                $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -E -D__GENKSYMS__ $< \
 246                | $(GENKSYMS) $(genksyms_smp_prefix) -k $(VERSION).$(PATCHLEVEL).$(SUBLEVEL) > $@.tmp; \
 247                if [ -r $@ ] && cmp -s $@ $@.tmp; then echo $@ is unchanged; rm -f $@.tmp; \
 248                else echo mv $@.tmp $@; mv -f $@.tmp $@; fi; \
 249        fi; touch $(MODINCL)/$*.stamp
 250        
 251$(addprefix $(MODINCL)/,$(export-objs:.o=.ver)): $(TOPDIR)/include/linux/autoconf.h
 252
 253# updates .ver files but not modversions.h
 254fastdep: $(addprefix $(MODINCL)/,$(export-objs:.o=.ver))
 255
 256# updates .ver files and modversions.h like before (is this needed?)
 257dep: fastdep update-modverfile
 258
 259endif # export-objs 
 260
 261# update modversions.h, but only if it would change
 262update-modverfile:
 263        @(echo "#ifndef _LINUX_MODVERSIONS_H";\
 264          echo "#define _LINUX_MODVERSIONS_H"; \
 265          echo "#include <linux/modsetver.h>"; \
 266          cd $(TOPDIR)/include/linux/modules; \
 267          for f in *.ver; do \
 268            if [ -f $$f ]; then echo "#include <linux/modules/$${f}>"; fi; \
 269          done; \
 270          echo "#endif"; \
 271        ) > $(TOPDIR)/include/linux/modversions.h.tmp
 272        @if [ -r $(TOPDIR)/include/linux/modversions.h ] && cmp -s $(TOPDIR)/include/linux/modversions.h $(TOPDIR)/include/linux/modversions.h.tmp; then \
 273                echo $(TOPDIR)/include/linux/modversions.h was not updated; \
 274                rm -f $(TOPDIR)/include/linux/modversions.h.tmp; \
 275        else \
 276                echo $(TOPDIR)/include/linux/modversions.h was updated; \
 277                mv -f $(TOPDIR)/include/linux/modversions.h.tmp $(TOPDIR)/include/linux/modversions.h; \
 278        fi
 279
 280$(active-objs): $(TOPDIR)/include/linux/modversions.h
 281
 282else
 283
 284$(TOPDIR)/include/linux/modversions.h:
 285        @echo "#include <linux/modsetver.h>" > $@
 286
 287endif # CONFIG_MODVERSIONS
 288
 289ifneq "$(strip $(export-objs))" ""
 290$(export-objs): $(export-objs:.o=.c) $(TOPDIR)/include/linux/modversions.h
 291        $(CC) $(CFLAGS) $(EXTRA_CFLAGS_nostdinc) -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) $(CFLAGS_$@) -DEXPORT_SYMTAB -c $(@:.o=.c)
 292        @ ( \
 293            echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS_nostdinc) $(CFLAGS_$@) -DEXPORT_SYMTAB)),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS_nostdinc) $$(CFLAGS_$@) -DEXPORT_SYMTAB)))' ; \
 294            echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \
 295            echo 'endif' \
 296        ) > $(dir $@)/.$(notdir $@).flags
 297endif
 298
 299endif # CONFIG_MODULES
 300
 301
 302#
 303# include dependency files if they exist
 304#
 305ifneq ($(wildcard .depend),)
 306include .depend
 307endif
 308
 309#
 310# Find files whose flags have changed and force recompilation.
 311# For safety, this works in the converse direction:
 312#   every file is forced, except those whose flags are positively up-to-date.
 313#
 314FILES_FLAGS_UP_TO_DATE :=
 315
 316# For use in expunging commas from flags, which mung our checking.
 317comma = ,
 318
 319FILES_FLAGS_EXIST := $(wildcard .*.flags)
 320ifneq ($(FILES_FLAGS_EXIST),)
 321include $(FILES_FLAGS_EXIST)
 322endif
 323
 324FILES_FLAGS_CHANGED := $(strip \
 325    $(filter-out $(FILES_FLAGS_UP_TO_DATE), \
 326        $(O_TARGET) $(L_TARGET) $(active-objs) \
 327        ))
 328
 329# A kludge: .S files don't get flag dependencies (yet),
 330#   because that will involve changing a lot of Makefiles.  Also
 331#   suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS).
 332#   This allows handling of assembly files that get translated into
 333#   multiple object files (see arch/ia64/lib/idiv.S, for example).
 334FILES_FLAGS_CHANGED := $(strip \
 335    $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
 336    $(FILES_FLAGS_CHANGED)))
 337
 338ifneq ($(FILES_FLAGS_CHANGED),)
 339$(FILES_FLAGS_CHANGED): dummy
 340endif
 341