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

include ../source.mk

CFLAGS = -g -O2

nop:
	@:

configure:
	# Generate the main makefile.
	#   * Use multiarch library search directories.
	#     - The library path is given to ld/configure through
	#       host_configargs in Makefile's "configure-host" target.
	#     - If we're building a cross ld, search only target-specific
	#       library paths.
	#   * Use shared BFD and opcodes libraries for all utilities.
	#     - That is, dynamically link the utilities against a single copy of
	#       the BFD and opcodes libraries.
	#   * Don't enable multilib (multiarch is better).
	#   * Enable plugins.
	for target in $$(cat ../targets); do \
		if [ '$(OPK_HOST_ARCH)' = "$${target}" ]; then \
			LIB_PATH="=/usr/local/lib/$${target}:=/usr/local/lib"; \
			LIB_PATH="$${LIB_PATH}:=/lib/$${target}:=/lib"; \
			LIB_PATH="$${LIB_PATH}:=/usr/lib/$${target}:=/usr/lib"; \
		else \
			LIB_PATH="=/usr/local/lib/$${target}"; \
			LIB_PATH="$${LIB_PATH}:=/lib/$${target}"; \
			LIB_PATH="$${LIB_PATH}:=/usr/lib/$${target}"; \
		fi; \
		CFLAGS='$(CFLAGS)' \
			host_configargs="--with-lib-path=$${LIB_PATH}" \
			oh-autoconfigure \
			-B "build-$${target}" -t "$${target}" -- \
			--with-sysroot="$${OPK_SYSROOT:-/}" \
			--program-transform-name="s&^&$${target}-&" \
			--enable-shared --disable-multilib \
			--enable-plugins \
			--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 \
			tooldir='/usr/tool' scriptdir="/usr/lib/$${target}" \
			bfdlibdir="/usr/lib/$(OPK_HOST_ARCH)/$${target}" \
			bfdincludedir="/usr/include/$(OPK_HOST_ARCH)/$${target}" || \
		exit 1; \
	done
	touch $@

build: configure
	touch src/bfd/doc/bfd.info
	# Build BFD header files.
	for target in $$(cat ../targets); do \
		oh-autobuild -B "build-$${target}/bfd" -T headers \
			tooldir='/usr/tool' scriptdir="/usr/lib/$${target}" \
			bfdlibdir="/usr/lib/$(OPK_HOST_ARCH)/$${target}" \
			bfdincludedir="/usr/include/$(OPK_HOST_ARCH)/$${target}" || \
			exit 1; \
	done
	# Build ALL the things!
	for target in $$(cat ../targets); do \
		oh-autobuild -B "build-$${target}" CFLAGS='$(CFLAGS)' \
			MAKEINFO=true \
			tooldir='/usr/tool' scriptdir="/usr/lib/$${target}" \
			bfdlibdir="/usr/lib/$(OPK_HOST_ARCH)/$${target}" \
			bfdincludedir="/usr/include/$(OPK_HOST_ARCH)/$${target}" || \
			exit 1; \
	done
	touch $@
	# Run tests if natively building.
	if [ '$(OPK_BUILD_ARCH)' = '$(OPK_HOST_ARCH)' ]; then \
		for target in $$(cat ../targets); do \
			oh-autotest -B "build-$${target}" || \
				exit 1; \
		done; \
	fi

