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
|
#!/usr/bin/env bash
export source=$1
set +h
umask 022
export MELVIX=/home/melvix/os
cd ${MELVIX}
export LC_ALL=POSIX
export PATH=${MELVIX}/cross-tools/bin:/bin:/usr/bin
mkdir -p ${MELVIX}/sources
cd ${MELVIX}/sources
echo -en " Downloading resources"
curl -sSL "http://ftp.gnu.org/gnu/binutils/binutils-2.32.tar.xz" | tar xJ
curl -sSL "https://busybox.net/downloads/busybox-1.31.0.tar.bz2" | tar xj
curl -sSL "https://github.com/cross-lfs/bootscripts-embedded/archive/master.tar.gz" | tar xz
curl -sSL "https://gcc.gnu.org/pub/gcc/releases/gcc-9.1.0/gcc-9.1.0.tar.xz" | tar xJ
curl -sSL "http://ftp.gnu.org/gnu/gmp/gmp-6.1.2.tar.xz" | tar xJ
curl -sSL "https://mirrors.edge.kernel.org/pub/linux/kernel/v5.x/linux-5.1.tar.xz" | tar xJ
curl -sSL "http://ftp.gnu.org/gnu/mpc/mpc-1.1.0.tar.gz" | tar xz
curl -sSL "http://ftp.gnu.org/gnu/glibc/glibc-2.29.tar.xz" | tar xJ
curl -sSL "http://ftp.gnu.org/gnu/mpfr/mpfr-4.0.2.tar.xz" | tar xJ
curl -sSL "https://www.zlib.net/zlib-1.2.11.tar.xz" | tar xJ
cd ${MELVIX}
echo -en "\r Initializing filesystem structure"
mkdir -p ${MELVIX}/{bin,boot{,/grub},dev,{etc/,}opt,home,lib/{firmware,modules},lib64,mnt}
mkdir -p ${MELVIX}/{proc,media/{floppy,cdrom},sbin,srv,sys}
mkdir -p ${MELVIX}/var/{lock,log,mail,run,spool}
mkdir -p ${MELVIX}/var/{opt,cache,lib/{misc,locate},local}
install -d -m 0750 ${MELVIX}/root &> /dev/null
install -d -m 1777 ${MELVIX}{/var,}/tmp &> /dev/null
install -d ${MELVIX}/etc/init.d &> /dev/null
mkdir -p ${MELVIX}/usr/{,local/}{bin,include,lib{,64},sbin,src}
mkdir -p ${MELVIX}/usr/{,local/}share/{doc,info,locale,man}
mkdir -p ${MELVIX}/usr/{,local/}share/{misc,terminfo,zoneinfo}
mkdir -p ${MELVIX}/usr/{,local/}share/man/man{1,2,3,4,5,6,7,8}
for dir in ${MELVIX}/usr{,/local}; do
ln -s share/{man,doc,info} ${dir} &> /dev/null
done
install -d ${MELVIX}/cross-tools{,/bin} &> /dev/null
ln -sf /proc/mounts ${MELVIX}/etc/mtab
echo "melvix" > ${MELVIX}/etc/HOSTNAME
touch ${MELVIX}/var/run/utmp ${MELVIX}/var/log/{btmp,lastlog,wtmp}
chmod 664 ${MELVIX}/var/run/utmp ${MELVIX}/var/log/lastlog
unset CFLAGS
unset CXXFLAGS
export MELVIX_HOST=$(echo ${MACHTYPE} | sed "s/-[^-]*/-cross/")
export MELVIX_TARGET=x86_64-unknown-linux-gnu
export MELVIX_CPU=k8
export MELVIX_ARCH=$(echo ${MELVIX_TARGET} | sed -e 's/-.*//' -e 's/i.86/i386/')
export MELVIX_ENDIAN=little
echo -en "\r Building kernel headers"
cd ${MELVIX}/sources/linux-5.1/
make mrproper &> /dev/null
make ARCH=${MELVIX_ARCH} headers_check &> /dev/null
make ARCH=${MELVIX_ARCH} INSTALL_HDR_PATH=dest headers_install &> /dev/null
cp -r dest/include/* ${MELVIX}/usr/include
echo -en "\r Building binutils"
mkdir ${MELVIX}/sources/binutils-build/
cd ${MELVIX}/sources/binutils-build/
../binutils-2.32/configure --prefix=${MELVIX}/cross-tools --target=${MELVIX_TARGET} --with-sysroot=${MELVIX} --disable-nls --enable-shared --disable-multilib &> /dev/null
make configure-host &> /dev/null
make &> /dev/null
ln -s lib ${MELVIX}/cross-tools/lib64
make install &> /dev/null
cp ../binutils-2.32/include/libiberty.h ${MELVIX}/usr/include
echo -en "\r Building static gcc"
cd ${MELVIX}/sources/
mv gmp-6.1.2 gcc-9.1.0/gmp/
mv mpc-1.1.0 gcc-9.1.0/mpc/
mv mpfr-4.0.2 gcc-9.1.0/mpfr/
mkdir ${MELVIX}/sources/gcc-static
cd ${MELVIX}/sources/gcc-static
AR=ar LDFLAGS="-Wl,-rpath,${MELVIX}/cross-tools/lib" \
../gcc-9.1.0/configure --prefix=${MELVIX}/cross-tools \
--build=${MELVIX_HOST} --host=${MELVIX_HOST} \
--target=${MELVIX_TARGET} \
--with-sysroot=${MELVIX}/target --disable-nls \
--disable-shared \
--with-mpfr-include=$(pwd)/../gcc-9.1.0/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs \
--without-headers --with-newlib --disable-decimal-float \
--disable-libgomp --disable-libmudflap --disable-libssp \
--disable-threads --enable-languages=c,c++ \
--disable-multilib --with-arch=${MELVIX_CPU} &> /dev/null
make all-gcc all-target-libgcc &> /dev/null
make install-gcc install-target-libgcc &> /dev/null
ln -s libgcc.a `${MELVIX_TARGET}-gcc -print-libgcc-file-name | sed 's/libgcc/&_eh/'`
echo -en "\r Building glibc"
mkdir ${MELVIX}/sources/glibc-build
cd ${MELVIX}/sources/glibc-build
echo "libc_cv_forced_unwind=yes" > config.cache
echo "libc_cv_c_cleanup=yes" >> config.cache
echo "libc_cv_ssp=no" >> config.cache
echo "libc_cv_ssp_strong=no" >> config.cache
BUILD_CC="gcc" CC="${MELVIX_TARGET}-gcc" \
AR="${MELVIX_TARGET}-ar" \
RANLIB="${MELVIX_TARGET}-ranlib" CFLAGS="-O2" \
../glibc-2.29/configure --prefix=/usr \
--host=${MELVIX_TARGET} --build=${MELVIX_HOST} \
--disable-profile --enable-add-ons --with-tls \
--enable-kernel=2.6.32 --with-__thread \
--with-binutils=${MELVIX}/cross-tools/bin \
--with-headers=${MELVIX}/usr/include \
--cache-file=config.cache &> /dev/null
make &> /dev/null
make install_root=${MELVIX}/ install &> /dev/null
echo -en "\r Building gcc"
mkdir ${MELVIX}/sources/gcc-build
cd ${MELVIX}/sources/gcc-build
AR=ar LDFLAGS="-Wl,-rpath,${MELVIX}/cross-tools/lib" \
../gcc-9.1.0/configure --prefix=${MELVIX}/cross-tools \
--build=${MELVIX_HOST} --target=${MELVIX_TARGET} \
--host=${MELVIX_HOST} --with-sysroot=${MELVIX} \
--disable-nls --enable-shared \
--enable-languages=c,c++ --enable-c99 \
--enable-long-long \
--with-mpfr-include=$(pwd)/../gcc-9.1.0/mpfr/src \
--with-mpfr-lib=$(pwd)/mpfr/src/.libs \
--disable-multilib --with-arch=${MELVIX_CPU} &> /dev/null
make &> /dev/null
make install &> /dev/null
cp ${MELVIX}/cross-tools/${MELVIX_TARGET}/lib64/libgcc_s.so.1 ${MELVIX}/lib64
export CC="${MELVIX_TARGET}-gcc"
export CXX="${MELVIX_TARGET}-g++"
export CPP="${MELVIX_TARGET}-gcc -E"
export AR="${MELVIX_TARGET}-ar"
export AS="${MELVIX_TARGET}-as"
export LD="${MELVIX_TARGET}-ld"
export RANLIB="${MELVIX_TARGET}-ranlib"
export READELF="${MELVIX_TARGET}-readelf"
export STRIP="${MELVIX_TARGET}-strip"
echo -en "\r Building busybox"
cd ${MELVIX}/sources/busybox-1.31.0
make CROSS_COMPILE="${MELVIX_TARGET}-" defconfig &> /dev/null
# make CROSS_COMPILE="${MELVIX_TARGET}-" menuconfig
make CROSS_COMPILE="${MELVIX_TARGET}-" &> /dev/null
make CROSS_COMPILE="${MELVIX_TARGET}-" CONFIG_PREFIX="${MELVIX}" install &> /dev/null
cp examples/depmod.pl ${MELVIX}/cross-tools/bin
chmod 755 ${MELVIX}/cross-tools/bin/depmod.pl
echo -en "\r Building kernel"
cd ${MELVIX}/sources/linux-5.1
make ARCH=${MELVIX_ARCH} CROSS_COMPILE=${MELVIX_TARGET}- x86_64_defconfig &> /dev/null
mv ${MELVIX}/kernel.conf ${MELVIX}/sources/linux-5.1/.config
# make ARCH=${MELVIX_ARCH} CROSS_COMPILE=${MELVIX_TARGET}- menuconfig
make ARCH=${MELVIX_ARCH} CROSS_COMPILE=${MELVIX_TARGET}- &> /dev/null
make ARCH=${MELVIX_ARCH} CROSS_COMPILE=${MELVIX_TARGET}- INSTALL_MOD_PATH=${MELVIX} modules_install &> /dev/null
cp arch/x86/boot/bzImage ${MELVIX}/boot/vmlinuz
cp System.map ${MELVIX}/boot/System.map
cp .config ${MELVIX}/boot/config
${MELVIX}/cross-tools/bin/depmod.pl -F ${MELVIX}/boot/System.map -b ${MELVIX}/lib/modules/5.1.0 &> /dev/null
echo -en "\r Installing boot scripts"
cd ${MELVIX}/sources/bootscripts-embedded-master
make DESTDIR=${MELVIX}/ install-bootscripts &> /dev/null
ln -s ../rc.d/startup ${MELVIX}/etc/init.d/rcS
echo -en "\r Building zlib"
cd ${MELVIX}/sources/zlib-1.2.11
sed -i 's/-O3/-Os/g' configure
./configure --prefix=/usr --shared &> /dev/null
make &> /dev/null
make DESTDIR=${MELVIX}/ install &> /dev/null
mv ${MELVIX}/usr/lib/libz.so.* ${MELVIX}/lib
ln -sf ../../lib/libz.so.1 ${MELVIX}/usr/lib/libz.so
ln -sf ../../lib/libz.so.1 ${MELVIX}/usr/lib/libz.so.1
ln -sf ../lib/libz.so.1 ${MELVIX}/lib64/libz.so.1
# Cleanup
echo -en "\r Cleaning up and backing up current state"
cp -rf ${MELVIX}/ ${MELVIX}-copy
rm -rf ${MELVIX}-copy/cross-tools
rm -rf ${MELVIX}-copy/usr/src/*
rm -rf ${MELVIX}-copy/sources
FILES="$(ls ${MELVIX}-copy/usr/lib64/*.a)"
for file in ${FILES};
do rm -f ${file}
done
|