OSDN Git Service

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