OSDN Git Service

add rules to handle .s and .E
[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 else
12 .LIBPATTERNS: "lib%.a"
13 libs: lib-a-y
14 endif
15
16 lib-a-y: $(lib-a-y)
17 lib-so-y: $(lib-so-y)
18
19 ifneq ($(findstring s,$(MAKEFLAGS)),)
20 DISP := sil
21 Q := @
22 else
23 ifneq ($(V)$(VERBOSE),)
24 DISP := ver
25 Q := 
26 else
27 DISP := pur
28 Q := @
29 endif
30 endif
31
32 show_objs = $(subst ../,,$@)
33
34 pur_disp_compile.c = echo "  "CC $(show_objs)
35 pur_disp_compile.S = echo "  "AS $(show_objs)
36 pur_disp_compile.m = $(pur_disp_compile.c)
37 pur_disp_compile-m = echo "  "CC-m $(show_objs)
38 pur_disp_strip     = echo "  "STRIP $(STRIP_FLAGS)
39 pur_disp_ar        = echo "  "AR $(ARFLAGS) $@
40 pur_disp_ld        = echo "  "LD $($(LIB_NAME)_FULL_NAME)
41
42 sil_disp_compile.c = true
43 sil_disp_compile.S = true
44 sil_disp_compile.m = true
45 sil_disp_compile-m = true
46 sil_disp_strip     = true
47 sil_disp_ar        = true
48 sil_disp_ld        = true
49
50 ver_disp_compile.c = echo $(cmd_compile.c)
51 ver_disp_compile.S = echo $(cmd_compile.S)
52 ver_disp_compile.m = echo $(cmd_compile.m)
53 ver_disp_compile-m = echo $(cmd_compile-m)
54 ver_disp_strip     = echo $(cmd_strip)
55 ver_disp_ar        = echo $(cmd_ar)
56 ver_disp_ld        = 
57
58 disp_compile.c = $($(DISP)_disp_compile.c)
59 disp_compile.S = $($(DISP)_disp_compile.S)
60 disp_compile.m = $($(DISP)_disp_compile.m)
61 disp_compile-m = $($(DISP)_disp_compile-m)
62 disp_strip     = $($(DISP)_disp_strip)
63 disp_ar        = $($(DISP)_disp_ar)
64 disp_ld        = $($(DISP)_disp_ld)
65
66 cmd_compile.c = $(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<))
67 cmd_compile.S = $(cmd_compile.c) $(S_CPPFLAGS) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $@)) $(ASFLAGS-$(notdir $<))
68 cmd_compile.m = $(cmd_compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
69 cmd_compile-m = $(CC) $^ -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<)) $(CFLAGS-multi-y)
70 cmd_strip     = $(STRIPTOOL) $(STRIP_FLAGS) $^
71 cmd_ar        = $(AR) $(ARFLAGS) $@ $^
72
73 compile.c = @$(disp_compile.c) ; $(cmd_compile.c)
74 compile.E = $(cmd_compile.c:-c=-E)
75 compile.S = @$(disp_compile.S) ; $(cmd_compile.S)
76 compile.m = @$(disp_compile.m) ; $(cmd_compile.m)
77 compile-m = @$(disp_compile-m) ; $(cmd_compile-m)
78 do_strip  = @$(disp_strip)     ; $(cmd_strip)
79 do_ar     = @$(disp_ar)        ; $(cmd_ar)
80
81 CFLAGS-.os+=$(PICFLAG)
82 CFLAGS-.oS+=$(PICFLAG) -DSHARED
83
84 %.o: %.c
85         $(compile.c)
86 %.os: %.c
87         $(compile.c)
88 %.oS: %.c
89         $(compile.c)
90 %.o: %.S
91         $(compile.S)
92 %.os: %.S
93         $(compile.S)
94 %.o: %.s
95         $(compile.S)
96 %.os: %.s
97         $(compile.S)
98 %.E: %.c
99         $(compile.E)
100 %.E: %.S
101         $(compile.E)
102
103 #ifeq ($(HAVE_ELF),y)
104 CRT=crt1
105 #else
106 #CRT=crt0
107 #endif
108
109 ifeq ($(HAVE_SHARED),y)
110 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
111 else
112 CRTS=$(top_builddir)lib/$(CRT).o
113 endif
114
115 $(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
116         $(Q)$(INSTALL) -d $(dir $@)
117         $(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
118         @$(disp_strip) $(show_objs)
119         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
120
121 $(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
122         $(Q)$(INSTALL) -d $(dir $@)
123         $(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
124         @$(disp_strip) $(show_objs)
125         $(Q)$(STRIPTOOL) -x -R .note -R .comment $@
126
127 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
128
129 ifeq ($(UCLIBC_CTOR_DTOR),y)
130 $(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
131         $(Q)$(INSTALL) -d $(dir $@)
132         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
133
134 $(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
135         $(Q)$(INSTALL) -d $(dir $@)
136         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
137 else
138 $(CTOR_TARGETS):
139         $(Q)$(INSTALL) -d $(top_builddir)lib
140         $(do_ar)
141 endif
142
143 crt-y: $(crt-y)
144 $(crt-y): $(CRTS) $(CTOR_TARGETS)
145
146 other-y: $(other-y)
147 headers-y: $(headers-y)
148
149 objclean-y: $(objclean-y)
150 headers_clean-y: $(headers_clean-y)
151
152 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
153         $(Q)$(INSTALL) -d $(dir $@)
154         $(do_ar)
155
156 .PHONY: dummy create
157 clean: objclean-y headers_clean-y
158
159 ifeq ($(strip $(LIB_NAME)),)
160 LIB_NAME=libc
161 endif
162
163 ifeq ($(strip $($(LIB_NAME)_FULL_NAME)),)
164 $(LIB_NAME)_FULL_NAME:=$(LIB_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
165 endif
166
167 $(LIB_NAME)-SHARED_OBJS=$($(LIB_NAME)-so-y) $($(LIB_NAME)-shared-y)
168 ifeq ($(HAVE_SHARED),y)
169 shared: $($(LIB_NAME)-SHARED_OBJS)
170 else
171 shared:
172 endif
173
174 $(LIB_NAME)-ARCHIVE_OBJS=$($(LIB_NAME)-a-y) $($(LIB_NAME)-static-y)
175 ifeq ($(DOPIC),y)
176 objs: shared $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os) $(crt-y) $(other-y)
177 else
178 objs: shared $($(LIB_NAME)-ARCHIVE_OBJS) $(crt-y) $(other-y)
179 endif
180
181 libc=$(top_builddir)lib/libc.so
182 interp=$(top_builddir)libc/misc/internals/interp.os
183 ifeq ($(strip $(EXTRA_LINK_LIBS)),)
184 #EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib -lc $(LDADD_LIBFLOAT) $(LIBGCC)
185 EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib $(libc) $(LDADD_LIBFLOAT) $(LIBGCC)
186 endif
187
188 ifneq ($(strip $(LIB_NAME)),libc)
189 ifneq ($(strip $(LIB_NAME)),ld-uClibc)
190 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp) $(libc)
191 else
192 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a
193 endif
194 else
195 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp)
196 endif
197         $(Q)$(INSTALL) -d $(dir $@)
198         $(Q)$(RM) $@ $@.$(MAJOR_VERSION) $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME)
199         @$(disp_ld)
200         $(Q)$(LD) $(LDFLAGS) $(EXTRA_LINK_OPTS) -soname=$(notdir $@).$(MAJOR_VERSION) \
201                 -o $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME) $(SHARED_START_FILES) \
202                 --whole-archive $(firstword $^) --no-whole-archive \
203                 $(EXTRA_LINK_LIBS) $(SHARED_END_FILES)
204         $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@.$(MAJOR_VERSION)
205 ifneq ($(strip $(LIB_NAME)),libc)
206 ifneq ($(strip $(LIB_NAME)),ld-uClibc)
207         $(Q)$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@
208 endif
209 else
210         $(Q)echo "/* GNU ld script" > $@
211         $(Q)echo " * Use the shared library, but some functions are only in" >> $@
212         $(Q)echo " * the static library, so try that secondarily. */" >> $@
213 ifeq ($(COMPAT_ATEXIT),y)
214         $(Q)echo "GROUP ( $(NONSHARED_LIBNAME) $(SHARED_MAJORNAME) $(ASNEEDED) )" >> $@
215 else
216         $(Q)echo "GROUP ( $(SHARED_MAJORNAME) $(NONSHARED_LIBNAME) $(ASNEEDED) )" >> $@
217 endif
218 endif
219
220 $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
221         $(compile-m)
222
223 # local testing only until libc is multi-capable
224 libc_m.os: $(libc-multi-y)
225         $(compile-m)
226
227 ifneq ($(DOMULTI),n)
228
229 $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
230         $(Q)$(RM) $@
231         $(do_strip)
232         $(do_ar)
233
234 ifeq ($(DOPIC),y)
235 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-static-y:.o=.os)
236 else
237 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
238 endif
239         $(Q)$(INSTALL) -d $(dir $@)
240         $(Q)$(RM) $@
241         $(do_strip)
242         $(do_ar)
243
244 else # DOMULTI
245
246 $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
247         $(Q)$(RM) $@
248         $(do_strip)
249         $(do_ar)
250
251 ifeq ($(DOPIC),y)
252 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
253 else
254 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
255 endif
256         $(Q)$(INSTALL) -d $(dir $@)
257         $(Q)$(RM) $@
258         $(do_strip)
259         $(do_ar)
260
261 endif # DOMULTI
262
263 $(LIB_NAME)_clean:
264         $(RM) $($(LIB_NAME)_OUT)/*.{o,os,a}