OSDN Git Service

- use the compiler-driver instead of the linker
[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.S = echo "  "AS $(show_objs)
64 pur_disp_compile.m = $(pur_disp_compile.c)
65 pur_disp_compile-m = echo "  "CC-m $(show_objs)
66 pur_disp_strip     = echo "  "STRIP $(STRIP_FLAGS) $@
67 pur_disp_t_strip   = echo "  "STRIP $(STRIP_FLAGS) $@
68 pur_disp_ar        = echo "  "AR $(ARFLAGS) $@
69 pur_disp_ld        = echo "  "LD $(1)
70
71 sil_disp_compile.c = true
72 sil_disp_compile.S = true
73 sil_disp_compile.m = true
74 sil_disp_compile-m = true
75 sil_disp_strip     = true
76 sil_disp_t_strip   = true
77 sil_disp_ar        = true
78 sil_disp_ld        = true
79
80 ver_disp_compile.c = echo $(cmd_compile.c)
81 ver_disp_compile.S = echo $(cmd_compile.S)
82 ver_disp_compile.m = echo $(cmd_compile.m)
83 ver_disp_compile-m = echo $(cmd_compile-m)
84 ver_disp_strip     = echo $(cmd_strip)
85 ver_disp_t_strip   = echo $(cmd_t_strip)
86 ver_disp_ar        = echo $(cmd_ar)
87 ver_disp_ld        = 
88
89 disp_compile.c = $($(DISP)_disp_compile.c)
90 disp_compile.S = $($(DISP)_disp_compile.S)
91 disp_compile.m = $($(DISP)_disp_compile.m)
92 disp_compile-m = $($(DISP)_disp_compile-m)
93 disp_strip     = $($(DISP)_disp_strip)
94 disp_t_strip   = $($(DISP)_disp_t_strip)
95 disp_ar        = $($(DISP)_disp_ar)
96 disp_ld        = $($(DISP)_disp_ld)
97
98 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 $@))
99 cmd_compile.S = $(cmd_compile.c) -D__ASSEMBLER__ $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $<)) $(ASFLAGS-$(notdir $@))
100 cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
101 cmd_compile-m = $(CC) $^ -c -o $@ $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $(@D))) $(CFLAGS-$(notdir $@))
102 cmd_strip     = $(STRIPTOOL) $(STRIP_FLAGS) $^
103 cmd_t_strip   = $(STRIPTOOL) $(STRIP_FLAGS) $@
104 cmd_ar        = $(AR) $(ARFLAGS) $@ $^
105
106 compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
107 compile.i = $(cmd_compile.c:-c=-E -dD)
108 compile.s = $(cmd_compile.c:-c=-S)
109 compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
110 compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
111 compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
112 do_strip  = @$(disp_strip)     ; $(cmd_strip)
113 do_t_strip= @$(disp_t_strip)   ; $(cmd_t_strip)
114 do_ar     = @$(disp_ar)        ; $(cmd_ar)
115
116 define compile.u
117         @$(disp_compile.c)
118         $(Q)$(CC) $^ $(DEPS-$(notdir $@)) -o $@ $(CFLAGS) $(CFLAGS-$(notdir $(^D))) $(CFLAGS-$(notdir $@))
119         @$(disp_strip)
120         $(Q)$(STRIPTOOL) $(STRIP_FLAGS) $@
121 endef
122 hcompile.u = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -o $@ $(BUILD_LDFLAGS) $(BUILD_LDFLAGS-$(notdir $(^D))) $(BUILD_LDFLAGS-$(notdir $@)) $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
123 hcompile.o = $(HOSTCC) $^ $(DEPS-$(notdir $@)) -c -o $@ $(BUILD_CFLAGS) $(BUILD_CFLAGS-$(notdir $(^D))) $(BUILD_CFLAGS-$(notdir $@))
124
125 define link.so
126         $(Q)$(INSTALL) -d $(dir $@)
127         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
128         @$(disp_ld)
129         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
130                 -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) \
131                 -Wl,--whole-archive $(firstword $^) -Wl,--no-whole-archive \
132                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
133         $(Q)$(LN) -sf $(1) $@.$(2)
134         $(Q)$(LN) -sf $(1) $@
135 endef
136
137 # CRT files needed by link-flat.so
138 LINK_FLAT_CRTS := $(top_builddir)lib/Scrt1.o $(top_builddir)lib/crti.o \
139         $(top_builddir)lib/crtn.o
140
141 # Create a shared flat library from the archive named by the first dependency.
142 # $@ names the shared library's .gdb file, not the flat file itself.
143 # (This is because the .gdb suffix makes the ELF file more distinctive
144 # than the suffixless flat file.)
145 #
146 # Argument 1 is the shared library file -- i.e. $(@:.gdb=) -- and argument 2
147 # is the shared library identifier.  If it wasn't for $(disp_ld), we could
148 # avoid passing $(@:.gdb=) as an argument and use $(@:.gdb=) instead of $(1).
149 define link-flat.so
150         $(Q)$(INSTALL) -d $(dir $@)
151         $(Q)$(RM) $(1) $@
152         @$(disp_ld)
153         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -nostdlib -o $(1) \
154                 -Wl,-elf2flt -Wl,-shared-lib-id $(2) $(top_builddir)lib/Scrt1.o \
155                 $(top_builddir)/lib/crti.o -Wl,--whole-archive $(firstword $^) \
156                 -Wl,--no-whole-archive $(LIBS-$(notdir $@)) $(LIBGCC) \
157                 $(top_builddir)/lib/crtn.o
158 endef
159
160 define linkm.so
161         $(Q)$(INSTALL) -d $(dir $@)
162         $(Q)$(RM) $@ $@.$(2) $(dir $@)$(1)
163         @$(disp_ld)
164         $(Q)$(CC) $(LDFLAGS-$(notdir $@)) -Wl,-soname=$(notdir $@).$(2) \
165                 -nostdlib -o $(dir $@)$(1) $(START_FILE-$(notdir $@)) $^ \
166                 $(LIBS-$(notdir $@)) $(LIBGCC) $(END_FILE-$(notdir $@))
167         $(Q)$(LN) -sf $(1) $@.$(2)
168         $(Q)$(LN) -sf $(1) $@
169 endef
170
171 CFLAGS-.os+=$(PICFLAG)
172 CFLAGS-.oS+=$(PICFLAG) -DSHARED
173
174 %.o:  %.c ; $(compile.c)
175 %.os: %.c ; $(compile.c)
176 %.oS: %.c ; $(compile.c)
177 %.o:  %.S ; $(compile.S)
178 %.os: %.S ; $(compile.S)
179 %.oS: %.S ; $(compile.S)
180 %.o:  %.s ; $(compile.S)
181 %.os: %.s ; $(compile.S)
182 %.oS: %.s ; $(compile.S)
183 %.i:  %.c ; $(compile.i)
184 %.i:  %.S ; $(compile.i)
185 %.s:  %.c ; $(compile.s)
186 %.s:  %.S ; $(compile.s)
187
188 $(top_builddir)lib/interp.c: | $(sub_headers)
189         $(Q)$(INSTALL) -d $(dir $@)
190         $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@
191         $(Q)echo "#include <features.h>" >> $@
192         $(Q)echo "const char __dl_ldso__[] __attribute__ ((section " \
193                 "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@
194
195 $(interp): $(top_builddir)lib/interp.c
196         $(compile.c)
197         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
198
199 $(ldso):
200         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
201
202 $(libc):
203         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
204
205 $(headers_dep):
206         $(Q)cd $(top_builddir); $(MAKE) headers
207
208 CRT := crt1
209
210 ifeq ($(HAVE_SHARED)$(UCLIBC_FORMAT_SHARED_FLAT),y)
211 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
212 else
213 CRTS=$(top_builddir)lib/$(CRT).o
214 endif
215
216 ASFLAGS-$(CRT).o := -DL_$(CRT)
217 ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
218 $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
219         $(Q)$(INSTALL) -d $(dir $@)
220         $(compile.S)
221         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
222
223 ifeq ($(UCLIBC_CTOR_DTOR),y)
224 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
225 else
226 CTOR_TARGETS:=
227 endif
228
229 ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
230 CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
231 $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c
232         $(compile.c)
233
234 $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
235         $(Q)sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
236                 gawk -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
237         $(Q)mv $@.tmp $@
238
239 $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
240         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
241                -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
242                -e '/@TRAILER_BEGINS/,$$p' $< > $@
243
244 $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
245         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
246                -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
247                -e '/@TRAILER_BEGINS/,$$p' $< > $@
248
249 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
250         $(Q)$(INSTALL) -d $(dir $@)
251         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
252 else
253 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
254         $(Q)$(INSTALL) -d $(dir $@)
255         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
256 endif
257
258 #ifeq ($(TARGET_ARCH),nios)
259 #CRTS_COMPAT := $(top_builddir)lib/crt0.o
260 #$(CRTS_COMPAT):
261 #       ln -fs crt1.o $(top_builddir)lib/crt0.o
262 #else
263 CRTS_COMPAT :=
264 #endif
265
266 $(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT)
267 $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT): | headers
268
269 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
270         $(Q)$(INSTALL) -d $(dir $@)
271         $(Q)$(RM) $@
272         $(do_strip)
273         $(do_ar)
274
275 $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
276         $(Q)$(INSTALL) -d $(dir $@)
277         $(Q)$(RM) $@
278         $(do_strip)
279         $(do_ar)
280
281 .PHONY: dummy create
282 clean: objclean-y headers_clean-y
283
284 objclean-y: $(objclean-y)
285 headers_clean-y: $(headers_clean-y)
286
287 .PHONY: \
288         all check clean distclean test \
289         config dist menuconfig oldconfig release \
290         subdirs utils