summaryrefslogtreecommitdiff
path: root/Makerules
blob: 6ab90394db4726c266466f783986a55afeb524cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#
# Licensed under LGPL v2.1, see the file COPYING.LIB in this tarball for details.
#

.SUFFIXES: .c .S .o .os .oS .so .a .s .i

# order is important, the stripping uses STRIP_FLAGS for lib-so, but not for lib-a
ifeq ($(HAVE_SHARED),y)
.LIBPATTERNS: "lib%.so"
libs: lib-so-y lib-a-y
else
.LIBPATTERNS: "lib%.a"
libs: lib-a-y
endif

lib-a-y: $(lib-a-y)
lib-so-y: $(lib-so-y)

compile.c=$(CC) -c $< -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<))
compile.S=$(compile.c) $(S_CPPFLAGS) $(ASFLAGS) $(ARCH_ASFLAGS) $(ASFLAGS-$(suffix $@)) $(ASFLAGS-$(notdir $@)) $(ASFLAGS-$(notdir $<))
compile.m=$(compile.c) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))

compile-m=$(CC) $^ -c -o $@ $(CPPFLAGS) $(CFLAGS) $(ARCH_CFLAGS) $(CFLAGS-$(suffix $@)) $(CFLAGS-$(notdir $@)) $(CFLAGS-$(notdir $<)) $(CFLAGS-multi-y)

CFLAGS-.os+=$(PICFLAG)
CFLAGS-.oS+=$(PICFLAG) -DSHARED

%.o %.os: %.c
	$(compile.c)

%.oS: %.c
	$(compile.c)

%.o %.os: %.S
	$(compile.S)

#ifeq ($(HAVE_ELF),y)
CRT=crt1
#else
#CRT=crt0.o
#endif

ifeq ($(HAVE_SHARED),y)
CRTS=$(top_builddir)lib/$(CRT).o $(top_builddir)lib/S$(CRT).o
else
CRTS=$(top_builddir)lib/$(CRT).o
endif

$(top_builddir)lib/$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
	$(INSTALL) -d $(dir $@)
	$(compile.S) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
	$(STRIPTOOL) -x -R .note -R .comment $@

$(top_builddir)lib/S$(CRT).o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/$(CRT).S
	$(INSTALL) -d $(dir $@)
	$(compile.S) $(PIEFLAG) -DL_$(patsubst %$(suffix $(notdir $@)),%,$(notdir $@))
	$(STRIPTOOL) -x -R .note -R .comment $@

CTOR_TARGETS=$(top_builddir)lib/crti.o $(top_builddir)lib/crtn.o

ifeq ($(UCLIBC_CTOR_DTOR),y)
$(top_builddir)lib/crti.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crti.S
	$(INSTALL) -d $(dir $@)
	$(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)

$(top_builddir)lib/crtn.o: $(top_srcdir)libc/sysdeps/linux/$(TARGET_ARCH)/crtn.S
	$(INSTALL) -d $(dir $@)
	$(compile.S) $(PICFLAG) $(SSP_DISABLE_FLAGS)
else
$(CTOR_TARGETS):
	$(INSTALL) -d $(top_builddir)lib
	$(AR) $(ARFLAGS) $@
endif

crt-y: $(crt-y)
$(crt-y): $(CRTS) $(CTOR_TARGETS)

other-y: $(other-y)
headers-y: $(headers-y)

objclean-y: $(objclean-y)
headers_clean-y: $(headers_clean-y)

$(top_builddir)lib/$(NONSHARED_LIBNAME): $(libc-nonshared-y)
	$(INSTALL) -d $(dir $@)
	$(AR) $(ARFLAGS) $@ $^

.PHONY: dummy create
clean: objclean-y headers_clean-y

ifeq ($(strip $(LIB_NAME)),)
LIB_NAME=libc
endif

ifeq ($(strip $($(LIB_NAME)_FULL_NAME)),)
$(LIB_NAME)_FULL_NAME:=$(LIB_NAME)-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so
endif

$(LIB_NAME)-SHARED_OBJS=$($(LIB_NAME)-so-y) $($(LIB_NAME)-shared-y)
ifeq ($(HAVE_SHARED),y)
shared: $($(LIB_NAME)-SHARED_OBJS)
else
shared:
endif

$(LIB_NAME)-ARCHIVE_OBJS=$($(LIB_NAME)-a-y) $($(LIB_NAME)-static-y)
ifeq ($(DOPIC),y)
objs: shared $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os) $(crt-y) $(other-y)
else
objs: shared $($(LIB_NAME)-ARCHIVE_OBJS) $(crt-y) $(other-y)
endif

