-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.sh
executable file
·128 lines (109 loc) · 2.63 KB
/
build.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
118
119
120
121
122
123
124
125
126
127
128
#!/bin/bash
#This script builds YourOS a free opensource operating system.
CORES=`nproc`
CURRENT_DIR=`pwd`
CROSSTOOLS_DIR=${CURRENT_DIR}/crosstools
TOOLCHAIN_DIR=${CROSSTOOLS_DIR}/env
BOOTLOADER_SRC=${CURRENT_DIR}/src/Bootloader
KERNEL_SRC=${CURRENT_DIR}/src/Kernel
PROG_SRC=${CURRENT_DIR}/src/Programs
ERROR_OPT=false
REBUILD=false
DISASSEMBLE=false
BUILD_CONFIG=
BUILD_DOCKER=false
BUILD_IMAGE=false
function die()
{
echo -e "$1"
exit -1
}
function help()
{
echo "Usage: build.sh [options]"
echo "Options:"
echo " -d Build Docker container"
echo " -h Display this information"
echo " -f Rebuild all (but not the toolchain)"
echo " -s Disassemble all binaries (useful for debugging)"
echo " -r Make a release build (enable otpimizations)"
echo " -v Additionally build a hard drive image"
}
#Start
echo "YourOS builder V0.1"
while getopts ":dhfrsv" option; do
case "${option}" in
d)
BUILD_DOCKER=true
;;
h)
help
exit 0
;;
f)
REBUILD=true
;;
s)
DISASSEMBLE=true
;;
r)
BUILD_CONFIG=release
;;
v)
BUILD_IMAGE=true
;;
\?)
echo "Invalid option -${OPTARG}" >&2
ERROR_OPT=true
;;
:)
echo -e "Option -${OPTARG} requires an argument" >&2
ERROR_OPT=true
;;
esac
done
if [ ${ERROR_OPT} = true ]; then
help
exit 1
fi
if [ ${BUILD_DOCKER} = true ]; then
echo "Building Docker container..."
INCLUDE_DIR=${CROSSTOOLS_DIR}/include
mkdir -p ${INCLUDE_DIR} \
&& make -C ${KERNEL_SRC} SYSROOT_DIR=${CROSSTOOLS_DIR} install-headers \
&& docker build --pull -t ghcr.io/gurgel100/youros-dev:latest ${CROSSTOOLS_DIR}
rm -r ${INCLUDE_DIR}
else
echo "Checking for dependencies..."
(which make > /dev/null 2>&1) || die "Make is required"
(which grub-mkrescue > /dev/null 2>&1) || die "grub-mkrescue is required"
echo "Checking crosstools..."
export PATH=${PATH}:${TOOLCHAIN_DIR}/bin
if ! [[ \
-x "$(command -v x86_64-elf-gcc)" \
&& -x "$(command -v x86_64-elf-ld)" \
&& -x "$(command -v x86_64-pc-youros-gcc)" \
&& -x "$(command -v x86_64-pc-youros-ld)" \
]];
then
cd ${CROSSTOOLS_DIR}
./build_crosstools.sh -k ${KERNEL_SRC} -d -c || die "Could not build crosstools"
fi
if [ ${REBUILD} = true ]; then
make clean
fi
if [ ${BUILD_IMAGE} = true ]; then
MAKE_TARGET=all
else
MAKE_TARGET=YourOS.iso
fi
make BUILD_CONFIG=${BUILD_CONFIG} -j ${CORES} ${MAKE_TARGET}
if [ ${DISASSEMBLE} = true ]; then
echo "Disassembling..."
BOOTLOADER_BIN=${BOOTLOADER_SRC}/build/bootloader
KERNEL_BIN=${KERNEL_SRC}/build/kernel
x86_64-elf-objdump -D -S ${BOOTLOADER_BIN} > ${CURRENT_DIR}/disassembly_boot.S
x86_64-elf-objdump -D -S ${KERNEL_BIN} > ${CURRENT_DIR}/disassembly_kernel.S
fi
fi
echo "Completed"