Compile on Linux with this shellscript

Previous topic - Next topic

r0ber7

#15
While I still have no answer to the above question, I did update the script today. It didn't work well with my new 64bit machine, so I added 32bit compilation flags to the ld & g++ commands. In addition, it now automatically checks if there is a glblicence.inc present. If it's not, it tries to copy glblicence.inc from the GLB_PATH (where gpc-linux lives).
It also reads the .gbas files used for compilation from a textfile now, which should be called project_files.txt and be put into the project's directory. I added these things cause I didn't want to spend time making a new shellscript for every project. So anyway, here it is.

Code (glbasic) Select

# glbc.sh [FILE1.gbas] [FILE2.gbas] etc.
#
# this shellscript will compile glbasic projects on linux, for linux.
# it will take seperate .gbas files as command line arguments, in case only those have to be linked again.
# similar to Inredibuild, but you have to enter the filenames of the files you changed into the commandline
# if no commandline arguments are given, all the standard .gbas files will be compiled.
# note: the file called "glblicence.inc" should be in the directory from where the script is executed.
# the gbas files should also be in there.
# this will only compile standard linux executables. for console applications or xbox linux stuff, change the g++ commandline options
# according to platform.ini (found in Compiler/platform folder)
# hope this is of some help to someone.
# cheers!
#
# - r0ber7

#!/bin/bash

# edit to suit your project. path to glbasic compiler
GLB_PATH="/home/robert/code/glbasic/Compiler/platform"

# edit to suit your project. executable name
EXECUTABLE="a.out"

##########################################################

# Below this line nothing should need editing.

##########################################################


# -m32 is for 32bit compilation
CFLAGS="-m32 -c -Wall -static-libgcc -pipe -O3 -w 
-I"$GLB_PATH/Include/""
LDFLAGS="-m32
-Wl,--allow-shlib-undefined,-rpath-link,"$GLB_PATH/Linux/Lib/"
-DLINUX -DUNIX -DNDEBUG -DWANT_SDL -DHAVE_OPENGL -L"$GLB_PATH/Linux/Lib/" -lGLBasicLinux -lpng-gf -lGL -lSDL_mixer -lSDL"

POST_CMD="mv $EXECUTABLE *.app"
POST_CMD2="*.app/$EXECUTABLE"



# check if a glblicence can be found in the current directory. if not, copy it from the GLB Path.
echo "Checking if glblicence.inc exists."
FILE="glblicence.inc"
if [ -f $FILE ]
then
echo "Yep."
else
echo "No."
echo "Getting it."
if [ -f $GLB_PATH/glblicence.inc ]
then
cp -rv $GLB_PATH/glblicence.inc ./
else
echo "No glblicence.inc found. Please copy one into $GLB_PATH".
exit
fi
fi

echo "Checking if there is a project_files.txt here."
FILE="project_files.txt"
if [ -f $FILE ]
then
echo "Project files found, getting data."
echo "Data found: "


GBAS_FILES=`cat project_files.txt`

#echo -e "\nTotal $count lines read"
echo $GBAS_FILES


else
echo "No project_files.txt found."
exit
fi

# the actual compilation. you shouldn't have to change anything here.

$GLB_PATH/gpc-linux $GBAS_FILES



