Eric Andersen | 4bcdd72 | 2001-10-24 05:26:42 +0000 | [diff] [blame] | 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 | # |
| 13 | unexport EXTRA_AFLAGS |
| 14 | unexport EXTRA_CFLAGS |
| 15 | unexport EXTRA_LDFLAGS |
| 16 | unexport EXTRA_ARFLAGS |
| 17 | unexport SUBDIRS |
| 18 | unexport SUB_DIRS |
| 19 | unexport ALL_SUB_DIRS |
| 20 | unexport O_TARGET |
| 21 | |
| 22 | unexport obj-y |
| 23 | unexport obj-n |
| 24 | unexport obj- |
| 25 | unexport export-objs |
| 26 | unexport subdir-y |
| 27 | unexport subdir-n |
| 28 | unexport subdir- |
| 29 | |
| 30 | # |
| 31 | # Get things started. |
| 32 | # |
| 33 | first_rule: sub_dirs |
| 34 | $(MAKE) all_targets |
| 35 | |
| 36 | SUB_DIRS := $(subdir-y) |
| 37 | ALL_SUB_DIRS := $(sort $(subdir-y) $(subdir-n) $(subdir-)) |
| 38 | |
| 39 | |
| 40 | # |
| 41 | # Common rules |
| 42 | # |
| 43 | |
| 44 | %.s: %.c |
| 45 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -S $< -o $@ |
| 46 | |
| 47 | %.i: %.c |
| 48 | $(CPP) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) $< > $@ |
| 49 | |
| 50 | %.o: %.c |
| 51 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -c -o $@ $< |
| 52 | @ ( \ |
| 53 | echo 'ifeq ($(strip $(subst $(comma),:,$(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@))),$$(strip $$(subst $$(comma),:,$$(CFLAGS) $$(EXTRA_CFLAGS) $$(CFLAGS_$@))))' ; \ |
| 54 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ |
| 55 | echo 'endif' \ |
| 56 | ) > $(dir $@)/.$(notdir $@).flags |
| 57 | |
| 58 | %.o: %.s |
| 59 | $(AS) $(AFLAGS) $(EXTRA_CFLAGS) -o $@ $< |
| 60 | |
| 61 | # Old makefiles define their own rules for compiling .S files, |
| 62 | # but these standard rules are available for any Makefile that |
| 63 | # wants to use them. Our plan is to incrementally convert all |
| 64 | # the Makefiles to these standard rules. -- rmk, mec |
| 65 | ifdef USE_STANDARD_AS_RULE |
| 66 | |
| 67 | %.s: %.S |
| 68 | $(CPP) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) $< > $@ |
| 69 | |
| 70 | %.o: %.S |
| 71 | $(CC) $(AFLAGS) $(EXTRA_AFLAGS) $(AFLAGS_$@) -c -o $@ $< |
| 72 | |
| 73 | endif |
| 74 | |
| 75 | %.lst: %.c |
| 76 | $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $< |
| 77 | $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP) |
| 78 | # |
| 79 | # |
| 80 | # |
| 81 | all_targets: $(O_TARGET) $(L_TARGET) |
| 82 | |
| 83 | # |
| 84 | # Rule to compile a set of .o files into one .o file |
| 85 | # |
| 86 | ifdef O_TARGET |
| 87 | $(O_TARGET): $(obj-y) |
| 88 | rm -f $@ |
| 89 | ifneq "$(strip $(obj-y))" "" |
| 90 | $(LD) $(EXTRA_LDFLAGS) -r -o $@ $(filter $(obj-y), $^) |
| 91 | else |
| 92 | $(AR) rcs $@ |
| 93 | endif |
| 94 | @ ( \ |
| 95 | echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_LDFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_LDFLAGS) $$(obj-y))))' ; \ |
| 96 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ |
| 97 | echo 'endif' \ |
| 98 | ) > $(dir $@)/.$(notdir $@).flags |
| 99 | endif # O_TARGET |
| 100 | |
| 101 | # |
| 102 | # Rule to compile a set of .o files into one .a file |
| 103 | # |
| 104 | ifdef L_TARGET |
| 105 | $(L_TARGET): $(obj-y) |
| 106 | rm -f $@ |
| 107 | $(AR) $(EXTRA_ARFLAGS) rcs $@ $(obj-y) |
| 108 | @ ( \ |
| 109 | echo 'ifeq ($(strip $(subst $(comma),:,$(EXTRA_ARFLAGS) $(obj-y))),$$(strip $$(subst $$(comma),:,$$(EXTRA_ARFLAGS) $$(obj-y))))' ; \ |
| 110 | echo 'FILES_FLAGS_UP_TO_DATE += $@' ; \ |
| 111 | echo 'endif' \ |
| 112 | ) > $(dir $@)/.$(notdir $@).flags |
| 113 | endif |
| 114 | |
| 115 | |
| 116 | # |
| 117 | # This make dependencies quickly |
| 118 | # |
| 119 | fastdep: dummy |
| 120 | $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend |
| 121 | ifdef ALL_SUB_DIRS |
| 122 | $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)" |
| 123 | endif |
| 124 | |
| 125 | ifdef _FASTDEP_ALL_SUB_DIRS |
| 126 | $(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)): |
| 127 | $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep |
| 128 | endif |
| 129 | |
| 130 | |
| 131 | # |
| 132 | # A rule to make subdirectories |
| 133 | # |
| 134 | subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS))) |
| 135 | sub_dirs: dummy $(subdir-list) |
| 136 | |
| 137 | ifdef SUB_DIRS |
| 138 | $(subdir-list) : dummy |
| 139 | $(MAKE) -C $(patsubst _subdir_%,%,$@) |
| 140 | endif |
| 141 | |
| 142 | # |
| 143 | # A rule to do nothing |
| 144 | # |
| 145 | dummy: |
| 146 | |
| 147 | # |
| 148 | # This is useful for testing |
| 149 | # |
| 150 | script: |
| 151 | $(SCRIPT) |
| 152 | |
| 153 | # |
| 154 | # include dependency files if they exist |
| 155 | # |
| 156 | ifneq ($(wildcard .depend),) |
| 157 | include .depend |
| 158 | endif |
| 159 | |
| 160 | ifneq ($(wildcard $(TOPDIR)/.hdepend),) |
| 161 | include $(TOPDIR)/.hdepend |
| 162 | endif |
| 163 | |
| 164 | # |
| 165 | # Find files whose flags have changed and force recompilation. |
| 166 | # For safety, this works in the converse direction: |
| 167 | # every file is forced, except those whose flags are positively up-to-date. |
| 168 | # |
| 169 | FILES_FLAGS_UP_TO_DATE := |
| 170 | |
| 171 | # For use in expunging commas from flags, which mung our checking. |
| 172 | comma = , |
| 173 | |
| 174 | FILES_FLAGS_EXIST := $(wildcard .*.flags) |
| 175 | ifneq ($(FILES_FLAGS_EXIST),) |
| 176 | include $(FILES_FLAGS_EXIST) |
| 177 | endif |
| 178 | |
| 179 | FILES_FLAGS_CHANGED := $(strip \ |
| 180 | $(filter-out $(FILES_FLAGS_UP_TO_DATE), \ |
| 181 | $(O_TARGET) $(L_TARGET) $(active-objs) \ |
| 182 | )) |
| 183 | |
| 184 | # A kludge: .S files don't get flag dependencies (yet), |
| 185 | # because that will involve changing a lot of Makefiles. Also |
| 186 | # suppress object files explicitly listed in $(IGNORE_FLAGS_OBJS). |
| 187 | # This allows handling of assembly files that get translated into |
| 188 | # multiple object files (see arch/ia64/lib/idiv.S, for example). |
| 189 | FILES_FLAGS_CHANGED := $(strip \ |
| 190 | $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \ |
| 191 | $(FILES_FLAGS_CHANGED))) |
| 192 | |
| 193 | ifneq ($(FILES_FLAGS_CHANGED),) |
| 194 | $(FILES_FLAGS_CHANGED): dummy |
| 195 | endif |