OSDN Git Service

- strip the targets and not prerequisites
[uclinux-h8/uClibc.git] / Makerules
1 #
2 # Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
3 #
4
5 .SUFFIXES: .c .S .o .os .oS .so .a .s .i
6
7 PHONY := FORCE
8 # order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
9 ifeq ($(HAVE_SHARED),y)
10 .LIBPATTERNS: "lib%.so"
11 libs: $(lib-so-y) $(lib-a-y)
12 $(lib-so-y): $(interp)
13 else
14 .LIBPATTERNS: "lib%.a"
15 ifeq ($(UCLIBC_FORMAT_SHARED_FLAT),y)
16 libs: $(lib-gdb-y)
17 endif
18 libs: $(lib-a-y)
19 endif
20 objs: all_objs
21
22 shared_objs =  $(ldso-y) $(libc-y:.o=.os) $(libc-shared-y) $(libc-nonshared-y) $(libdl-so-y)
23 shared_objs += $(libcrypt-so-y) $(libintl-so-y) $(libm-so-y) $(libnsl-so-y) $(libpthread-so-y) $(libpthread-nonshared-y)
24 shared_objs += $(libthread_db-so-y) $(libresolv-so-y) $(librt-so-y) $(libutil-so-y)
25 ar_objs =  $(libc-y) $(libc-static-y) $(libdl-a-y) $(libcrypt-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y)
26 ar_objs += $(libpthread-a-y) $(libthread_db-a-y) $(libresolv-a-y) $(librt-a-y) $(libutil-a-y)
27 ifeq ($(DOPIC),y)
28 ar_objs := $(ar_objs:.o=.os)
29 endif
30
31 ifeq ($(HAVE_SHARED),y)
32 all_objs: $(sort $(shared_objs) $(ar_objs))
33 else
34 all_objs: $(ar_objs)
35 endif
36 $(shared_objs) $(ar_objs): | $(sub_headers)
37
38 headers-y: $(headers-y)
39         @true
40
41 MAKEFLAGS += --no-print-directory
42 SHELL_SET_X := set +x
43 ifneq ($(findstring s,$(MAKEFLAGS)),)
44 export MAKE_IS_SILENT := y
45 SECHO := -@false
46 DISP := sil
47 Q := @
48 else
49 export MAKE_IS_SILENT := n
50 SECHO := @echo
51 ifneq ($(V)$(VERBOSE),)
52 SHELL_SET_X := set -x
53 DISP := ver
54 Q :=
55 else
56 DISP := pur
57 Q := @
58 endif
59 endif
60
61 show_objs = $(subst ../,,$@)
62
63 pur_disp_compile.c = echo "  "CC $(show_objs)
64 pur_disp_compile.i = echo "  "CPP $(show_objs)
65 pur_disp_compile.s = echo "  "CC-S $(show_objs)
66 pur_disp_compile.u = echo "  "CC $(show_objs)
67 pur_disp_compile.S = echo "  "AS $(show_objs)
68 pur_disp_compile.m = $(pur_disp_compile.c)
69 pur_disp_compile-m = echo "  "CC-m $(show_objs)
70 pur_disp_strip     = echo "  "STRIP $(STRIP_FLAGS) $@
71 pur_disp_t_strip   = echo "  "STRIP $(STRIP_FLAGS) $@
72 pur_disp_ar        = echo "  "AR $(ARFLAGS) $@
73 pur_disp_ld        = echo "  "LD $(1)
74
75 sil_disp_compile.c = true
76 sil_disp_compile.i = true
77 sil_disp_compile.s = true
78 sil_disp_compile.u = true
79 sil_disp_compile.S = true
80 sil_disp_compile.m = true
81 sil_disp_compile-m = true
82 sil_disp_strip     = true
83 sil_disp_t_strip   = true
84 sil_disp_ar        = true
85 sil_disp_ld        = true
86
87 ver_disp_compile.c = echo $(cmd_compile.c)
88 ver_disp_compile.i = echo $(cmd_compile.i)
89 ver_disp_compile.s = echo $(cmd_compile.s)
90 ver_disp_compile.u = echo $(cmd_compile.u)
91 ver_disp_compile.S = echo $(cmd_compile.S)
92 ver_disp_compile.m = echo $(cmd_compile.m)
93 ver_disp_compile-m = echo $(cmd_compile-m)
94 ver_disp_strip     = echo $(cmd_strip)
95 ver_disp_t_strip   = echo $(cmd_t_strip)
96 ver_disp_ar        = echo $(cmd_ar)
97 ver_disp_ld        =
98
99 disp_compile.c = $($(DISP)_disp_compile.c)
100 disp_compile.i = $($(DISP)_disp_compile.i)
101 disp_compile.s = $($(DISP)_disp_compile.s)
102 disp_compile.u = $($(DISP)_disp_compile.u)
103 disp_compile.S = $($(DISP)_disp_compile.S)
104 disp_compile.m = $($(DISP)_disp_compile.m)
105 disp_compile-m = $($(DISP)_disp_compile-m)
106 disp_strip     = $($(DISP)_disp_strip)
107 disp_t_strip   = $($(DISP)_disp_t_strip)
108 disp_ar        = $($(DISP)_disp_ar)
109 disp_ld        = $($(DISP)_disp_ld)
110
111 any-prereq = $(filter-out $(PHONY),$?) $(filter-out $(PHONY) $(wildcard $^),$^)
112
113 # True if not identical. Neither order nor whitespace nor identical flags
114 # matter.
115 compare_flags = $(strip $(filter-out $(cmd_$(1)), $(cmd_$(@))) \
116                         $(filter-out $(cmd_$(@)), $(cmd_$(1))))
117
118 # Rebuild if any prerequisite, the used CC or flags changed.
119 # Previously used flags are stored in the corresponding .%.dep files
120 maybe_exec = $(if $(strip $(compare_flags) $(any-prereq)), \
121                 @set -e; \
122                 $(disp_$(1)); \
123                 $(cmd_$(1)); \
124                 echo 'cmd_$@ := $(cmd_$1)' >> $(dir $@).$(notdir $@).dep)
125
126 CFLAGS_gen.dep = -MT $@ -MD -MP -MF $(dir $@).$(notdir $@).dep
127
128 cmd_compile.c = $(CC) -c $< -o $@ $(CFLAGS) $(ARCH_CFLAGS) \
129         $(CFLAGS-$(suffix $@)) \
130         $(filter-out $(CFLAGS-OMIT-$(notdir $<)),$(CFLAGS-$(notdir $(<D)))) \
131         $(CFLAGS-$(subst $(top_srcdir),,$(dir $<))) \
132         $(CFLAGS-$(notdir $<)) \
133         $(CFLAGS-$(notdir $@)) \
134         $(CFLAGS_gen.dep)
135 cmd_compile.i = $(cmd_compile.c:-c=-E -dD)
136 cmd_compile.s = $(cmd_compile.c:-c=-S)
137 cmd_compile.u = $(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@)) $(CFLAGS_gen.dep)
138 cmd_compile.S = $(filter-out -std=gnu99, $(cmd_compile.c)) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
139 cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
140
141 cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@))
142 cmd_strip     = $(STRIPTOOL) $(STRIP_FLAGS) $^
143 cmd_t_strip   = $(STRIPTOOL) $(STRIP_FLAGS) $@
144 cmd_ar        = $(AR) $(ARFLAGS) $@ $^
145
146 compile.c = @$(call maybe_exec,compile.c)
147 compile.i =  $(call maybe_exec,compile.i)
148 compile.s =  $(call maybe_exec,compile.s)
149 compile.S = @$(call maybe_exec,compile.S)
150 compile.m = @$(call maybe_exec,compile.m)
151 compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
152 do_strip  = @$(disp_strip)     ; $(cmd_strip)
153 do_t_strip= @$(disp_t_strip)   ; $(cmd_t_strip)
154 do_ar     = @$(disp_ar)        ; $(cmd_ar)
155
156 define compile.u
157         @$(disp_compile.u) ; $(cmd_compile.u)
158         @$(disp_t_strip)
159 endef
160 hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
161 hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
162
163 define link.so
164         $(Q)$(INSTALL) -d $(dir $@)
165         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
166         @$(disp_ld)
167         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
168                 $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
169                 -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \
170                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
171         $(Q)$(LN) -sf $(1) $@.$(2)
172         $(Q)$(LN) -sf $(1) $@
173 endef
174
175 # CRT files needed by link-flat.so
176 LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \
177         $(top_builddir)lib/crtn.o
178
179 # Create a shared flat library from the archive named by the first dependency.
180 # $@ names the shared library's .gdb file, not the flat file itself.
181 # (This is because the .gdb suffix makes the ELF file more distinctive
182 # than the suffixless flat file.)
183 #
184 # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2
185 # is the shared library identifier.  If it wasn't for $(disp_ld), we could
186 # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1).
187 #
188 # This is so far only used for libc, for which we want to link the entire
189 # libgcc into the shared object.
190 define link-flat.so
191         $(Q)$(INSTALL) -d $(dir $@)
192         $(Q)$(RM) $(1) $@
193         @$(disp_ld)
194         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) $(NOSTDLIB_CFLAGS) -o $(1) \
195                 -Wl,-elf2flt -Wl,-shared-lib-id,$(2) $(top_builddir)lib/Scrt1.o \
196                 $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \
197                 $(LIBGCC) -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \
198                 $(top_builddir)/lib/crtn.o
199 endef
200
201 define linkm.so
202         $(Q)$(INSTALL) -d $(dir $@)
203         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
204         @$(disp_ld)
205         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
206                 $(NOSTDLIB_CFLAGS) -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
207                 $^ \
208                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
209         $(Q)$(LN) -sf $(1) $@.$(2)
210         $(Q)$(LN) -sf $(1) $@
211 endef
212
213 CFLAGS-.os+=$(PICFLAG)
214 CFLAGS-.oS+=$(PICFLAG) -DSHARED
215
216 %.o:  %.c FORCE ; $(compile.c)
217 %.os: %.c FORCE ; $(compile.c)
218 %.oS: %.c FORCE ; $(compile.c)
219 %.o:  %.S FORCE ; $(compile.S)
220 %.os: %.S FORCE ; $(compile.S)
221 %.oS: %.S FORCE ; $(compile.S)
222 %.o:  %.s FORCE ; $(compile.S)
223 %.os: %.s FORCE ; $(compile.S)
224 %.oS: %.s FORCE ; $(compile.S)
225 %.i:  %.c FORCE ; $(compile.i)
226 %.i:  %.S FORCE ; $(compile.i)
227 %.s:  %.c FORCE ; $(compile.s)
228 %.s:  %.S FORCE ; $(compile.s)
229
230 $(top_builddir)lib/interp.c: | $(sub_headers)
231         $(Q)$(INSTALL) -d $(dir $@)
232         $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@
233         $(Q)echo "#include <features.h>" >> $@
234         $(Q)echo "const char __dl_ldso__[] __attribute__ ((section " \
235                 "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@
236
237 $(interp): $(top_builddir)lib/interp.c
238         $(compile.c)
239         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
240
241 $(ldso):
242         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
243
244 $(libc):
245         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
246
247 $(headers_dep): $(top_srcdir)extra/scripts/gen_bits_syscall_h.sh
248         $(Q)cd $(top_builddir); $(MAKE) pregen
249
250 CRT := crt1
251
252 ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y)
253 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
254 else
255 CRTS=$(top_builddir)lib/$(CRT).o
256 endif
257
258 ASFLAGS-$(CRT).o := -DL_$(CRT)
259 ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
260 $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
261         $(Q)$(INSTALL) -d $(dir $@)
262         $(compile.S)
263         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
264
265 ifeq ($(UCLIBC_CTOR_DTOR),y)
266 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
267 else
268 CTOR_TARGETS:=
269 endif
270
271 ifeq ($(UCLIBC_FORMAT_FDPIC_ELF),y)
272 CRTRELOC=$(top_builddir)lib/crtreloc.o
273 $(CRTRELOC): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.c
274         $(Q)$(INSTALL) -d $(dir $@)
275         $(compile.c)
276 endif
277
278 ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
279 CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
280 $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c
281         $(compile.c)
282
283 $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
284         $(Q)sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
285                 gawk -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
286         $(Q)mv $@.tmp $@
287
288 $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
289         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
290                 -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
291                 -e '/@TRAILER_BEGINS/,$$p' $< > $@
292
293 $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
294         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
295                 -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
296                 -e '/@TRAILER_BEGINS/,$$p' $< > $@
297
298 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
299         $(Q)$(INSTALL) -d $(dir $@)
300         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
301 else
302 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
303         $(Q)$(INSTALL) -d $(dir $@)
304         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
305 endif
306
307 #ifeq ($(TARGET_ARCH),nios)
308 #CRTS_COMPAT := $(top_builddir)lib/crt0.o
309 #$(CRTS_COMPAT):
310 #       ln -fs crt1.o $(top_builddir)lib/crt0.o
311 #else
312 CRTS_COMPAT :=
313 #endif
314
315 $(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC)
316 $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT) $(CRTRELOC): | headers
317
318 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
319         $(Q)$(INSTALL) -d $(dir $@)
320         $(Q)$(RM) $@
321         $(do_ar)
322         $(do_t_strip)
323
324 $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
325         $(Q)$(INSTALL) -d $(dir $@)
326         $(Q)$(RM) $@
327         $(do_ar)
328         $(do_t_strip)
329
330 files.dep := $(libc-a-y) $(libc-so-y) $(libc-nonshared-y) \
331         $(libm-a-y) $(libm-so-y) \
332         $(libpthread-a-y) $(libpthread-so-y) $(libpthread-nonshared-y) \
333         $(libthread_db-a-y) $(libthread_db-so-y) \
334         $(librt-a-y) $(librt-so-y)  $(libresolv-a-y) $(libresolv-so-y) \
335         $(libcrypt-a-y) $(libcrypt-so-y) $(libutil-a-y) $(libutil-so-y) \
336         $(libnsl-a-y) $(libnsl-so-y) $(ldso-y) $(libdl-a-y) $(libdl-so-y)
337 .depends.dep := \
338         $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \
339         $(patsubst %.os,%.os.dep,$(filter %.os,$(files.dep))) \
340         $(patsubst %.oS,%.oS.dep,$(filter %.oS,$(files.dep)))
341 # Oh, and prepend a dot to the basename so i don't have to change my habit of
342 # calling 'size thefile.o*'
343 .depends.dep := $(foreach f,$(.depends.dep),$(dir $(f)).$(notdir $(f)))
344 .depends.dep := $(wildcard $(.depends.dep))
345
346 ifneq ($(strip $(.depends.dep)),)
347 -include $(.depends.dep)
348 endif
349
350 .PHONY: dummy $(PHONY)
351 FORCE:
352
353 clean: objclean-y headers_clean-y
354 realclean: clean
355         $(Q)$(RM) $(.depends.dep)
356
357 objclean-y: $(objclean-y)
358 headers_clean-y: $(headers_clean-y)
359
360 .PHONY: \
361         all check clean realclean distclean test \
362         config dist menuconfig oldconfig release \
363         subdirs utils