forked from kentosama/m68k-elf-gcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-toolchain.sh
executable file
·118 lines (104 loc) · 2.81 KB
/
build-toolchain.sh
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
#!/usr/bin/env bash
###################################################################
#Script Name : build-toolchain
#Description : build toolchain for the Motorola 68000
#Date : Monday, 14 November 2022
#Author : 5inf, Jacques Belosoukinski (kentosama)
###################################################################
BUILD_BINUTILS="yes"
BUILD_GCC_STAGE_1="yes"
BUILD_GCC_STAGE_2="no"
BUILD_NEWLIB="no"
BUILD_PICOLIBC="no"
CPU="m68000"
PREFIX="m68k-elf-"
# Check if user is root
if [ ${EUID} == 0 ]; then
echo "Please don't run this script as root!"
exit
fi
# Check all args
i=1
for arg do
if [[ "$arg" == "--with-newlib" ]]; then
BUILD_NEWLIB="yes"
BUILD_GCC_STAGE_2="yes"
export WITH_NEWLIB="--with-newlib"
elif [[ "$arg" == "--with-picolibc" ]]; then
BUILD_PICOLIBC="yes"
BUILD_GCC_STAGE_2="yes"
export WITH_PICOLIBC="--with-picolibc"
elif [[ "$arg" == "--with-cpu=" ]]; then
CPU = ${i}
elif [[ "$arg" == "--program-prefix=" ]]; then
PREFIX = ${i}
fi
i=$((i + 1))
done
# Export
if [ "$(uname)" = 'FreeBSD' ]; then
export MAKE="gmake"
export NUM_PROC=$(sysctl -n hw.ncpu)
else
export MAKE="make"
export NUM_PROC=$(nproc)
fi
export ARCH=$(uname -m)
export TARGET="m68k-elf"
export BUILD_MACH="${ARCH}-pc-linux-gnu"
export HOST_MACH="${ARCH}-pc-linux-gnu"
export PROGRAM_PREFIX=${PREFIX}
export INSTALL_DIR="${PWD}/m68k-toolchain"
export DOWNLOAD_DIR="${PWD}/download"
export ROOT_DIR="${PWD}"
export BUILD_DIR="${ROOT_DIR}/build"
export SRC_DIR="${ROOT_DIR}/source"
export WITH_CPU=${CPU}
# Create main folders in the root dir
mkdir -p ${INSTALL_DIR}
mkdir -p ${BUILD_DIR}
mkdir -p ${SRC_DIR}
mkdir -p ${DOWNLOAD_DIR}
export PATH=$INSTALL_DIR/bin:$PATH
# Build binutils
if [ ${BUILD_BINUTILS} == "yes" ]; then
./build-binutils.sh
if [ $? -ne 0 ]; then
"Failed to build binutils, please check build.log"
exit 1
fi
fi
# Build GCC stage 1
if [ ${BUILD_GCC_STAGE_1} == "yes" ]; then
./build-gcc.sh
if [ $? -ne 0 ]; then
"Failed to build gcc stage 1, please check build.log"
exit
fi
fi
# Build newlib
if [ ${BUILD_NEWLIB} == "yes" ] || [ ${BUILD_PICOLIBC} == "yes" ]; then
if [ ${BUILD_NEWLIB} == "yes" ]; then
./build-newlib.sh
if [ $? -ne 0 ]; then
"Failed to build newlib, please check build.log"
exit
fi
fi
if [ ${BUILD_PICOLIBC} == "yes" ]; then
./build-picolib.sh
if [ $? -ne 0 ]; then
"Failed to build newlib, please check build.log"
exit
fi
fi
# Build GCC stage 2 (with newlib)
if [ ${BUILD_GCC_STAGE_2} == "yes" ]; then
./build-gcc.sh
if [ $? -ne 0 ]; then
"Failed to build gcc stage 2, please check build.log"
exit
fi
fi
fi
echo "${TARGET} toolchain build has finished"