if [ -z $1 ]
then
echo "--> Compiling all .cpp files..."
g++ $CFLAGS ./*.cpp
else
for i in $@
do

# check all cpp files for a match to this gbas name
returnstr=$(grep -l "GBAS: $i" *.cpp)
if [ -z $returnstr ]
then
echo "--> No .cpp file found containing $i."
else
echo "--> Compiling $i ($returnstr)..."
g++ $CFLAGS $returnstr
fi
done
fi

echo "--> Linking .o files..."

g++ $LDFLAGS ./*.o -o $EXECUTABLE

#g++ -static-libgcc -pipe -O3 -w -Wl,--allow-shlib-undefined,-rpath-link,"$GLB_PATH/Linux/Lib" -L"$GLB_PATH/Linux/Lib/" -I"$GLB_PATH/Include/" -DLINUX -DUNIX -DNDEBUG -DWANT_SDL -DHAVE_OPENGL ./*.cpp  -lGLBasicLinux -lpng-gf -lGL -lSDL_mixer -lSDL -o $EXECUTABLE


echo "--> Done!"
echo "$EXECUTABLE should now be in this folder."

$POST_CMD
echo "Run?"
read
$POST_CMD2

MrTAToad


r0ber7

Here's the script for 64 bit Ubuntu.

Code (glbasic) Select

#!/bin/bash
# glbc.sh [FILE1.gbas] [FILE2.gbas] etc.
#
# this shellscript will compile glbasic projects on linux, for linux.
# it will take seperate .gbas files as command line arguments, in case only those have to be linked again.
# similar to Inredibuild, but you have to enter the filenames of the files you changed into the commandline
# if no commandline arguments are given, all the standard .gbas files will be compiled.
# note: the file called "glblicence.inc" should be in the directory from where the script is executed.
# the gbas files should also be in there.
# according to platform.ini (found in Compiler/platform folder)
# hope this is of some help to someone.
# cheers!
#
# - r0ber7

#!/bin/bash




# edit to suit your project. path to glbasic compiler
GLB_PATH="/home/robert/code/glbasic/Compiler/platform"

# edit to suit your project. executable name
EXECUTABLE="run"

if [ -z "$1" ]

then
echo "No app path given."
echo "Use: glbc.sh <path> [file.gbas]"
exit
else
echo "Appdir set to $1"
APPDIR="$1"
fi

POST_CMD="mv $EXECUTABLE $APPDIR" #"$EXECUTABLE in this directory (may need moving
POST_CMD2="$APPDIR/$EXECUTABLE"




##########################################################

# Below this line nothing should need editing.

##########################################################


# -m32 is for 32bit compilation
CFLAGS="-m32 -c -Wall -static-libgcc -pipe -O3 -w 
-I"$GLB_PATH/Include/""
LDFLAGS="-m32
-Wl,--allow-shlib-undefined,-rpath-link,"$GLB_PATH/Linux/Lib/"
-DLINUX -DUNIX -DNDEBUG -DWANT_SDL -DHAVE_OPENGL -L/usr/lib32 -L"$GLB_PATH/Linux/Lib/" -lGLBasicLinux -lpng-gf -lGL -lSDL_mixer -lSDL -ldl -lpthread -lgcc"

#g++ -static-libgcc -pipe -O3 -w -Wl,--allow-shlib-undefined,-rpath-link,"$GLB_PATH/Linux/Lib" -L"$GLB_PATH/Linux/Lib/" -I"$GLB_PATH/Include/" -DLINUX -DUNIX -DNDEBUG -DWANT_SDL -DHAVE_OPENGL ./*.cpp  -lGLBasicLinux -lpng-gf -lGL -lSDL_mixer -lSDL -o $EXECUTABLE



# check if a glblicence can be found in the current directory. if not, copy it from the GLB Path.
echo "Checking if glblicence.inc exists."
FILE="glblicence.inc"
if [ -f $FILE ]
then
echo "Yep."
else
echo "No."
echo "Getting it."
if [ -f $GLB_PATH/glblicence.inc ]
then
cp -rv $GLB_PATH/glblicence.inc ./
else
echo "No glblicence.inc found. Please copy one into $GLB_PATH".
exit
fi
fi

echo "Checking if there is a project_files.txt here."
FILE="project_files.txt"
if [ -f $FILE ]
then
echo "Project files found, getting data."
echo "Data found: "


GBAS_FILESTR=`cat project_files.txt`
#GBAS_FILES= `echo "${GBAS_FILESTR//\n\0\EO}"`

#echo -e "\nTotal $count lines read"
#echo $GBAS_FILES

# adjust directories (everything gets the current directory added to it)
#string='cat,name,item,class,supplier,supplier2'
#IFS=' '
#array=( $GBAS_FILESTR )
#echo '--> Doing array trick to add current dir to .gbas filenames.'

#for (( i = 0 ; i < ${#array[@]} ; i++ )) do
#echo ${array[$i]}

#echo "--> Adding value to array: $array[$i]"
#file_array[$i]=${array[$i]}
#echo ${file_array[$i]}
#GBAS_FILES="$GBAS_FILES ${file_array[$i]} "
#done

#echo "--> Removed last entry:"
#echo $GBAS_FILES
#echo $GBAS_FILESTR | cut -c3-5
#exit

else
echo "No project_files.txt found."
exit
fi

# the actual compilation. you shouldn't have to change anything here.

$GLB_PATH/gpc-linux -P"$PWD" $GBAS_FILESTR



if [ -z $2 ]
then
echo "--> Compiling all .cpp files..."
g++ $CFLAGS ./*.cpp
else
for i in $@
do

if [ "$i" == "$1" ]
then
echo "--> Skipping path name as argument"
else
# check all cpp files for a match to this gbas name
returnstr=$(grep -l "GBAS: $i" *.cpp)
if [ -z $returnstr ]
then
echo "--> No .cpp file found containing $i."
else
echo "--> Compiling $i ($returnstr)..."
g++ $CFLAGS $returnstr
fi
fi
done
fi

echo "--> Linking .o files..."

g++ $LDFLAGS ./*.o -o $EXECUTABLE

#g++ -static-libgcc -pipe -O3 -w -Wl,--allow-shlib-undefined,-rpath-link,"$GLB_PATH/Linux/Lib" -L"$GLB_PATH/Linux/Lib/" -I"$GLB_PATH/Include/" -DLINUX -DUNIX -DNDEBUG -DWANT_SDL -DHAVE_OPENGL ./*.cpp  -lGLBasicLinux -lpng-gf -lGL -lSDL_mixer -lSDL -o $EXECUTABLE


echo "--> Done!"
echo "$EXECUTABLE should now be in $APPDIR."


$POST_CMD
echo "Run?"
read
$POST_CMD2

#echo "--> Cleaning up."
#rm ./*.o
#rm ./*.cpp

MrTAToad

Very handy - do you also set the execute attribute for the resulting file too ?

r0ber7

Quote from: MrTAToad on 2013-Sep-27
Very handy - do you also set the execute attribute for the resulting file too ?

Code (glbasic) Select
POST_CMD2="sudo chmod a+rwx $APPDIR/$EXECUTABLE;$APPDIR/$EXECUTABLE"