OSDN Git Service

get rid of the notion of .E files as .i is the proper usage
[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 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.i = $(cmd_compile.c:-c=-E -dD)
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 %.i:  %.c ; $(compile.i)
158 %.i:  %.S ; $(compile.i)
159 %.s:  %.c ; $(compile.s)
160 %.s:  %.S ; $(compile.s)
161
162 $(top_builddir)lib/interp.c: | $(sub_headers)
163         $(Q)$(INSTALL) -d $(dir $@)
164         $(Q)echo "/* Force shared libraries to know about the correct library loader */" > $@
165         $(Q)echo "#include <features.h>" >> $@
166         $(Q)echo "const char __dl_ldso__[] __attribute__ ((section " \
167                 "(\".interp\"))) =\""$(SHARED_LIB_LOADER_PREFIX)/$(UCLIBC_LDSO)"\";" >> $@
168
169 $(interp): $(top_builddir)lib/interp.c
170         $(compile.c)
171         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
172
173 $(ldso):
174         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
175
176 $(libc):
177         @cd $(top_builddir); $(MAKE) lib/$(patsubst %.$(MAJOR_VERSION),%,$(notdir $@))
178
179 $(headers_dep):
180         $(Q)cd $(top_builddir); $(MAKE) headers
181
182 CRT := crt1
183
184 ifeq ($(HAVE_SHARED),y)
185 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
186 else
187 CRTS=$(top_builddir)lib/$(CRT).o
188 endif
189
190 ASFLAGS-$(CRT).o := -DL_$(CRT)
191 ASFLAGS-S$(CRT).o := $(PIEFLAG) -DL_S$(CRT)
192 $(CRTS): $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
193         $(Q)$(INSTALL) -d $(dir $@)
194         $(compile.S)
195         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
196
197 ifeq ($(UCLIBC_CTOR_DTOR),y)
198 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
199 else
200 CTOR_TARGETS:=
201 endif
202
203 ifneq ($(wildcard $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c),)
204 CFLAGS-initfini.s := -S -g0 $(PICFLAG) -fno-inline-functions -finhibit-size-directive
205 $(top_builddir)lib/initfini.s: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/initfini.c
206         $(compile.c)
207
208 $(top_builddir)lib/defs.h: $(top_builddir)lib/initfini.s
209         $(Q)sed -n -e '/@TESTS_BEGIN/,/@TESTS_END/p' $< | \
210                 gawk -f $(top_srcdir)extra/scripts/defs.awk > $@.tmp
211         $(Q)mv $@.tmp $@
212
213 $(top_builddir)lib/crti.S: $(top_builddir)lib/initfini.s $(top_builddir)lib/defs.h
214         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
215                -e '/@_.*_PROLOG_BEGINS/,/@_.*_PROLOG_ENDS/p' \
216                -e '/@TRAILER_BEGINS/,$$p' $< > $@
217
218 $(top_builddir)lib/crtn.S: $(top_builddir)lib/initfini.s
219         $(Q)sed -n -e '1,/@HEADER_ENDS/p' \
220                -e '/@_.*_EPILOG_BEGINS/,/@_.*_EPILOG_ENDS/p' \
221                -e '/@TRAILER_BEGINS/,$$p' $< > $@
222
223 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_builddir)lib/%.S
224         $(Q)$(INSTALL) -d $(dir $@)
225         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
226 else
227 $(CTOR_TARGETS): $(top_builddir)lib/%.o : $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/%.S
228         $(Q)$(INSTALL) -d $(dir $@)
229         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
230 endif
231
232 #ifeq ($(TARGET_ARCH),nios)
233 #CRTS_COMPAT := $(top_builddir)lib/crt0.o
234 #$(CRTS_COMPAT):
235 #       ln -fs crt1.o $(top_builddir)lib/crt0.o
236 #else
237 CRTS_COMPAT :=
238 #endif
239
240 $(crt-y): $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT)
241 $(CRTS) $(CTOR_TARGETS) $(CRTS_COMPAT): | headers
242
243 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
244         $(Q)$(INSTALL) -d $(dir $@)
245         $(Q)$(RM) $@
246         $(do_strip)
247         $(do_ar)
248
249 $(top_builddir)lib/libpthread_nonshared.a: $(libpthread-nonshared-y)
250         $(Q)$(INSTALL) -d $(dir $@)
251         $(Q)$(RM) $@
252         $(do_strip)
253         $(do_ar)
254
255 .PHONY: dummy create
256 clean: objclean-y headers_clean-y
257
258 objclean-y: $(objclean-y)
259 headers_clean-y: $(headers_clean-y)
260
261 .PHONY: \
262         all check clean distclean test \
263         config dist menuconfig oldconfig release \
264         subdirs utils