summaryrefslogtreecommitdiffstats
path: root/build
blob: ff2d7ddab1b5059c62ff693aa04aa73ddc5e2fc8 (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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
#!/usr/bin/make -f

libgcc_soversion = 1

# POSIX.1-2008:
#   If the pathname does not begin with a '/' it shall be treated as relative to
#   the current working directory of the process, not relative to the directory
#   containing the makefile.
include ../source.mk
include ../targets.mk

# Hardcode the targets to allow only native compilers for now.
targets = $(OPK_HOST_ARCH)

version = $$(printf '%s\n' '$(OPK_SOURCE_VERSION_UPSTREAM)' | sed 's/+sip.*//')
base_version = $$(printf '%s\n' '$(OPK_SOURCE)' | sed 's/^gcc-//')

# target will be set in sub-makes.
target = ~none
target_gnu = $$(oh-architecture $(target))

builddir = obj-$(target)
destdir = dest-$(target)

include ../targets.d/$(target).mk

# /usr/lib/<target>/ld.so is a symbolic link for use by GCC to find the system's
# dynamic linker.  It should be provided by the development package of any
# standard C library.
# ProteanOS GCC should build binaries with an ELF INTERP field as follows:
#   /lib/<target>/<soname>
# <soname> is the SONAME of the target's dynamic linker.
elf_interp = /lib/$(target)/$(elf_interp_soname)
elf_interp_soname = $$(readelf -d "/usr/lib/$(target)/ld.so" | \
	sed -n 's/^.*(SONAME).*\[\([^]]*\)\].*$$/\1/p')

common_opts = \
	--libexecdir='$${prefix}/libexec' \
	--with-pkgversion='GCC for ProteanOS' \
	--program-suffix="-$(base_version)" \
	--enable-linker-build-id \
	--with-system-zlib \
	--disable-multilib \
	--enable-multiarch \
	--without-included-gettext \
	--with-nls \
	--with-sysroot="$${OPK_SYSROOT}" \
	--disable-libquadmath \
	$(target_opts) \
	$(extra_opts)

full_opts = \
	--enable-shared \
	--enable-threads=posix \
	--enable-languages=c,c++ \
	$(common_opts)

bootstrap1_opts = \
	--without-headers \
	--with-newlib \
	--disable-shared \
	--disable-threads \
	--enable-languages=c,c++ \
	--disable-libgomp \
	--disable-libssp \
	$(common_opts)

# Abbreviation for build-gcc-config
tm = src/gcc/config

# Defaults:
libdir        = /usr/lib/$(OPK_HOST_ARCH)
libsubdir     = /usr/lib/$(OPK_HOST_ARCH)/gcc/$(target_gnu)/$(version)
libexecsubdir = /usr/libexec/gcc/$(target_gnu)/$(version)
libsuffix     = $$(g++ -print-multi-os-directory)
def_gcc_gcc_include_dir          = $(libsubdir)/include
def_gcc_fixed_include_dir        = $(libsubdir)/include-fixed
def_gcc_gxx_include_dir          = /usr/include/c++/$(version)
def_gcc_gxx_tool_include_dir     = $(def_gcc_gxx_include_dir)/$(target_gnu)
def_gcc_gxx_backward_include_dir = $(def_gcc_gxx_include_dir)/backward
# Customs:
gccexedir = /usr/libexec/gcc/$(target)/$(base_version)
tgtlibdir = /usr/lib/$(target)/gcc/$(base_version)
gcc_gcc_include_dir          = /usr/include/$(target)/gcc/$(base_version)
gcc_fixed_include_dir        = /usr/include/$(target)/gcc/$(base_version)/fixed
gcc_gxx_include_dir          = /usr/include/c++/$(base_version)
gcc_gxx_tool_include_dir     = /usr/include/$(target)/c++/$(base_version)
gcc_gxx_backward_include_dir = /usr/include/c++/$(base_version)/backward
dir_macros = \
	"gcc_gcc_include_dir=$(gcc_gcc_include_dir)" \
	"gcc_fixed_include_dir=$(gcc_fixed_include_dir)" \
	"gcc_gxx_include_dir=$(gcc_gxx_include_dir)" \
	"gcc_gxx_tool_include_dir=$(gcc_gxx_tool_include_dir)" \
	"gcc_gxx_backward_include_dir=$(gcc_gxx_backward_include_dir)"

extra_opts =
native_target = bootstrap-lean
cross_target = all-gcc
jobs = $$(printf '%s\n' /sys/devices/system/cpu/cpu[0-9]* | wc -l)
include ../local.mk
# For example, to disable bootstrapping, set these in local.mk:
#     extra_opts = --disable-bootstrap
#     native_target = all

nop:
	@:

../local.mk:
	>../local.mk

$(configure_native_stamps) $(configure_cross_stamps):
	set -e; \
	if [ 'x$(OPK_HOST_PLAT)' = 'xbootstrap1' ]; then \
		oh-autoconfigure -B "$(builddir)" -t "$(target)" -- \
			$(bootstrap1_opts); \
	else \
		oh-autoconfigure -B "$(builddir)" -t "$(target)" -- \
			$(full_opts); \
	fi
	touch $@

# This rule sets (host- and) target-dependent paths in files in gcc/config.
# They must be edited here rather than in a patch because any given GCC target
# configuration can be used by multiple ProteanOS targets.  These commands run
# once per target, but they modify files in the src/ directory that other
# targets might also use, so backups are made.
build-gcc-config:
	[ -e "$(tm)/$(tm_file).orig" ] || \
		mv "$(tm)/$(tm_file)" "$(tm)/$(tm_file).orig"
	# Set the default dynamic linker path inserted into ELF INTERP fields.
	sed "s|^\(#define $(tm_interp_macro)\) \".*\"$$|\1 \"$(elf_interp)\"|" \
		"$(tm)/$(tm_file).orig" >"$(tm)/$(tm_file)"
	# Set macros for executable and startup(/library) file prefixes.
	printf '\n#undef %s\n#define %s "%s"\n' STANDARD_EXEC_PREFIX \
		STANDARD_EXEC_PREFIX "$(tgtlibdir)/" >>"$(tm)/$(tm_file)"
	printf '#undef %s\n#define %s "%s"\n' STANDARD_LIBEXEC_PREFIX \
		STANDARD_LIBEXEC_PREFIX "$(gccexedir)/" >>"$(tm)/$(tm_file)"
	[ -e "$(tm)/$(tmake_file).orig" ] || \
		mv "$(tm)/$(tmake_file)" "$(tm)/$(tmake_file).orig"
	sed "$(tmake_script)" "$(tm)/$(tmake_file).orig" >"$(tm)/$(tmake_file)"
	printf '\nMULTIARCH_DIRNAME = %s\n' "$(target)" >>"$(tm)/$(tmake_file)"

$(build_native_stamps):
	$(MAKE) -f ../build target=$(target) build-gcc-config
	oh-autobuild -B "$(builddir)" -T $(native_target) -- \
		-j $${JOBS:-$(jobs)} $(dir_macros)
	#if [ '$(OPK_BUILD_ARCH)' = '$(OPK_HOST_ARCH)' ]; then \
	#	cd "$(builddir)" && make -k check; \
	#fi
	touch $@

$(build_cross_stamps):
	$(MAKE) -f ../build target=$(target) build-gcc-config
	oh-autobuild -B "$(builddir)" -T $(cross_target) -- \
		-j $${JOBS:-$(jobs)} $(dir_macros)
	touch $@

$(install_native_stamps):
	# The -T option is necessary because otherwise:
	#   * oh-autoinstall checks for an "install" target by running make with
	#     the -n option,
	#   * Many commands in GCC makefiles contain the "$(MAKE)" macro
	#     expansion, and
	#   * GNU Make executes any commands that contain "$(MAKE)", even if -n
	#     is specified.
	# See also: <http://gcc.gnu.org/ml/gcc/2013-04/msg00171.html>.
	oh-autoinstall -B "$(builddir)" -d "$(destdir)" -T install -- \
		$(dir_macros)
	# Change the target architecture prefix of files in /usr/bin.
	rm -f $(destdir)/usr/bin/$(target_gnu)-*
	for f in $(destdir)/usr/bin/*; do f="$${f##*/}"; \
		mv $(destdir)/usr/bin/$${f} $(destdir)/usr/bin/$(target)-$${f};\
		ln -s $(target)-$${f} $(destdir)/usr/bin/$${f}; \
	done
	rm -f $(destdir)/usr/bin/$(target)-c++-$(base_version)
	ln -s $(target)-g++-$(base_version) \
		$(destdir)/usr/bin/$(target)-c++-$(base_version)
	# Move files into ProteanOS-style directories.
	# gcc programs:
	mkdir -p $(destdir)$(gccexedir)
	mv \
		$(destdir)$(libexecsubdir)/cc1* \
		$(destdir)$(libexecsubdir)/collect2 \
		$(destdir)$(libexecsubdir)/*.so* \
		$(destdir)$(libexecsubdir)/lto* \
		$(destdir)$(gccexedir)
	# Start files and gcc libraries:
	mkdir -p $(destdir)$(tgtlibdir)
	mv \
		$(destdir)$(libsubdir)/*.o \
		$(destdir)$(libsubdir)/*.a \
		$(destdir)$(tgtlibdir)
	# gcc and C++ headers:
	mkdir -p \
		$(destdir)$(gcc_gcc_include_dir) \
		$(destdir)$(gcc_fixed_include_dir) \
		$(destdir)$(gcc_gxx_include_dir) \
		$(destdir)$(gcc_gxx_tool_include_dir) \
		$(destdir)$(gcc_gxx_backward_include_dir)
	mv $(destdir)$(def_gcc_gcc_include_dir)/* \
		$(destdir)$(gcc_gcc_include_dir)
	rmdir $(destdir)$(def_gcc_gcc_include_dir)
	mv $(destdir)$(def_gcc_fixed_include_dir)/* \
		$(destdir)$(gcc_fixed_include_dir)
	rmdir $(destdir)$(def_gcc_fixed_include_dir)
	# def_gcc_gxx_tool_include_dir and def_gcc_gxx_backward_include_dir are
	# subdirectories of def_gcc_gxx_include_dir, so move them first.
	mv $(destdir)$(def_gcc_gxx_tool_include_dir)/* \
		$(destdir)$(gcc_gxx_tool_include_dir)
	rmdir $(destdir)$(def_gcc_gxx_tool_include_dir)
	mv $(destdir)$(def_gcc_gxx_backward_include_dir)/* \
		$(destdir)$(gcc_gxx_backward_include_dir)
	rmdir $(destdir)$(def_gcc_gxx_backward_include_dir)
	mv $(destdir)$(def_gcc_gxx_include_dir)/* \
		$(destdir)$(gcc_gxx_include_dir)
	rmdir $(destdir)$(def_gcc_gxx_include_dir)
	# Target-arch libraries:
	mkdir -p $(destdir)$(libdir)
	mv $(destdir)$(libdir)/$(libsuffix)/* $(destdir)$(libdir)
	# Put *.so links in a versioned directory.   We want links to
	# libfoo.so.x, not libfoo.x.y.z as libtool generates.
	set -e; \
	for link in $(destdir)$(libdir)/*.so; do \
		rm -f $${link}; \
		lib=$$(ls $${link}.* | sed 's|^.*/||; q;'); \
		link=$$(printf '%s\n' $${link} | sed 's|^.*/||;'); \
		ln -sf ../../$${lib} $(destdir)$(tgtlibdir)/$${link}; \
	done
	# Put *.o and *.spec files in a versioned directory.
	mv $(destdir)$(libdir)/*.o $(destdir)$(libdir)/*.spec \
		$(destdir)$(tgtlibdir)
	# Put libgcc_s.so.* under /lib.
	mkdir -p $(destdir)/lib/$(OPK_HOST_ARCH)
	mv $(destdir)$(libdir)/libgcc_s.so.* $(destdir)/lib/$(OPK_HOST_ARCH)
	ln -sf /lib/$(OPK_HOST_ARCH)/libgcc_s.so.$(libgcc_soversion) \
		$(destdir)$(tgtlibdir)/libgcc_s.so
	# Remove libitm files.
	rm -f $(destdir)$(libdir)/libitm.*
	# Remove libmpx files.
	rm -f $(destdir)$(libdir)/libmpx*
	# Remove libtool archives and static libraries.
	rm -f \
		$(destdir)$(libdir)/*.la \
		$(destdir)$(libdir)/*.a \
		$(destdir)$(libexecsubdir)/*.la \
		$(destdir)$(libsubdir)/plugin/*.la
	# Remove the info directory node.
	rm -f $(destdir)/usr/share/info/dir
	# Remove empty documentation files.
	find $(destdir)/usr/share/man -type f -a -size 0c -a \
		-exec rm -f '{}' ';'
	find $(destdir)/usr/share/info -type f -a -size 0c -a \
		-exec rm -f '{}' ';'
	# TODO: Provide these files in a fixincludes package (arch:any,
	# target-specific?).
	rm -Rf \
		$(destdir)$(libsubdir)/install-tools/ \
		$(destdir)$(libexecsubdir)/install-tools/
	# TODO: Provide these files in a libstdc++-*-dbg package.
	rm -f $(destdir)$(libdir)/libstdc++.so.*-gdb.py
	rm -Rf $(destdir)/usr/share/gcc-$(version)/python/libstdcxx/
	# TODO: Provide these files in a doc package.
	rm -Rf $(destdir)/usr/share/man/ $(destdir)/usr/share/info/
	# TODO: Provide these files in a gcc-*-plugin-dev package.
	rm -Rf $(destdir)$(libsubdir)/plugin/ $(destdir)$(libexecsubdir)/plugin/
	oh-fixperms -d "$(destdir)"
	oh-strip -d "$(destdir)"
	OPK_PACKAGES="\
		cpp-$(base_version)-$(target) \
		gcc-$(base_version)-$(target) \
		g++-$(base_version)-$(target) \
		" oh-installfiles -d "$(destdir)"
	OPK_PACKAGES="\
		$$(printf '%s\n' $${OPK_PACKAGES} | \
			grep -Ev "(cpp|gcc|g++)-$(base_version)-.*-.*-.*") \
		" oh-installfiles -d "$(destdir)"
	oh-shlibdeps

$(install_cross_stamps):
	oh-autoinstall -B "$(builddir)" -d "$(destdir)" -T install-gcc -- \
		$(dir_macros)
	# Change the target architecture prefix of files in /usr/bin.
	rm -f $(destdir)/usr/bin/$(target_gnu)-*
	for f in $(destdir)/usr/bin/*; do f="$${f##*/}"; \
		mv $(destdir)/usr/bin/$${f} $(destdir)/usr/bin/$(target)-$${f};\
	done
	rm -f $(destdir)/usr/bin/$(target)-c++-$(base_version)
	ln -s $(target)-g++-$(base_version) \
		$(destdir)/usr/bin/$(target)-c++-$(base_version)
	# Move files into ProteanOS-style directories.
	mkdir -p $(destdir)$(gccexedir)
	mv \
		$(destdir)$(libexecsubdir)/cc1* \
		$(destdir)$(libexecsubdir)/collect2 \
		$(destdir)$(libexecsubdir)/*.la \
		$(destdir)$(libexecsubdir)/*.so* \
		$(destdir)$(libexecsubdir)/lto* \
		$(destdir)$(gccexedir)
	rm -Rf \
		$(destdir)$(libsubdir)/*.o \
		$(destdir)$(libsubdir)/include* \
		$(destdir)$(libsubdir)/*.a \
		$(destdir)$(libsubdir)/install-tools \
		$(destdir)$(libexecsubdir)/install-tools \
		$(destdir)$(libsubdir)/plugin \
		$(destdir)$(libexecsubdir)/plugin \
		$(destdir)/usr/share/locale \
		$(destdir)/usr/share/man \
		$(destdir)/usr/share/info
	oh-fixperms -d "$(destdir)"
	oh-strip -d "$(destdir)"
	OPK_PACKAGES="\
		cpp-$(base_version)-$(target) \
		gcc-$(base_version)-$(target) \
		g++-$(base_version)-$(target) \
		" oh-installfiles -d "$(destdir)"
	oh-shlibdeps

configure build install:
	set -e; \
	for tgt in $(targets); do \
		if [ x"$${tgt}" = x'$(OPK_HOST_ARCH)' ]; then \
			$(MAKE) -f ../build target=$${tgt} $@-native_$${tgt}; \
		else \
			$(MAKE) -f ../build target=$${tgt} $@-cross_$${tgt}; \
		fi; \
	done

configure:
build: configure
install: build