OSDN Git Service

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