OSDN Git Service

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