summaryrefslogtreecommitdiffstats
path: root/build
blob: 1326229c7105517967cabfd8431ed8a7f59ec759 (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
#! /usr/bin/make -f

CFLAGS = -g -O2

configure:
	# Generate the main makefile.
	# Use shared BFD and opcodes libraries for all utilities.
	# Don't enable multilib (multiarch is better).
	# Enable plugins.
	# Don't expect to find Gettext.
	for target in $$(cat ../targets); do \
		CFLAGS='$(CFLAGS)' oh-autoconfigure \
			-B "build-$${target}" -t "$${target}" -- \
			$$([ -n "$${OPK_SYSROOT}" ] && \
				printf "--with-sysroot='%s'" "$${OPK_SYSROOT}") \
			--program-transform-name="s&^&$${target}-&" \
			--enable-shared --disable-multilib \
			--enable-plugins --disable-nls \
			--with-pkgversion='GNU Binutils for ProteanOS' || \
			exit 1; \
		done
	# Generate all the individual program makefiles.
	for target in $$(cat ../targets); do \
		oh-autobuild -B "build-$${target}" -T configure-host || \
			exit 1; \
		done
	touch $@

build: configure
	# Build BFD header files.
	for target in $$(cat ../targets); do \
		oh-autobuild -B "build-$${target}/bfd" -T headers || \
			exit 1; \
		done
	# Build ALL the things!
	for target in $$(cat ../targets); do \
		oh-autobuild -B "build-$${target}" CFLAGS='$(CFLAGS)' || \
			exit 1; \
		done
	touch $@

install: build
	# Install everything.
	for target in $(PKG_TARGETS); do \
		cd "build-$${target}" && \
		make CFLAGS='$(CFLAGS)' \
			prefix="$${PWD}/../dest/usr" tooldir="$${PWD}/../dest/usr/tool" \
			bindir="$${PWD}/../dest/usr/bin/$(OH_HOST_ARCH)" \
			libdir="$${PWD}/../dest/usr/lib/$(OH_HOST_ARCH)" \
			install && \
		cd ..; \
		done
	# tooldir contains target ldscripts and hard links to tools.
	# Move ldscripts to where they belong and delete everything else.
	# ldscripts should be independent of the host architecture and therefore
	# coinstallable with themselves across host architectures.
	for target in $(PKG_TARGETS); do \
		mv dest/usr/tool/lib/ldscripts "dest/usr/lib/$${target}" && \
		rm -Rf dest/usr/tool; \
		done
	# This is a kludge to put libiberty.a in the right place.
	# The problem is that libiberty's makefile asks GCC for a multilib
	# directory.
	liberty="$$(find dest/usr/lib -name libiberty.a)" && \
		mv "$${liberty}" dest/usr/lib/$(OH_HOST_ARCH) && \
		rmdir "$${liberty%/libiberty.a}"
	# Move BFD libraries and headers into multiarch locations.
	# This can't be done with *dir options; these paths are hardcoded in
	# bfd/configure.
	for target in $(PKG_TARGETS); do \
		target_arch_gnu=$$(oh-getarchitecture -t gnu "$${target}") && \
		mkdir dest/usr/include && \
		mkdir dest/usr/include/$(OH_HOST_ARCH) && \
		mv "dest/usr/$(OH_HOST_ARCH_GNU)/$${target_arch_gnu}/include" \
			"dest/usr/include/$(OH_HOST_ARCH)/$${target}" && \
		mv "dest/usr/$(OH_HOST_ARCH_GNU)/$${target_arch_gnu}/lib" \
			"dest/usr/lib/$(OH_HOST_ARCH)/$${target}" && \
		rmdir "dest/usr/$(OH_HOST_ARCH_GNU)/$${target_arch_gnu}"; \
		done
	rmdir "dest/usr/$(OH_HOST_ARCH_GNU)" \
	# Remove static library dependency metadata generated by libtool.
	rm -f dest/usr/lib/$(OH_HOST_ARCH)/*/*.la
	# Make symbolic links to native utilities.
	for target in $(PKG_TARGETS); do \
		if [ '$(OH_HOST_ARCH)' = "$${target}" ]; then \
			for util in "../dest/usr/bin/$${target}-"*; do \
				ln -sf "$${util##*/}" "$${util%/*}/$${util##*/$${target}}"; \
			done \
		fi; \
		done
	# Write GNU ld configuration to point to BFD libraries.
	mkdir -p /etc/ld.so.conf.d
	for target in $(PKG_TARGETS); do \
		echo '# GNU BFD libraries' >"dest/etc/ld.so.conf.d/bdf-$${target}" && \
		echo "/usr/lib/$(OH_HOST_ARCH)/$${target}" \
			>>"dest/etc/ld.so.conf.d/bdf-$${target}"; \
		done
	# Post-process and install everything.
	oh-strip
	oh-installfiles
	touch $@

clean:
	for target in $$(cat ../targets); do \
		oh-autoclean -B "build-$${target}" || \
			exit 1; \
		done
	rm -f configure build
	rm -Rf *.data