summaryrefslogtreecommitdiffstats
path: root/EXTERNAL/mk-arm-hard
blob: 14cb6bf263f18f34b460373f596b1e85e600c1de (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
#! /bin/sh

INSTDIR=/opt/cross/arm-unknown
ARCH=arm
TARGET=arm-unknown-linux-gnu
HOST=i686-pc-linux-gnu

SYSROOT=$INSTDIR/sys-root-hard
HEADERDIR=$SYSROOT/usr/include
BINDIR=linuxthreads-hard

SYSROOTNPTL=$INSTDIR/sys-root-nptl-hard
HEADERDIRNPTL=$SYSROOTNPTL/usr/include
BINDIRNPTL=nptl-hard

ORIGPATH=$PATH

cleanup() {
  # cleanup
  sudo rm -rf ep-hard-*
  sudo rm -rf $SYSROOT
  sudo rm -rf $SYSROOTNPTL
  sudo rm -rf $BINDIR
  sudo rm -rf $BINDIRNPTL
}

create_sys_root() {
  # create sys-root
  mkdir -p $SYSROOT/lib
  mkdir -p $SYSROOT/usr/lib
  mkdir -p $HEADERDIR
}

create_sys_root_nptl() {
  # create sys-root-nptl
  mkdir -p $SYSROOTNPTL/lib
  mkdir -p $SYSROOTNPTL/usr/lib
  mkdir -p $HEADERDIRNPTL
}

prepare_kernel() {
  # prepare kernel
  pushd linux
  make distclean
  make ARCH=$ARCH edb7211_defconfig
  make ARCH=$ARCH include/asm include/linux/version.h include/asm-$ARCH/.arch

  cp -r include/linux $HEADERDIR
  cp -r include/asm-${ARCH} $HEADERDIR/asm
  cp -r include/asm-generic $HEADERDIR/asm-generic

  cp -r include/linux $HEADERDIRNPTL
  cp -r include/asm-${ARCH} $HEADERDIRNPTL/asm
  cp -r include/asm-generic $HEADERDIRNPTL/asm-generic

  popd
}

build_binutils() {
  # build binutils
  mkdir -p ep-hard-binutils

  pushd ep-hard-binutils
  ../binutils/configure --target=$TARGET --host=$HOST --with-sysroot=$SYSROOT \
	--prefix=$INSTDIR/$BINDIR
  make
  sudo make install

  ../binutils/configure --target=$TARGET --host=$HOST \
  	--with-sysroot=$SYSROOTNPTL --prefix=$INSTDIR/$BINDIRNPTL
  make
  sudo make install

  popd
}

glibc_header() {
  # glibc-header
  mkdir -p ep-hard-glibc-header

  pushd ep-hard-glibc-header
  libc_cv_ppc_machine=yes ../libc/configure --prefix=/usr \
	--build=$HOST --host=$TARGET --without-cvs \
	--disable-sanity-checks --with-headers=$HEADERDIR \
	--enable-hacker-mode

  libc_cv_ppc_machine=yes make sysdeps/gnu/errlist.c
  mkdir -p stdio-common
  touch stdio-common/errlist-compat.c

  libc_cv_ppc_machine=yes make cross-compiling=yes install_root=$SYSROOT \
	install-headers
  mkdir -p $HEADERDIR/gnu
  touch $HEADERDIR/gnu/stubs.h
  cp ../libc/include/features.h $HEADERDIR/features.h
  cp bits/stdio_lim.h $HEADERDIR/bits/stdio_lim.h

  libc_cv_ppc_machine=yes make cross-compiling=yes install_root=$SYSROOTNPTL \
	install-headers
  mkdir -p $HEADERDIRNPTL/gnu
  touch $HEADERDIRNPTL/gnu/stubs.h
  cp ../libc/include/features.h $HEADERDIRNPTL/features.h
  cp bits/stdio_lim.h $HEADERDIRNPTL/bits/stdio_lim.h

  popd
}

build_gcc_core() {
  # build gcc-core
  export PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH
  mkdir -p ep-hard-gcc-core

  pushd ep-hard-gcc-core
  ../gcc-arm/configure --target=$TARGET --host=$HOST \
	--with-local-prefix=$SYSROOT --disable-multilib --with-newlib \
	--with-sysroot=$SYSROOT --enable-threads=no \
	--enable-symvers=gnu --enable-__cxa_atexit --enable-languages=c \
	--disable-shared --prefix=$INSTDIR/$BINDIR
  make all-gcc
  sudo make PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH install-gcc
  popd
}

build_glibc_linuxthreads() {
  # build glibc/linuxthreads
  export PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH

  mkdir -p ep-hard-glibc
  sudo touch $INSTDIR/$BINDIR/lib/gcc/arm-unknown-linux-gnu/3.4.3/libgcc_s.a

  pushd ep-hard-glibc
  #BUILD_CC=gcc CFLAGS="-O2 -funroll-loops -mcpu=ep9312 -mfpu=maverick" \
  BUILD_CC=gcc CFLAGS="-O2 -funroll-loops" \
  CC=$TARGET-gcc AR=$TARGET-ar RANLIB=$TARGET-ranlib \
  ../libc/configure --prefix=/usr \
	--build=$HOST --host=$TARGET \
	--enable-kernel=2.4.3 --without-cvs --disable-profile \
	--disable-debug --without-gd --without-tls --without-__thread \
	--enable-shared --enable-add-ons=linuxthreads --enable-omitfp \
	--without-fp --with-headers=$HEADERDIR
  make LD=$TARGET-ld RANLIB=$TARGET-ranlib lib
  make install_root=$SYSROOT install-lib-all install-headers
  popd

  sudo rm $INSTDIR/$BINDIR/lib/gcc/arm-unknown-linux-gnu/3.4.3/libgcc_s.a
}

build_final_gcc() {
  # build final gcc
  export PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH

  mkdir -p ep-hard-gcc
  pushd ep-hard-gcc
  ac_cv_lib_m_main=yes ../gcc-arm/configure --target=$TARGET --host=$HOST \
	--with-local-prefix=$SYSROOT --with-sysroot=$SYSROOT \
	--enable-threads=posix --enable-symvers=gnu \
	--enable-__cxa_atexit --enable-languages="c,c++" \
	--enable-shared --enable-c99 --enable-long-long \
	--prefix=$INSTDIR/$BINDIR --enable-multilib
  make all
  sudo make PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH install
  popd
}

build_glibc_NPTL() {
  # build glibc-NPTL
  export PATH=$INSTDIR/$BINDIR/bin:$ORIGPATH

  mkdir -p ep-hard-glibc-nptl
  pushd ep-hard-glibc-nptl
  #BUILD_CC=gcc CFLAGS="-O2 -funroll-loops -mcpu=ep9312 -mfpu=maverick"  -mtp=linux" \
  BUILD_CC=gcc CFLAGS="-O2 -funroll-loops -mtp=soft" \
  CC=$TARGET-gcc AR=$TARGET-ar RANLIB=$TARGET-ranlib \
  ../libc/configure --prefix=/usr \
	--build=$HOST --host=$TARGET \
	--enable-kernel=2.4.3 --without-cvs --disable-profile \
	--enable-debug --without-gd --with-tls --with-__thread \
	--enable-shared --enable-add-ons=nptl --enable-profile \
	--without-fp --with-headers=$HEADERDIRNPTL
  make LD=$TARGET-ld RANLIB=$TARGET-ranlib lib
  make install_root=$SYSROOTNPTL install-lib-all install-headers
  popd
}

build_final_nptl_gcc() {
  # build final nptl gcc
  export PATH=$INSTDIR/$BINDIRNPTL/bin:$ORIGPATH
  mkdir -p ep-hard-gcc-nptl

  pushd ep-hard-gcc-nptl
  ac_cv_lib_m_main=yes ../gcc-arm/configure --target=$TARGET --host=$HOST \
	--with-local-prefix=$SYSROOTNPTL --with-sysroot=$SYSROOTNPTL \
	--enable-threads=posix --enable-symvers=gnu \
	--enable-__cxa_atexit --enable-languages="c,c++" \
	--enable-shared --enable-c99 --enable-long-long \
	--prefix=$INSTDIR/$BINDIRNPTL \
  #	--enable-cxx-flags='-mcpu=ep9312 -mfpu=maverick'
  make all
  sudo make PATH=$INSTDIR/$BINDIRNPTL/bin:$ORIGPATH install
  popd
}

build_gdb() {
  # build gdb
  pushd ep-hard-binutils

  mkdir readline
  cd readline
  ../../binutils-complete/readline/configure --target=$TARGET --host=$HOST
  make
  cd ..
  mkdir gdb
  cd gdb
  ../../binutils-complete/gdb/configure --target=$TARGET --host=$HOST \
  	--with-sysroot=$SYSROOT --prefix=$INSTDIR/$BINDIR \
	--enable-tui --disable-gdbtk
  make
  sudo make install

  ../../binutils-complete/gdb/configure --target=$TARGET --host=$HOST \
  	--with-sysroot=$SYSROOTNPTL --prefix=$INSTDIR/$BINDIRNPTL \
	--enable-tui --disable-gdbtk
  make
  sudo make install

  cd ..
  popd
}

err() {
	echo Failed to build $1
	exec false
}

keystroke() {
#	read -n1 -p "$@ [key to continue]"
	echo "*** $@ ***"
}

### MAIN ###

keystroke "cleanup"
cleanup

keystroke "create sys_root"
create_sys_root

keystroke "create sys_root_nptl"
create_sys_root_nptl

keystroke "prepare kernel"
prepare_kernel

keystroke "binutils"
build_binutils

keystroke "glibc header"
glibc_header

keystroke "gcc core"
build_gcc_core

keystroke "glibc linuxthreads"
build_glibc_linuxthreads

keystroke "final gcc linuxthreads"
build_final_gcc

keystroke "glibc nptl"
build_glibc_NPTL

keystroke "final gcc nptl"
build_final_nptl_gcc

keystroke "gdb"
build_gdb