OSDN Git Service

Use consequently headers-y and headers_clean-y, try avoiding TARGET_ARCH use in main...
[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 compile.c=$(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<))
20 compile.S=$(compile.c) $(S_CPPFLAGS) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $@)) $(ASFLAGS-$(notdir $<))
21 compile.m=$(compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
22
23 compile-m=$(CC) $^ -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<)) $(CFLAGS-multi-y)
24
25 CFLAGS-.os+=$(PICFLAG)
26 CFLAGS-.oS+=$(PICFLAG) -DSHARED
27
28 %.o %.os: %.c
29         $(compile.c)
30
31 %.oS: %.c
32         $(compile.c)
33
34 %.o %.os: %.S
35         $(compile.S)
36
37 #ifeq ($(HAVE_ELF),y)
38 CRT=crt1
39 #else
40 #CRT=crt0.o
41 #endif
42
43 ifeq ($(HAVE_SHARED),y)
44 CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
45 else
46 CRTS=$(top_builddir)lib/$(CRT).o
47 endif
48
49 $(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
50         $(INSTALL) -d $(dir $@)
51         $(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
52         $(STRIPTOOL) -x -R .note -R .comment $@
53
54 $(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
55         $(INSTALL) -d $(dir $@)
56         $(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
57         $(STRIPTOOL) -x -R .note -R .comment $@
58
59 CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o
60
61 ifeq ($(UCLIBC_CTOR_DTOR),y)
62 $(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
63         $(INSTALL) -d $(dir $@)
64         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
65
66 $(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
67         $(INSTALL) -d $(dir $@)
68         $(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
69 else
70 $(CTOR_TARGETS):
71         $(INSTALL) -d $(top_builddir)lib
72         $(AR) $(ARFLAGS) $@
73 endif
74
75 crt-y: $(crt-y)
76 $(crt-y): $(CRTS) $(CTOR_TARGETS)
77
78 other-y: $(other-y)
79 headers-y: $(headers-y)
80
81 objclean-y: $(objclean-y)
82 headers_clean-y: $(headers_clean-y)
83
84 $(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
85         $(INSTALL) -d $(dir $@)
86         $(AR) $(ARFLAGS) $@ $^
87
88 .PHONY: dummy create
89 clean: objclean-y headers_clean-y
90
91 ifeq ($(strip $(LIB_NAME)),)
92 LIB_NAME=libc
93 endif
94
95 ifeq ($(strip $($(LIB_NAME)_FULL_NAME)),)
96 $(LIB_NAME)_FULL_NAME:=$(LIB_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
97 endif
98
99 $(LIB_NAME)-SHARED_OBJS=$($(LIB_NAME)-so-y) $($(LIB_NAME)-shared-y)
100 ifeq ($(HAVE_SHARED),y)
101 shared: $($(LIB_NAME)-SHARED_OBJS)
102 else
103 shared:
104 endif
105
106 $(LIB_NAME)-ARCHIVE_OBJS=$($(LIB_NAME)-a-y) $($(LIB_NAME)-static-y)
107 ifeq ($(DOPIC),y)
108 objs: shared $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os) $(crt-y) $(other-y)
109 else
110 objs: shared $($(LIB_NAME)-ARCHIVE_OBJS) $(crt-y) $(other-y)
111 endif
112
113 libc=$(top_builddir)lib/libc.so
114 interp=$(top_builddir)libc/misc/internals/interp.os
115 ifeq ($(strip $(EXTRA_LINK_LIBS)),)
116 #EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib -lc $(LDADD_LIBFLOAT) $(LIBGCC)
117 EXTRA_LINK_LIBS:=$(interp) $(libc) $(LDADD_LIBFLOAT) $(LIBGCC)
118 endif
119
120 ifneq ($(strip $(LIB_NAME)),libc)
121 ifneq ($(strip $(LIB_NAME)),ld-uClibc)
122 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp) $(libc)
123 else
124 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a
125 endif
126 else
127 $(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp)
128 endif
129         $(INSTALL) -d $(dir $@)
130         $(RM) $@ $@.$(MAJOR_VERSION) $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME)
131         $(LD) $(LDFLAGS) $(EXTRA_LINK_OPTS) -soname=$(notdir $@).$(MAJOR_VERSION) \
132                 -o $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME) $(SHARED_START_FILES) \
133                 --whole-archive $(firstword $^) --no-whole-archive \
134                 $(EXTRA_LINK_LIBS) $(SHARED_END_FILES)
135         $(LN) -sf $($(LIB_NAME)_FULL_NAME) $@.$(MAJOR_VERSION)
136 ifneq ($(strip $(LIB_NAME)),libc)
137 ifneq ($(strip $(LIB_NAME)),ld-uClibc)
138         $(LN) -sf $($(LIB_NAME)_FULL_NAME) $@
139 endif
140 else
141         echo "/* GNU ld script" > $@
142         echo " * Use the shared library, but some functions are only in" >> $@
143         echo " * the static library, so try that secondarily. */" >> $@
144 ifeq ($(UCLIBC_HAS_SSP),y)
145 ifeq ($(COMPAT_ATEXIT),y)
146         echo "GROUP ( $(top_builddir)lib/$(NONSHARED_LIBNAME) $(top_builddir)lib/$(SHARED_MAJORNAME) AS_NEEDED ( $(top_builddir)lib/$(UCLIBC_LDSO) ) )" >> $@
147 else
148         echo "GROUP ( $(top_builddir)lib/$(SHARED_MAJORNAME) $(top_builddir)lib/$(NONSHARED_LIBNAME) AS_NEEDED ( $(top_builddir)lib/$(UCLIBC_LDSO) ) )" >> $@
149 endif
150 else
151 ifeq ($(COMPAT_ATEXIT),y)
152         echo "GROUP ( $(top_builddir)lib/$(NONSHARED_LIBNAME) $(top_builddir)lib/$(SHARED_MAJORNAME) )" >> $@
153 else
154         echo "GROUP ( $(top_builddir)lib/$(SHARED_MAJORNAME) $(top_builddir)lib/$(NONSHARED_LIBNAME) )" >> $@
155 endif
156 endif
157 endif
158
159 $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
160         $(compile-m)
161
162 # local testing only until libc is multi-capable
163 libc_m.os: $(libc-multi-y)
164         $(compile-m)
165
166 ifneq ($(DOMULTI),n)
167
168 $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
169         $(RM) $@
170 ifneq ($(strip $(STRIP_FLAGS)),)
171         $(STRIPTOOL) $(STRIP_FLAGS) $^
172 else
173         $(STRIPTOOL) -x -R .note -R .comment $^
174 endif
175         $(AR) $(ARFLAGS) $@ $^
176
177 ifeq ($(DOPIC),y)
178 $(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)
179 else
180 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
181 endif
182         $(INSTALL) -d $(dir $@)
183         $(RM) $@
184         $(STRIPTOOL) -x -R .note -R .comment $^
185         $(AR) $(ARFLAGS) $@ $^
186
187 else # DOMULTI
188
189 $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
190         $(RM) $@
191 ifneq ($(strip $(STRIP_FLAGS)),)
192         $(STRIPTOOL) $(STRIP_FLAGS) $^
193 else
194         $(STRIPTOOL) -x -R .note -R .comment $^
195 endif
196         $(AR) $(ARFLAGS) $@ $^
197
198 ifeq ($(DOPIC),y)
199 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
200 else
201 $(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
202 endif
203         $(INSTALL) -d $(dir $@)
204         $(RM) $@
205         $(STRIPTOOL) -x -R .note -R .comment $^
206         $(AR) $(ARFLAGS) $@ $^
207
208 endif # DOMULTI
209
210 $(LIB_NAME)_clean:
211         rm -f $($(LIB_NAME)_OUT)/*.{o,os,a}