OSDN Git Service

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