libc=$(top_builddir)lib/libc.so
interp=$(top_builddir)libc/misc/internals/interp.os
ifeq ($(strip $(EXTRA_LINK_LIBS)),)
#EXTRA_LINK_LIBS:=$(interp) -L$(top_builddir)lib -lc $(LDADD_LIBFLOAT) $(LIBGCC)
EXTRA_LINK_LIBS:=$(interp) $(libc) $(LDADD_LIBFLOAT) $(LIBGCC)
endif

ifneq ($(strip $(LIB_NAME)),libc)
ifneq ($(strip $(LIB_NAME)),ld-uClibc)
$(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp) $(libc)
else
$(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a
endif
else
$(top_builddir)lib/$(LIB_NAME).so: $($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a $(interp)
endif
	$(INSTALL) -d $(dir $@)
	$(RM) $@ $@.$(MAJOR_VERSION) $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME)
	$(LD) $(LDFLAGS) $(EXTRA_LINK_OPTS) -soname=$(notdir $@).$(MAJOR_VERSION) \
		-o $(top_builddir)lib/$($(LIB_NAME)_FULL_NAME) $(SHARED_START_FILES) \
		--whole-archive $(firstword $^) --no-whole-archive \
		$(EXTRA_LINK_LIBS) $(SHARED_END_FILES)
	$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@.$(MAJOR_VERSION)
ifneq ($(strip $(LIB_NAME)),libc)
ifneq ($(strip $(LIB_NAME)),ld-uClibc)
	$(LN) -sf $($(LIB_NAME)_FULL_NAME) $@
endif
else
	echo "/* GNU ld script" > $@
	echo " * Use the shared library, but some functions are only in" >> $@
	echo " * the static library, so try that secondarily. */" >> $@
ifeq ($(UCLIBC_HAS_SSP),y)
ifeq ($(COMPAT_ATEXIT),y)
	echo "GROUP ( $(top_builddir)lib/$(NONSHARED_LIBNAME) $(top_builddir)lib/$(SHARED_MAJORNAME) AS_NEEDED ( $(top_builddir)lib/$(UCLIBC_LDSO) ) )" >> $@
else
	echo "GROUP ( $(top_builddir)lib/$(SHARED_MAJORNAME) $(top_builddir)lib/$(NONSHARED_LIBNAME) AS_NEEDED ( $(top_builddir)lib/$(UCLIBC_LDSO) ) )" >> $@
endif
else
ifeq ($(COMPAT_ATEXIT),y)
	echo "GROUP ( $(top_builddir)lib/$(NONSHARED_LIBNAME) $(top_builddir)lib/$(SHARED_MAJORNAME) )" >> $@
else
	echo "GROUP ( $(top_builddir)lib/$(SHARED_MAJORNAME) $(top_builddir)lib/$(NONSHARED_LIBNAME) )" >> $@
endif
endif
endif

$($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os: $($(LIB_NAME)-multi-y)
	$(compile-m)

# local testing only until libc is multi-capable
libc_m.os: $(libc-multi-y)
	$(compile-m)

ifneq ($(DOMULTI),n)

$($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.os $($(LIB_NAME)-nomulti-y:.o=.os) $($(LIB_NAME)-shared-y)
	$(RM) $@
ifneq ($(strip $(STRIP_FLAGS)),)
	$(STRIPTOOL) $(STRIP_FLAGS) $^
else
	$(STRIPTOOL) -x -R .note -R .comment $^
endif
	$(AR) $(ARFLAGS) $@ $^

ifeq ($(DOPIC),y)
$(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)
else
$(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)_OUT)/$(LIB_NAME)_m.o $($(LIB_NAME)-nomulti-y) $($(LIB_NAME)-static-y)
endif
	$(INSTALL) -d $(dir $@)
	$(RM) $@
	$(STRIPTOOL) -x -R .note -R .comment $^
	$(AR) $(ARFLAGS) $@ $^

else # DOMULTI

$($(LIB_NAME)_OUT)/$(LIB_NAME)_so.a: $($(LIB_NAME)-SHARED_OBJS)
	$(RM) $@
ifneq ($(strip $(STRIP_FLAGS)),)
	$(STRIPTOOL) $(STRIP_FLAGS) $^
else
	$(STRIPTOOL) -x -R .note -R .comment $^
endif
	$(AR) $(ARFLAGS) $@ $^

ifeq ($(DOPIC),y)
$(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS:.o=.os)
else
$(top_builddir)lib/$(LIB_NAME).a: $($(LIB_NAME)-ARCHIVE_OBJS)
endif
	$(INSTALL) -d $(dir $@)
	$(RM) $@
	$(STRIPTOOL) -x -R .note -R .comment $^
	$(AR) $(ARFLAGS) $@ $^

endif # DOMULTI

$(LIB_NAME)_clean:
	rm -f $($(LIB_NAME)_OUT)/*.{o,os,a}