Suggestions for Shell Scripts for Building Large FiveLinux A
Posted: Tue May 20, 2008 10:32 pm
Hi All
My biggest FiveLinux application currently has 11 xHarbour source files. I built a shell script (based on buildx.sh) to build the application. One problem I encountered was that the script didn't stop if it encountered an error so you weren't immediately aware of the problem. And the error messages would be shifted off the screen by the batch file continuing. Mind you I had inadvertantly exaccerbated the problem by not automatically deleting the previously generated .c and .o files which meant that executable code might still be generated - but just not from the source intended.
I set out to improve upon the script.
The first step was to notify immediately an error occurred and stop execution at that point. Rather than have to put the same code in for every compile (both harbour and gcc) I found a neat shell script function:
so after each compile you only have to add something like:
But why not take this kind of approach further. By that I mean that each harbour source compilation requires the same basic code along the following lines:
So why not wrap that up into a function? Which is what I did as follows:
That means that to compile my mSYS xHarbour source file all I need in my script is:
Simple! So why not do the same thing for compiling the generated C code to object code - not to forget then deleting the C code. So I wrote the following function:
That means that I can replace:
with:
Much simpler. There are added bonuses too. Like if I want to switch compilers or the layout of my programming tools on my hard disk I only have to edit in one place (the functions above). Also the script is now highly readable. Much more xBase like!
So currently my build file looks like this:
Whereto from here? Well maybe we can somehow create a list of modules and use that list throughout. But I'll have to do some more research on shell script capabilities to see if I can find a way to do that. In the meantime I'm pretty happy with the script as it stands. I certainly think it suits me a lot better than my old one.
Happy programming
xProgrammer
My biggest FiveLinux application currently has 11 xHarbour source files. I built a shell script (based on buildx.sh) to build the application. One problem I encountered was that the script didn't stop if it encountered an error so you weren't immediately aware of the problem. And the error messages would be shifted off the screen by the batch file continuing. Mind you I had inadvertantly exaccerbated the problem by not automatically deleting the previously generated .c and .o files which meant that executable code might still be generated - but just not from the source intended.
I set out to improve upon the script.
The first step was to notify immediately an error occurred and stop execution at that point. Rather than have to put the same code in for every compile (both harbour and gcc) I found a neat shell script function:
Code: Select all
check_errs()
{
# Function. Parameter 1 is the return code
# Para. 2 is text to display on failure.
if [ "${1}" -ne "0" ]; then
echo "ERROR # ${1} : ${2}"
# as a bonus, make our script exit with the right error code.
exit ${1}
fi
}
Code: Select all
check_errs $? "compiling mSYS.c to object code"
Code: Select all
echo compiling mSYS C module...
gcc mSYS.c -c -I./../include -I./../../xharbour/include `pkg-config --cflags gtk+-2.0`
check_errs $? "compiling mSYS.c to object code"
Code: Select all
compile_prg()
{
# Function. Parameter 1 is the module name
echo compiling $1.prg xHarbour code to C code
./../../xharbour/bin/harbour $1.prg -n -I./../include -I./../../xharbour/include
check_errs $? "compiling ${1}.prg"
}
Code: Select all
compile_prg mSYS
Code: Select all
compile_c()
{
# Function. Parameter 1 is the module name
echo compiling $1.c to object code
gcc $1.c -c -I./../include -I./../../xharbour/include `pkg-config --cflags gtk+-2.0`
check_errs $? "compiling ${1}.c"
rm $1.c
}
Code: Select all
echo compiling mSYS C module...
gcc mSYS.c -c -I./../include -I./../../xharbour/include `pkg-config --cflags gtk+-2.0`
check_errs $? "compiling mSYS.c to object code"
rm mSYS.c
Code: Select all
compile_c mSYS
So currently my build file looks like this:
Code: Select all
# ./mb.sh
check_errs()
{
# Function. Parameter 1 is the return code
# Para. 2 is text to display on failure.
if [ "${1}" -ne "0" ]; then
echo "ERROR # ${1} : ${2}"
# as a bonus, make our script exit with the right error code.
exit ${1}
fi
}
compile_prg()
{
# Function. Parameter 1 is the module name
echo compiling $1.prg xHarbour code to C code
./../../xharbour/bin/harbour $1.prg -n -I./../include -I./../../xharbour/include
check_errs $? "compiling ${1}.prg"
}
compile_c()
{
# Function. Parameter 1 is the module name
echo compiling $1.c to object code
gcc $1.c -c -I./../include -I./../../xharbour/include `pkg-config --cflags gtk+-2.0`
check_errs $? "compiling ${1}.c"
rm $1.c
}
echo
echo Building mSYS Medical Software
echo ------------------------------
echo
echo compiling xHarbour source files
compile_prg mSYS
compile_prg mTEMLIST
compile_prg xOBJECTS
compile_prg PATIENT_Class
compile_prg PATFILE_Class
compile_prg EXTEND5
compile_prg DOCTOR_Classes
compile_prg OSTEO_Class
compile_prg SINGLE_Class
compile_prg xPATIENT_Class
compile_prg RECORD_Class
echo compiling generated C files
compile_c mSYS
compile_c mTEMLIST
compile_c xOBJECTS
compile_c PATIENT_Class
compile_c PATFILE_Class
compile_c EXTEND5
compile_c DOCTOR_Classes
compile_c OSTEO_Class
compile_c SINGLE_Class
compile_c xPATIENT_Class
compile_c RECORD_Class
echo linking...
gcc mSYS.o mTEMLIST.o xOBJECTS.o PATIENT_Class.o PATFILE_Class.o EXTEND5.o DOCTOR_Classes.o OSTEO_Class.o SINGLE_Class.o RECORD_Class.o -omSYS -L./../lib -L./../../xharbour/lib `pkg-config --libs gtk+-2.0` `pkg-config --libs libglade-2.0` `pkg-config --libs libgnomeprintui-2.2` -Wl,--start-group -lfivex -lfivec -lcommon -lvm -lrtl -lrdd -lmacro -llang -lcodepage -lpp -ldbfntx -ldbfcdx -ldbffpt -lhbsix -lhsx -lpcrepos -lusrrdd -ltip -lct -lcgi -lgtnul -lgtstd -lgtcgi -lgtcrs -lhbodbc -ldebug -lm -lgpm -lncurses -Wl,--end-group
echo removing .o files
rm mSYS.o
rm mTEMLIST.o
rm xOBJECTS.o
rm PATIENT_Class.o
rm PATFILE_Class.o
rm EXTEND5.o
rm DOCTOR_Classes.o
rm SINGLE_Class.o
rm xPATIENT_Class.o
rm RECORD_Class.o
echo done!
Happy programming
xProgrammer