patternbashMinor
Build script for an operating system written in C++
Viewed 0 times
scriptwrittensystemoperatingforbuild
Problem
I recently started following the James M Kernel Dev tutorials and was able to create an operating system in C++.
Here is the source on GitHub.
I have a couple of questions:
JOSMake.sh
```
#
# Build File for JOS
#
# To Build
# bash build.sh
# To Run
# bash run.sh
# ----------------------------------------------------------------------------------------------
# JOS uses assembly to build the bootsector
# Compile the boot Sectors in boot
echo "==============================================="
echo "-------- Building Boot Sectors ----------------"
cd boot
# Run the Make Script inside the boot directory
bash buildboot.sh
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# Compile the C++ Sources into Respective Objects
# Compile main.cc
echo "==============================================="
echo "--------- Compiling C++ Sources --------------"
g++ -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 -o main.o main.cc
mv main.o build
# Run scons to build the Entire Lbrary of C++ Files
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
## When Everything is Finished Link together the Objects into a Kernel File
echo "==============================================="
echo "--------- Linking ----------------"
cd build
# require ld , link.ld
ld -T '../link.ld' -m elf_i386 -o kernel.jos *.o
# Clean Up After Build
#rm *.o
echo "============================================
Here is the source on GitHub.
I have a couple of questions:
- Is my coding style ok?
- Is it wrong to write bash scripts for building the project?
JOSMake.sh
```
#
# Build File for JOS
#
# To Build
# bash build.sh
# To Run
# bash run.sh
# ----------------------------------------------------------------------------------------------
# JOS uses assembly to build the bootsector
# Compile the boot Sectors in boot
echo "==============================================="
echo "-------- Building Boot Sectors ----------------"
cd boot
# Run the Make Script inside the boot directory
bash buildboot.sh
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
# Compile the C++ Sources into Respective Objects
# Compile main.cc
echo "==============================================="
echo "--------- Compiling C++ Sources --------------"
g++ -c -nostdlib -nostdinc -fno-builtin -fno-stack-protector -ffreestanding -m32 -o main.o main.cc
mv main.o build
# Run scons to build the Entire Lbrary of C++ Files
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..
echo "==============================================="
# ----------------------------------------------------------------------------------------------
# ----------------------------------------------------------------------------------------------
## When Everything is Finished Link together the Objects into a Kernel File
echo "==============================================="
echo "--------- Linking ----------------"
cd build
# require ld , link.ld
ld -T '../link.ld' -m elf_i386 -o kernel.jos *.o
# Clean Up After Build
#rm *.o
echo "============================================
Solution
Instead of repeated statements like this:
I suggest adding a helper function, for example:
The advantage of this is if you later decide to change the length of the
Instead of entering into sub-directories with
Do like this:
Notice that there is no more
Working directory changes in a
This maybe a matter of taste, but I find that the many comment lines like this are just noise, and make the script hard to read, I suggest to remove them:
echo "==============================================="I suggest adding a helper function, for example:
print_hr() { # hr - as in horizontal rule
echo "==============================================="
}The advantage of this is if you later decide to change the length of the
= in the line, you can change it in one place.Instead of entering into sub-directories with
cd dirname and later stepping back with cd .., I recommend to use sub-shell environments with (...). For example, instead of this:cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..Do like this:
(
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
)Notice that there is no more
cd ...Working directory changes in a
(...) sub-shell environment are only in effect within.This maybe a matter of taste, but I find that the many comment lines like this are just noise, and make the script hard to read, I suggest to remove them:
# ----------------------------------------------------------------------------------------------Code Snippets
echo "==============================================="print_hr() { # hr - as in horizontal rule
echo "==============================================="
}cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
cd ..(
cd include
rm *.o
scons
# Move all Object Files into Build Directory
cp *.o ../build
)# ----------------------------------------------------------------------------------------------Context
StackExchange Code Review Q#112606, answer score: 3
Revisions (0)
No revisions yet.