OSDN Git Service

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