blob: a6f1116958c7622dad62e697956f9386c3a9c045 [file] [log] [blame]
Eric Andersen4bcdd722001-10-24 05:26:42 +00001#
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 O_TARGET
21
22unexport obj-y
23unexport obj-n
24unexport obj-
25unexport export-objs
26unexport subdir-y
27unexport subdir-n
28unexport subdir-
29
30#
31# Get things started.
32#
33first_rule: sub_dirs
34 $(MAKE) all_targets
35
36SUB_DIRS := $(subdir-y)
37ALL_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
65ifdef 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
73endif
74
75%.lst: %.c
76 $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CFLAGS_$@) -g -c -o $*.o $<
77 $(TOPDIR)/scripts/makelst $* $(TOPDIR) $(OBJDUMP)
78#
79#
80#
81all_targets: $(O_TARGET) $(L_TARGET)
82
83#
84# Rule to compile a set of .o files into one .o file
85#
86ifdef 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
99endif # O_TARGET
100
101#
102# Rule to compile a set of .o files into one .a file
103#
104ifdef 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
113endif
114
115
116#
117# This make dependencies quickly
118#
119fastdep: dummy
120 $(TOPDIR)/scripts/mkdep $(CFLAGS) $(EXTRA_CFLAGS) -- $(wildcard *.[chS]) > .depend
121ifdef ALL_SUB_DIRS
122 $(MAKE) $(patsubst %,_sfdep_%,$(ALL_SUB_DIRS)) _FASTDEP_ALL_SUB_DIRS="$(ALL_SUB_DIRS)"
123endif
124
125ifdef _FASTDEP_ALL_SUB_DIRS
126$(patsubst %,_sfdep_%,$(_FASTDEP_ALL_SUB_DIRS)):
127 $(MAKE) -C $(patsubst _sfdep_%,%,$@) fastdep
128endif
129
130
131#
132# A rule to make subdirectories
133#
134subdir-list = $(sort $(patsubst %,_subdir_%,$(SUB_DIRS)))
135sub_dirs: dummy $(subdir-list)
136
137ifdef SUB_DIRS
138$(subdir-list) : dummy
139 $(MAKE) -C $(patsubst _subdir_%,%,$@)
140endif
141
142#
143# A rule to do nothing
144#
145dummy:
146
147#
148# This is useful for testing
149#
150script:
151 $(SCRIPT)
152
153#
154# include dependency files if they exist
155#
156ifneq ($(wildcard .depend),)
157include .depend
158endif
159
160ifneq ($(wildcard $(TOPDIR)/.hdepend),)
161include $(TOPDIR)/.hdepend
162endif
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#
169FILES_FLAGS_UP_TO_DATE :=
170
171# For use in expunging commas from flags, which mung our checking.
172comma = ,
173
174FILES_FLAGS_EXIST := $(wildcard .*.flags)
175ifneq ($(FILES_FLAGS_EXIST),)
176include $(FILES_FLAGS_EXIST)
177endif
178
179FILES_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).
189FILES_FLAGS_CHANGED := $(strip \
190 $(filter-out $(patsubst %.S, %.o, $(wildcard *.S) $(IGNORE_FLAGS_OBJS)), \
191 $(FILES_FLAGS_CHANGED)))
192
193ifneq ($(FILES_FLAGS_CHANGED),)
194$(FILES_FLAGS_CHANGED): dummy
195endif