Mercurial > hg > aboriginal
comparison root-filesystem.sh @ 711:20ba34b54140
Rename mini-native.sh to root-filesystem.sh, since that's what it builds.
author | Rob Landley <rob@landley.net> |
---|---|
date | Thu, 09 Apr 2009 23:53:05 -0500 |
parents | mini-native.sh@64cc63ad26ce |
children | 9282f84b31a1 |
comparison
equal
deleted
inserted
replaced
710:946b01b2cc7f | 711:20ba34b54140 |
---|---|
1 #!/bin/bash | |
2 | |
3 # Get lots of predefined environment variables and shell functions. | |
4 | |
5 source sources/include.sh || exit 1 | |
6 | |
7 # Purple. And why not? | |
8 echo -e "$NATIVE_COLOR" | |
9 | |
10 check_for_base_arch root-filesystem || exit 0 | |
11 | |
12 echo "=== Building minimal native development environment" | |
13 | |
14 rm -rf "${NATIVE_ROOT}" | |
15 | |
16 # Determine which directory layout we're using | |
17 | |
18 if [ ! -z "${NATIVE_TOOLSDIR}" ] | |
19 then | |
20 mkdir -p "${TOOLS}/bin" || dienow | |
21 | |
22 # Tell the wrapper script where to find the dynamic linker. | |
23 export UCLIBC_DYNAMIC_LINKER=/tools/lib/ld-uClibc.so.0 | |
24 UCLIBC_TOPDIR="${NATIVE_ROOT}" | |
25 UCLIBC_DLPREFIX="/tools" | |
26 else | |
27 mkdir -p "${NATIVE_ROOT}"/{tmp,proc,sys,dev,etc,home} || dienow | |
28 UCLIBC_TOPDIR="${TOOLS}" | |
29 for i in bin sbin lib | |
30 do | |
31 mkdir -p "$TOOLS/$i" || dienow | |
32 ln -s "usr/$i" "${NATIVE_ROOT}/$i" || dienow | |
33 done | |
34 fi | |
35 | |
36 # Copy qemu setup script and so on. | |
37 | |
38 cp -r "${SOURCES}/native/." "${TOOLS}/" && | |
39 cp "$SRCDIR"/MANIFEST "${TOOLS}/src" || dienow | |
40 | |
41 if [ -z "${NATIVE_TOOLSDIR}" ] | |
42 then | |
43 sed -i -e 's@/tools/@/usr/@g' "${TOOLS}/sbin/init.sh" || dienow | |
44 fi | |
45 | |
46 # Install Linux kernel headers. | |
47 | |
48 setupfor linux | |
49 # Install Linux kernel headers (for use by uClibc). | |
50 make headers_install -j "$CPUS" ARCH="${KARCH}" INSTALL_HDR_PATH="${TOOLS}" && | |
51 # This makes some very old package builds happy. | |
52 ln -s ../sys/user.h "${TOOLS}/include/asm/page.h" && | |
53 cd .. | |
54 | |
55 cleanup linux | |
56 | |
57 # Build and install uClibc. (We could just copy the one from the compiler | |
58 # toolchain, but this is cleaner.) | |
59 | |
60 setupfor uClibc | |
61 make CROSS="${ARCH}-" KCONFIG_ALLCONFIG="$(getconfig uClibc)" allnoconfig && | |
62 cp .config "${TOOLS}"/src/config-uClibc || dienow | |
63 | |
64 # Alas, if we feed install and install_utils to make at the same time with | |
65 # -j > 1, it dies. Not SMP safe. | |
66 for i in install install_utils | |
67 do | |
68 make CROSS="${ARCH}-" KERNEL_HEADERS="${TOOLS}/include" \ | |
69 PREFIX="${UCLIBC_TOPDIR}/" $VERBOSITY \ | |
70 RUNTIME_PREFIX="$UCLIBC_DLPREFIX/" DEVEL_PREFIX="$UCLIBC_DLPREFIX/" \ | |
71 UCLIBC_LDSO_NAME=ld-uClibc -j $CPUS $i || dienow | |
72 done | |
73 cd .. | |
74 | |
75 cleanup uClibc | |
76 | |
77 # Build and install toybox | |
78 | |
79 setupfor toybox | |
80 make defconfig && | |
81 if [ -z "$USE_TOYBOX" ] | |
82 then | |
83 make CROSS="${ARCH}-" && | |
84 cp toybox "$TOOLS/bin" && | |
85 ln -s toybox "$TOOLS/bin/patch" && | |
86 ln -s toybox "$TOOLS/bin/oneit" && | |
87 ln -s toybox "$TOOLS/bin/netcat" && | |
88 cd .. | |
89 else | |
90 make install_flat PREFIX="${TOOLS}"/bin CROSS="${ARCH}-" && | |
91 rm "${TOOLS}"/bin/sh && # Bash won't install if this exists. | |
92 cd .. | |
93 fi | |
94 | |
95 cleanup toybox | |
96 | |
97 # Build and install busybox | |
98 | |
99 setupfor busybox | |
100 make allyesconfig KCONFIG_ALLCONFIG="${SOURCES}/trimconfig-busybox" && | |
101 make -j $CPUS CROSS_COMPILE="${ARCH}-" $VERBOSITY && | |
102 make busybox.links && | |
103 cp busybox "${TOOLS}/bin" | |
104 | |
105 [ $? -ne 0 ] && dienow | |
106 | |
107 for i in $(sed 's@.*/@@' busybox.links) | |
108 do | |
109 ln -s busybox "${TOOLS}/bin/$i" # || dienow | |
110 done | |
111 cd .. | |
112 | |
113 cleanup busybox | |
114 | |
115 if [ "$NATIVE_TOOLCHAIN" == "none" ] | |
116 then | |
117 # If we're not installing a compiler, delete the headers, static libs, | |
118 # and example source code. | |
119 | |
120 rm -rf "${TOOLS}"/include && | |
121 rm -rf "${TOOLS}"/lib/*.a && | |
122 rm -rf "${TOOLS}/src" || dienow | |
123 | |
124 elif [ "$NATIVE_TOOLCHAIN" == "headers" ] | |
125 then | |
126 | |
127 # If you want to use a compiler other than gcc, you need to keep the headers, | |
128 # so do nothing here. | |
129 echo | |
130 | |
131 else | |
132 | |
133 # Build and install native binutils | |
134 | |
135 setupfor binutils build-binutils | |
136 CC="${ARCH}-gcc" AR="${ARCH}-ar" "${CURSRC}/configure" --prefix="${TOOLS}" \ | |
137 --build="${CROSS_HOST}" --host="${CROSS_TARGET}" --target="${CROSS_TARGET}" \ | |
138 --disable-nls --disable-shared --disable-multilib --program-prefix= \ | |
139 --disable-werror $BINUTILS_FLAGS && | |
140 make -j $CPUS configure-host && | |
141 make -j $CPUS && | |
142 make -j $CPUS install && | |
143 cd .. && | |
144 mkdir -p "${TOOLS}/include" && | |
145 cp binutils/include/libiberty.h "${TOOLS}/include" | |
146 | |
147 cleanup binutils build-binutils | |
148 | |
149 # Build and install native gcc, with c++ support this time. | |
150 | |
151 setupfor gcc-core build-gcc | |
152 setupfor gcc-g++ build-gcc gcc-core | |
153 # GCC tries to "help out in the kitchen" by screwing up the linux include | |
154 # files. Cut out those bits with sed and throw them away. | |
155 sed -i 's@^STMP_FIX.*@@' "${CURSRC}/gcc/Makefile.in" && | |
156 # GCC has some deep assumptions about the name of the cross-compiler it should | |
157 # be using. These assumptions are wrong, and lots of redundant corrections | |
158 # are required to make it stop. | |
159 CC="${ARCH}-gcc" GCC_FOR_TARGET="${ARCH}-gcc" CC_FOR_TARGET="${ARCH}-gcc" \ | |
160 AR="${ARCH}-ar" AR_FOR_TARGET="${ARCH}-ar" AS="${ARCH}-as" LD="${ARCH}-ld" \ | |
161 ac_cv_path_AR_FOR_TARGET="${ARCH}-ar" \ | |
162 ac_cv_path_RANLIB_FOR_TARGET="${ARCH}-ranlib" \ | |
163 ac_cv_path_NM_FOR_TARGET="${ARCH}-nm" \ | |
164 NM="${ARCH}-nm" NM_FOR_TARGET="${ARCH}-nm" CXX_FOR_TARGET="${ARCH}-g++" \ | |
165 "${CURSRC}/configure" --prefix="${TOOLS}" --disable-multilib \ | |
166 --build="${CROSS_HOST}" --host="${CROSS_TARGET}" --target="${CROSS_TARGET}" \ | |
167 --enable-long-long --enable-c99 --enable-shared --enable-threads=posix \ | |
168 --enable-__cxa_atexit --disable-nls --enable-languages=c,c++ \ | |
169 --disable-libstdcxx-pch --program-prefix="" \ | |
170 $GCC_FLAGS && | |
171 mkdir gcc && | |
172 ln -s `which "${ARCH}-gcc"` gcc/xgcc && | |
173 make -j $CPUS configure-host && | |
174 make -j $CPUS all-gcc && | |
175 # Work around gcc bug; we disabled multilib but it doesn't always notice. | |
176 ln -s lib "$TOOLS/lib64" && | |
177 make -j $CPUS install-gcc && | |
178 rm "$TOOLS/lib64" && | |
179 ln -s gcc "${TOOLS}/bin/cc" && | |
180 # Now we need to beat libsupc++ out of gcc (which uClibc++ needs to build). | |
181 # But don't want to build the whole of libstdc++-v3 because | |
182 # A) we're using uClibc++ instead, B) the build breaks. | |
183 make -j $CPUS configure-target-libstdc++-v3 && | |
184 cd "$CROSS_TARGET"/libstdc++-v3/libsupc++ && | |
185 make -j $CPUS && | |
186 mv .libs/libsupc++.a "$TOOLS"/lib && | |
187 cd ../../../.. | |
188 | |
189 cleanup gcc-core build-gcc | |
190 | |
191 # Move the gcc internal libraries and headers somewhere sane, and | |
192 # build and install gcc wrapper script. | |
193 | |
194 mkdir -p "${TOOLS}"/gcc && | |
195 mv "${TOOLS}"/lib/gcc/*/*/include "${TOOLS}"/gcc/include && | |
196 mv "${TOOLS}"/lib/gcc/*/* "${TOOLS}"/gcc/lib && | |
197 mv "${TOOLS}/bin/gcc" "${TOOLS}/bin/rawgcc" && | |
198 "${ARCH}-gcc" "${SOURCES}"/toys/ccwrap.c -Os -s -o "${TOOLS}/bin/gcc" \ | |
199 -DGCC_UNWRAPPED_NAME='"rawgcc"' -DGIMME_AN_S && | |
200 | |
201 # Wrap C++ | |
202 mv "${TOOLS}/bin/g++" "${TOOLS}/bin/rawg++" && | |
203 ln "${TOOLS}/bin/gcc" "${TOOLS}/bin/g++" && | |
204 rm "${TOOLS}/bin/c++" && | |
205 ln -s g++ "${TOOLS}/bin/c++" | |
206 | |
207 cleanup "${TOOLS}"/{lib/gcc,gcc/lib/install-tools,bin/${ARCH}-unknown-*} | |
208 | |
209 # Tell future packages to link against the libraries in root-filesystem, | |
210 # rather than the ones in the cross compiler directory. | |
211 | |
212 export WRAPPER_TOPDIR="${TOOLS}" | |
213 | |
214 # Build and install uClibc++ | |
215 | |
216 setupfor uClibc++ | |
217 CROSS= make defconfig && | |
218 sed -r -i 's/(UCLIBCXX_HAS_(TLS|LONG_DOUBLE))=y/# \1 is not set/' .config && | |
219 sed -r -i '/UCLIBCXX_RUNTIME_PREFIX=/s/".*"/""/' .config && | |
220 CROSS= make oldconfig && | |
221 CROSS="$ARCH"- make && | |
222 CROSS= make install PREFIX="${TOOLS}/c++" && | |
223 | |
224 # Move libraries somewhere useful. | |
225 | |
226 mv "${TOOLS}"/c++/lib/* "${TOOLS}"/lib && | |
227 rm -rf "${TOOLS}"/c++/{lib,bin} && | |
228 ln -s libuClibc++.so "${TOOLS}"/lib/libstdc++.so && | |
229 ln -s libuClibc++.a "${TOOLS}"/lib/libstdc++.a && | |
230 cd .. | |
231 | |
232 cleanup uClibc++ | |
233 | |
234 # Build and install make | |
235 | |
236 setupfor make | |
237 CC="${ARCH}-gcc" ./configure --prefix="${TOOLS}" --build="${CROSS_HOST}" \ | |
238 --host="${CROSS_TARGET}" && | |
239 make -j $CPUS && | |
240 make -j $CPUS install && | |
241 cd .. | |
242 | |
243 cleanup make | |
244 | |
245 # Remove the busybox /bin/sh link so the bash install doesn't get upset. | |
246 | |
247 rm "$TOOLS"/bin/sh | |
248 | |
249 # Build and install bash. (Yes, this is an old version. I prefer it.) | |
250 # I plan to replace it with toysh anyway. | |
251 | |
252 setupfor bash | |
253 # wire around some tests ./configure can't run when cross-compiling. | |
254 cat > config.cache << EOF && | |
255 ac_cv_func_setvbuf_reversed=no | |
256 bash_cv_sys_named_pipes=yes | |
257 bash_cv_have_mbstate_t=yes | |
258 bash_cv_getenv_redef=no | |
259 EOF | |
260 CC="${ARCH}-gcc" RANLIB="${ARCH}-ranlib" ./configure --prefix="${TOOLS}" \ | |
261 --build="${CROSS_HOST}" --host="${CROSS_TARGET}" --cache-file=config.cache \ | |
262 --without-bash-malloc --disable-readline && | |
263 # note: doesn't work with -j | |
264 make && | |
265 make install && | |
266 # Make bash the default shell. | |
267 ln -s bash "${TOOLS}/bin/sh" && | |
268 cd .. | |
269 | |
270 cleanup bash | |
271 | |
272 setupfor distcc | |
273 CC="${ARCH}-cc" ./configure --host="${CROSS_TARGET}" --prefix="${TOOLS}" \ | |
274 --with-included-popt --disable-Werror && | |
275 make -j $CPUS && | |
276 make -j $CPUS install && | |
277 mkdir -p "${TOOLS}/distcc" || dienow | |
278 | |
279 for i in gcc cc g++ c++ | |
280 do | |
281 ln -s ../bin/distcc "${TOOLS}/distcc/$i" || dienow | |
282 done | |
283 cd .. | |
284 | |
285 cleanup distcc | |
286 | |
287 # Put statically and dynamically linked hello world programs on there for | |
288 # test purposes. | |
289 | |
290 "${ARCH}-gcc" "${SOURCES}/toys/hello.c" -Os -s -o "${TOOLS}/bin/hello-dynamic" && | |
291 "${ARCH}-gcc" "${SOURCES}/toys/hello.c" -Os -s -static -o "${TOOLS}/bin/hello-static" | |
292 | |
293 [ $? -ne 0 ] && dienow | |
294 | |
295 # Delete some unneeded files | |
296 | |
297 rm -rf "${TOOLS}"/{info,man,libexec/gcc/*/*/install-tools} | |
298 | |
299 # End of NATIVE_TOOLCHAIN | |
300 | |
301 fi | |
302 | |
303 # Clean up and package the result | |
304 | |
305 "${ARCH}-strip" "${TOOLS}"/{bin/*,sbin/*,libexec/gcc/*/*/*} | |
306 "${ARCH}-strip" --strip-unneeded "${TOOLS}"/lib/*.so | |
307 | |
308 create_stage_tarball root-filesystem | |
309 | |
310 if [ ! -z "$NATIVE_RETROFIT_CXX" ] | |
311 then | |
312 [ -z "$NATIVE_TOOLSDIR" ] && SUBDIR=usr || SUBDIR=tools | |
313 | |
314 (cd "${BUILD}/root-filesystem-$ARCH"/$SUBDIR && | |
315 tar c c++ lib/*c++* lib/libgcc_s.so* || dienow) | | |
316 (tar xC "${BUILD}/cross-compiler-$ARCH" || dienow) | |
317 | |
318 create_stage_tarball cross-compiler | |
319 fi | |
320 | |
321 # Color back to normal | |
322 echo -e "\e[0mBuild complete" |