install: build
	# Install everything.
	#   * scriptdir contains target ldscripts.
	#   * ldscripts are specific to both the host and target architectures.
	#     - If host != target, only target-specific paths are passed as
	#       arguments to SEARCH_DIR commands in ldscripts.  (See the
	#       LIB_PATH stuff in the "configure" target above.)
	#   * All of these macro settings are effective thanks to 
	#     `patches/01_pass-some-dirs-to-child-makes.patch`.
	for target in $$(cat ../targets); do \
		oh-autoinstall \
			-B "build-$${target}" -d "binutils-$${target}.data" \
			CFLAGS='$(CFLAGS)' MAKEINFO=true \
			tooldir='/usr/tool' \
			scriptdir="/usr/lib/$(OPK_HOST_ARCH)/$${target}" \
			bfdlibdir="/usr/lib/$(OPK_HOST_ARCH)/$${target}" \
			bfdincludedir="/usr/include/$(OPK_HOST_ARCH)/$${target}" || \
		exit 1; \
	done
	# Do some cleanup.
	#   * /usr/tool/bin (TOOLBINDIR) contains hard links to tools.  A quick
	#     look at the code suggests we don't need them; ld *should* work
	#     without them in any sane configuration.
	#   * We don't need a static libiberty.
	#   * Remove static library dependency metadata generated by libtool.
	for target in $$(cat ../targets); do \
		rm -Rf "binutils-$${target}.data/usr/tool" && \
		find "binutils-$${target}.data/usr/lib" -name 'libiberty.a' \
			-exec rm -f '{}' ';' && \
		find "binutils-$${target}.data/usr/lib" -name '*.la' \
			-exec rm -f '{}' ';' && \
		for dir in "binutils-$${target}.data/usr/lib/"*/; do \
			case "$${dir#binutils-$${target}.data/usr/lib/}" in \
				'$(OPK_HOST_ARCH)/') ;; \
				"$${target}/") ;; \
				*) rmdir "$${dir}" ;; \
			esac; \
		done; \
	done
	# Make symbolic links to native utilities.
	for target in $$(cat ../targets); do \
		if [ '$(OPK_HOST_ARCH)' = "$${target}" ]; then \
			for util in "binutils-$${target}.data/usr/bin/$${target}-"*; do \
				if [ "$${util##*/$${target}-}" = 'ar' ]; then \
					dest='ar.binutils'; \
				elif [ "$${util##*/$${target}-}" = 'strings' ]; then \
					dest='strings.binutils'; \
				else \
					dest="$${util##*/$${target}-}"; \
				fi; \
				ln -sf "$${util##*/}" \
					"$${util%/*}/$${dest}"; \
			done \
		fi; \
	done
	# Write GNU ld configuration to point to BFD libraries.
	for target in $$(cat ../targets); do \
		ld_so_conf_d="binutils-$${target}.data/etc/ld.so.conf.d" && \
		ld_so_conf="$${ld_so_conf_d}/bfd_$(OPK_HOST_ARCH)_$${target}" && \
		mkdir -p "$${ld_so_conf_d}" && \
		printf '# GNU BFD libraries\n/usr/lib/%s/%s\n' \
			'$(OPK_HOST_ARCH)' "$${target}" \
			>"$${ld_so_conf}"; \
	done
	# Move documentation into binutils-doc data directory.
	# Move locale files into binutils-locales data directory.
	mkdir -p 'binutils-doc.data/usr/share'
	mkdir -p 'binutils-locales.data/usr/share'
	for target in $$(cat ../targets); do \
		if [ ! -d 'binutils-doc.data/usr/share/man' ]; then \
			mv "binutils-$${target}.data/usr/share/man" \
				'binutils-doc.data/usr/share' || \
			exit 1; \
			for file in 'binutils-doc.data/usr/share/man/man1/'*; do \
				mv "$${file}" "$${file%/*}/$${file##*/$${target}-}" || \
				exit 1; \
			done; \
		fi; \
		if [ ! -d 'binutils-doc.data/usr/share/info' ]; then \
			mv "binutils-$${target}.data/usr/share/info" \
				'binutils-doc.data/usr/share' || \
			exit 1; \
		fi; \
		if [ ! -d 'binutils-locales.data/usr/share/locale' ]; then \
			mv "binutils-$${target}.data/usr/share/locale" \
				'binutils-locales.data/usr/share' || \
			exit 1; \
		fi; \
		rm -Rf "binutils-$${target}.data/usr/share" || \
		exit 1; \
	done
	# Remove info index.
	rm -f binutils-doc.data/usr/share/info/dir
	# Remove common info files.
	rm -f binutils-doc.data/usr/share/info/configure.info
	rm -f binutils-doc.data/usr/share/info/standards.info
	# Move BFD development files into libbfd-dev-* data directory.
	for target in $$(cat ../targets); do \
		if [ -d "libbfd-dev-$${target}.data/usr" ]; then \
			rm -Rf "libbfd-dev-$${target}.data/usr" || \
			exit 1; \
		fi; \
		mkdir -p "libbfd-dev-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}" && \
		mv "binutils-$${target}.data/usr/include" \
			"libbfd-dev-$${target}.data/usr" && \
		mv "binutils-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}/libbfd.so" \
			"binutils-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}/libbfd.a" \
			"binutils-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}/libopcodes.so" \
			"binutils-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}/libopcodes.a" \
			"libbfd-dev-$${target}.data/usr/lib/$(OPK_HOST_ARCH)/$${target}" || \
		exit 1; \
	done
	# Post-process and install everything.
	for target in $$(cat ../targets); do \
		oh-fixperms -d "binutils-$${target}.data" && \
		oh-strip -d "binutils-$${target}.data" || \
		exit 1; \
	done

clean: clean-build clean-install

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

clean-install:
	rm -Rf *.data