aboutsummaryrefslogtreecommitdiff
path: root/lib/configure.sh
blob: d6d9b7010d568e6482e011c3229ca5cc1998fa13 (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
#!/bin/bash
# 
#   Copyright (C) 2013, 2014, 2015, 2016 Linaro, Inc
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
# 

# Configure a source directory
# $1 - the directory to configure
# $2 - [OPTIONAL] which sub component to build (gcc stage)
configure_build()
{
#    trace "$*"

    local component=$1

    # Linux isn't a build project, we only need the headers via the existing
    # Makefile, so there is nothing to configure.
    if test x"${component}" = x"linux"; then
	return 0
    fi
    local srcdir="$(get_component_srcdir ${component})"
    local builddir="$(get_component_builddir ${component} $2)"
    local version="$(basename ${srcdir})"
    local stamp="$(get_stamp_name $component configure ${version} ${2:+$2})"

    # this is a hack for eglibc so that the configure script can be found
    if [ x"${component}" = x"eglibc" ]; then
	srcdir="${srcdir}/libc"
    fi

    # Set PATH, if needed, before potential early exit due to up-to-date
    # stamp.
    local needs_tools=false
    case ${component} in
	newlib*|libgloss*) needs_tools=true ;;
	glibc|eglibc) needs_tools=true ;;
	gcc)
	    if [ x"$build" != x"$host" ]; then
		# We need [prebuilt] $build-hosted target GCC to build
		# $host-hosted target GCC.
		needs_tools=true
	    fi
	    ;;
	gdbserver) needs_tools=true ;;
    esac
    if $needs_tools; then
	# This component needs build-side tools in PATH.
	# Usually, $host is the same as $build, and we just add $prefix/bin
	# to PATH below.  In mingw builds, however, we need to add to PATH
	# [prebuilt] linux-hosted tools from $local_builds/destdir/$build/bin.
	#
	# We are running inside a sub-shell provided by make.sh:build(),
	# so it's OK to alter environment.
	export PATH="$local_builds/destdir/$build/bin:$PATH"
	notice "Setting for $component${2:+ $2} build PATH=$PATH"
    fi

    # Don't look for the stamp in the builddir because it's in builddir's
    # parent directory.
    local stampdir="$(dirname ${builddir})"

    local ret=
    check_stamp "${stampdir}" ${stamp} ${srcdir} configure ${force}
    ret=$?
    if test $ret -eq 0; then
	return 0 
    elif test $ret -eq 255; then
	# This means that the compare file ${srcdir} is not present.
	return 1
    fi

    if test ! -d "${builddir}"; then
	notice "The build directory '${builddir}' doesn't exist, so creating it"
	dryrun "mkdir -p \"${builddir}\""
    fi

    if test ! -f "${srcdir}/configure" -a x"${dryrun}" != x"yes"; then
	warning "No configure script in ${srcdir}!"
        # not all packages commit their configure script, so if it has autogen,
        # then run that to create the configure script.
	if test -f ${srcdir}/autogen.sh; then
	    (cd ${srcdir} && ./autogen.sh)
	fi
	if test ! -f "${srcdir}/configure"; then
	    error "No configure script in ${srcdir}!"
	    return 1
	fi
    fi

    local opts="$(get_component_configure ${component} $2)"

    # Use static linking if component is configured for it
    local static="$(get_component_staticlink ${component})"
    if test x"${static}" = x"yes"; then
	case ${component} in
	    qemu)
		opts="${opts} --static"
		;;
	    *)
		opts="${opts} --disable-shared --enable-static"
		;;
	    esac
    fi

    if is_host_mingw; then
        opts="${opts} $(get_component_mingw_extraconf ${component})"
    fi

    # prefixhost is the root for host-side libs and tools.
    prefixhost="${local_builds}/hosttools/${host}"

    # The release string is usually the date as well, but in YYYY.MM format.
    # For snapshots we add the day field as well.
    if test x"${release}" = x; then
	local date="$(date --date="@${timestamp}" "+%Y.%m")"
    else
	local date="${release}"
    fi

    if test x"${override_cflags}" != x -a x"${component}" != x"eglibc"; then
	opts="${opts} CFLAGS=\"${override_cflags}\" CXXFLAGS=\"${override_cflags}\""
    fi

    # Some components' configure (eg. qemu's) do not support overriding
    # SHELL via an argument, so allow not to do so when needed.
    FORCESHELL="SHELL=${bash_shell}"

    # GCC and the binutils are the only toolchain components that need the
    # --target option set, as they generate code for the target, not the host.
    case ${component} in
	newlib*|libgloss*)
	    # Newlib installs itself into $prefix/$target, so setting --prefix to $prefix
	    # gives us the correct sysroot path.
	    opts="${opts} --host=${host} --target=${target} --prefix=${prefix}"
	    ;;
	glibc|eglibc)
	    # FIXME: Below is ancient evil that should be removed.
	    #        Forcing 64-bit rtld into /lib is against ABI.
	    # [e]glibc uses slibdir and rtlddir for some of the libraries and
	    # defaults to lib64/ for aarch64.  We need to override this.
	    # There's no need to install anything into lib64/ since we don't
	    # have biarch systems.

	    # libdir is where static libraries and linker scripts are installed,
	    # like libc.so, libc_nonshared.a, and libc.a.
	    echo libdir=/usr/lib > ${builddir}/configparms

	    # slibdir is where shared objects are installed.
	    echo slibdir=/lib >> ${builddir}/configparms

	    # rtlddir is where the dynamic-linker is installed.
	    echo rtlddir=/lib >> ${builddir}/configparms
	    opts="${opts} --build=${build} --host=${target} --target=${target} --prefix=/usr"
	    dryrun "(mkdir -p ${sysroots}/usr/lib)"
	    ;;
	gcc)
	    opts="$opts --prefix=$prefix"

	    if test x"$build" != x"$target"; then
		local stage="$2"

		case "$stage" in
			stage1)
			    opts="$opts $stage1_flags"
			    notice "Building stage 1 of GCC"
			    ;;
			stage2)
			    if [ ! -e "$sysroots/libc/usr/include/stdio.h" ]; then
				warning "No sysroot found before gcc stage2 build"
			    fi
			    opts="$opts $stage2_flags"
			    notice "Building stage 2 of GCC"
			    ;;
			*)
			    error "Unknown GCC stage: $stage"
			    ;;
		esac
		opts="$opts --build=$build --host=$host --target=$target"
	    else
		# Native build needs stage2 build only.
		opts="$opts $stage2_flags"
	    fi

	    if [ x"$send_results_to" != x ]; then
		# gcc/REVISION is used to build 'gcc --version'
		# output.  This file is not committed in the GCC repo,
		# but GCC's build system uses it if present in
		# $srcdir.
		local revstring="$(get_component_revision ${component})"
		local branch="$(get_component_branch ${component})"
		local srcdir="$(get_component_srcdir ${component})"

		# Try to generate a nicer revision.
		if [ -d ${srcdir}/.git ]; then
		    revstring=$(git -C ${srcdir} describe --match "basepoints/*" \
				    --match "releases/*" ${revstring}  | sed 's,^basepoints/,,')
		fi

		dryrun "echo \[${branch} revision ${revstring}\] | tee ${srcdir}/gcc/REVISION"
		dryrun "touch ${srcdir}/gcc/genversion.cc"
	    fi
	    ;;
	binutils)
	    if test x"${override_linker}" = x"gold"; then
		opts="${opts} --enable-gold=default"
	    fi
	    opts="${opts} --build=${build} --host=${host} --target=${target} --prefix=${prefix}"
	    ;;
	gdb)
	    opts="${opts} --build=${build} --host=${host} --target=${target} --prefix=${prefix}"
	    ;;
	gdbserver)
	    opts="${opts} --build=${build} --host=${target} --prefix=${sysroots}/usr"
	    ;;
	# These are only built for the host
	gmp|mpc|mpfr)
	    opts="${opts} --build=${build} --host=${host} --prefix=${prefix}"
	    ;;
	# Dejagnu is not a deliverable
	dejagnu)
	    opts="${opts} --build=${build} --host=${host} --prefix=${prefixhost}"
	    ;;
	qemu)
	    opts="${opts} --prefix=${prefixhost}"
	    # qemu's configure does not accept a parameter like SHELL=/bin/bash
	    FORCESHELL=""
	    ;;
	*)
	    # ??? Why the default for --prefix is not "$prefix"?
	    opts="${opts} --build=${build} --host=${host} --target=${target} --prefix=${sysroots}/usr"
	    ;;
    esac

    if test -e ${builddir}/config.status -a x"${force}" = xno; then
	warning "${builddir} already configured!"
    else
	if [ x"$component" = x"gdbserver" ]; then
	    # Workaround missing dependency of gdbsupport on BFD.
	    # It'll take a while for binutils-gdb patch to propagate into
	    # releases, so patch code here as a workaround.
	    if ! grep -q "^configure-gdbsupport: maybe-configure-bfd\$" $srcdir/Makefile.in; then
		echo "configure-gdbsupport: maybe-configure-bfd" >> $srcdir/Makefile.in
	    fi
	fi
	# Don't stop on CONFIG_SHELL if it's set in the environment.
	if test x"${CONFIG_SHELL}" = x; then
	    # ??? exporting CONFIG_SHELL seems excessive.
	    export CONFIG_SHELL=${bash_shell}
	fi
        # Substitute '@@' with '$' in $opts because there's a GDB configure flag
        # whose value has literal dollar signs and they were typed in as '@@' to
        # preserve them from shell parameter expansion.
	dryrun "(cd ${builddir} && ${CONFIG_SHELL} ${srcdir}/configure $FORCESHELL ${default_configure_flags} ${opts//@@/\\$})"
	if test $? -gt 0; then
	    error "Configure of $1 failed."
	    return 1
	fi

	# unset this to avoid problems later
	unset default_configure_flags
	unset stage1_flags
	unset stage2_flags
    fi

    notice "Done configuring ${component}"

    create_stamp "${stampdir}" "${stamp}"

    return 0
}