OSDN Git Service

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