Mercurial > hg > aboriginal
comparison mini-native.sh @ 43:6d16887ec084
Intermediate snapshot. Doesn't work yet.
author | Rob Landley <rob@landley.net> |
---|---|
date | Sun, 17 Dec 2006 14:21:02 -0500 |
parents | |
children | 41e82517e123 |
comparison
equal
deleted
inserted
replaced
42:7b0f34fbc35a | 43:6d16887ec084 |
---|---|
1 #!/bin/sh | |
2 | |
3 # Get lots of predefined environment variables and shell functions. | |
4 | |
5 source include.sh | |
6 TOOLS="${NATIVE}/tools" | |
7 | |
8 mkdir -p "${TOOLS}/bin" || dienow | |
9 | |
10 if false | |
11 then | |
12 | |
13 # Build qemu | |
14 setupfor qemu && | |
15 ./configure --disable-gcc-check --prefix="${NATIVE}" && | |
16 make && | |
17 make install && | |
18 cd .. && | |
19 $CLEANUP qemu-* | |
20 | |
21 [ $? -ne 0 ] && dienow | |
22 | |
23 setupfor linux | |
24 # Install Linux kernel headers (for use by uClibc). | |
25 make headers_install ARCH="${KARCH}" INSTALL_HDR_PATH="${TOOLS}" && | |
26 # build bootable kernel for target | |
27 mv "${WORK}/config-linux" .config && | |
28 (yes "" | make ARCH="${KARCH}" oldconfig) && | |
29 make ARCH="${KARCH}" CROSS_COMPILE="${ARCH}-" && | |
30 cp "${KERNEL_PATH}" "${NATIVE}/zImage-${ARCH}" && | |
31 cd .. && | |
32 $CLEANUP linux-* | |
33 | |
34 [ $? -ne 0 ] && dienow | |
35 | |
36 # Build and install busybox | |
37 | |
38 setupfor busybox | |
39 make defconfig && | |
40 make CONFIG_STATIC=y CROSS_COMPILE="${ARCH}-" && | |
41 cp busybox "${TOOLS}/bin" | |
42 [ $? -ne 0 ] && dienow | |
43 for i in $(sed 's@.*/@@' busybox.links) | |
44 do | |
45 ln -s busybox "${TOOLS}/bin/$i" || dienow | |
46 done | |
47 cd .. && | |
48 $CLEANUP busybox | |
49 | |
50 [ $? -ne 0 ] && dienow | |
51 | |
52 # Build and install native binutils | |
53 | |
54 setupfor binutils build-binutils | |
55 CC="${ARCH}"-gcc AR="${ARCH}"-ar "${CURSRC}/configure" --prefix="${TOOLS}" \ | |
56 --build="${CROSS_HOST}" --host=${CROSS_TARGET} --target=${CROSS_TARGET} \ | |
57 --disable-nls --disable-shared --disable-multilib $BINUTILS_FLAGS && | |
58 make configure-host && | |
59 make && | |
60 make install && | |
61 cd .. && | |
62 mkdir -p "${TOOLS}/include" && | |
63 cp binutils-*/include/libiberty.h "${TOOLS}/include" && | |
64 $CLEANUP binutils-* build-binutils | |
65 | |
66 [ $? -ne 0 ] && dienow | |
67 | |
68 # Build and install native gcc, with c++ support this time. | |
69 | |
70 setupfor gcc-core build-gcc gcc- | |
71 echo -n "Adding c++" && | |
72 (tar xvjCf "${WORK}" "${LINKDIR}/gcc-g++.tar.bz2" || dienow ) | dotprogress && | |
73 CC="${ARCH}-gcc" AS="${ARCH-gcc}" LD="${ARCH}-ld" "${CURSRC}/configure" \ | |
74 --prefix="${TOOLS}" --disable-multilib \ | |
75 --build="${CROSS_HOST}" --host="${CROSS_TARGET}" --target="${CROSS_TARGET}" \ | |
76 --enable-long-long --enable-c99 --enable-shared --enable-threads=posix \ | |
77 --enable-__cxa_atexit --disable-nls --enable-languages=c,c++ \ | |
78 --disable-libstdcxx-pch && | |
79 cd "${WORK}"/build-gcc && | |
80 | |
81 make all-gcc && # CC_FOR_TARGET="${ARCH}-gcc" AS_FOR_TARGET="${ARCH}-as" \ | |
82 # LD_FOR_TARGET="${ARCH}-ld" all-gcc && | |
83 make install-gcc && | |
84 ln -s gcc "${TOOLS}/bin/cc" && | |
85 cd .. && | |
86 $CLEANUP gcc-* build-gcc | |
87 | |
88 [ $? -ne 0 ] && dienow | |
89 | |
90 # Move the gcc internal libraries and headers somewhere sane. | |
91 | |
92 mkdir -p "${TOOLS}"/gcc && | |
93 mv "${TOOLS}"/lib/gcc/*/*/include "${TOOLS}"/gcc/include && | |
94 mv "${TOOLS}"/lib/gcc/*/* "${TOOLS}"/gcc/lib && | |
95 $CLEANUP "${TOOLS}"/{lib/gcc,gcc/lib/install-tools} && | |
96 | |
97 exit 0 | |
98 | |
99 # Build and install gcc wrapper script. | |
100 | |
101 mv "$GCCNAME" "${CROSS}"/bin/gcc-unwrapped && | |
102 gcc "${TOP}"/sources/toys/gcc-uClibc.c -Os -s -o "$GCCNAME" | |
103 | |
104 [ $? -ne 0 ] && dienow | |
105 | |
106 # Install the linux kernel, and kernel headers. | |
107 | |
108 setupfor linux | |
109 # Configure kernel | |
110 ##mv "${WORK}"/config-linux .config && | |
111 ##(yes "" | make ARCH="${KARCH}" oldconfig) && | |
112 # Install Linux kernel headers (for use by uClibc). | |
113 make headers_install ARCH="${KARCH}" INSTALL_HDR_PATH="${CROSS}" && | |
114 # Build bootable kernel for target. | |
115 ##make ARCH="${KARCH}" CROSS_COMPILE="${CROSS_TARGET}"- && | |
116 ##cp "${KERNEL_PATH}" "${CROSS}"/zImage && | |
117 cd .. && | |
118 $CLEANUP linux-* | |
119 | |
120 [ $? -ne 0 ] && dienow | |
121 | |
122 # Build and install uClibc | |
123 | |
124 setupfor uClibc | |
125 cp "${WORK}"/config-uClibc .config && | |
126 (yes "" | make CROSS="${CROSS_TARGET}"- oldconfig) && | |
127 make CROSS="${CROSS_TARGET}"- KERNEL_SOURCE="${CROSS}" && | |
128 #make CROSS="${CROSS_TARGET}"- utils && | |
129 # The kernel headers are already installed, but uClibc's install will try to | |
130 # be "helpful" and copy them over themselves, at which point hilarity ensues. | |
131 # Make it not do that. | |
132 rm include/{asm,asm-generic,linux} && | |
133 make CROSS="${CROSS_TARGET}"- KERNEL_SOURCE="${CROSS}"/ \ | |
134 RUNTIME_PREFIX="${CROSS}"/ DEVEL_PREFIX="${CROSS}"/ \ | |
135 install_runtime install_dev && | |
136 # The uClibc build uses ./include instead of ${CROSS}/include, so the symlinks | |
137 # need to come back. (Yes, it links against the _headers_ from the source, | |
138 # but against the _libraries_ from the destination. Hence needing to install | |
139 # libc.so before building utils.) | |
140 ln -s "${CROSS}"/include/linux include/linux && | |
141 ln -s "${CROSS}"/include/asm include/asm && | |
142 ln -s "${CROSS}"/include/asm-generic include/asm-generic && | |
143 make CROSS=${CROSS_TARGET}- RUNTIME_PREFIX="${CROSS}"/ install_utils && | |
144 cd .. && | |
145 $CLEANUP uClibc* | |
146 | |
147 [ $? -ne 0 ] && dienow | |
148 | |
149 # A quick hello world program to test the cross-compiler out. | |
150 | |
151 cat > "$WORK"/hello.c << 'EOF' && | |
152 #include <stdio.h> | |
153 | |
154 int main(int argc, char *argv[]) | |
155 { | |
156 printf("Hello world!\n"); | |
157 return 0; | |
158 } | |
159 EOF | |
160 | |
161 # Build hello.c dynamic, then static, to verify header/library paths. | |
162 | |
163 "$GCCNAME" -Os "$WORK"/hello.c -o "$WORK"/hello && | |
164 "$GCCNAME" -Os -static "$WORK"/hello.c -o "$WORK"/hello && | |
165 [ x"$(qemu-"${KARCH}" "${WORK}"/hello)" == x"Hello world!" ] && | |
166 echo Cross-toolchain seems to work. | |
167 | |
168 [ $? -ne 0 ] && dienow | |
169 | |
170 # Change the FSF's crazy names to something reasonable. | |
171 | |
172 cd "${CROSS}"/bin && | |
173 for i in "${ARCH}"-* | |
174 do | |
175 strip "$i" | |
176 mv "$i" "${ARCH}"-"$(echo "$i" | sed 's/.*-//')" | |
177 done | |
178 | |
179 cat > "${CROSS}"/README << "EOF" && | |
180 Cross compiler for $ARCH | |
181 From http://landley.net/code/firmware | |
182 | |
183 To use: Add the \"bin\" directory to your \$PATH, and use \"$ARCH-gcc\" as | |
184 your compiler. | |
185 | |
186 The syntax used to build the Linux kernel is: | |
187 | |
188 make ARCH="${KARCH}" CROSS_COMPILE="${ARCH}"- | |
189 | |
190 EOF | |
191 | |
192 # Tar up the cross compiler. | |
193 cd "${TOP}" | |
194 tar cjvCf build cross-compiler-"${ARCH}".tar.bz2 cross-compiler-"${ARCH}" && | |
195 | |
196 [ $? -ne 0 ] && dienow |