GLBasic forum

Main forum => GLBasic - en => Topic started by: r0ber7 on 2012-Aug-03

Title: Compile on Linux with this shellscript
Post by: r0ber7 on 2012-Aug-03
Hi!

For a long time now, I've wanted to be able to compile my GLBasic projects on Linux. Every time I wanted to work on my game, I'd have to switch to Windows, and I don't like Windows. :P

So, after some messing around, I created this shell script which compiles GLBasic projects on Linux.
For this to work, you'll need:

- the GLBasic compiler directory (usually found somewhere in C:\Program Files\GLBasic\Compiler)
- glblicence.inc (in c:\Users\username\AppData\Local\Temp\glbasic\, or somewhere else depending on your Windows version. Just run a search.)
- g++ installed on Linux
- my shellscript
- coffee

Copy the compiler directory and glblicence.inc to Linux, and you're good to go. Then, edit the shellscript according to your whishes, and run it in your project directory. For this to work, glblicence.inc has to be in the same directory as the project files.

Code (glbasic) Select


# this shellscript will compile glbasic projects on linux, for linux.
# 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

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

# edit to suit your project. .gbas files to pre-compile. start with main file, then add the rest.
GBAS_FILES="main.gbas file2.gbas file3.gbas"

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

# the actual compilation. you shouldn't have to change anything here.
echo "--> Pre-compiling .gbas files..."

$GLB_PATH/gpc-linux $GBAS_FILES

echo "--> Compiling .cpp files..."

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."



If you have many seperate files, as I do, you could consider setting up a Makefile (http://mrbook.org/tutorials/make/) so you don't have to compile everything when you've just made changes to one file.
I hope this will be useful to someone.

Ciao!  8)

[attachment deleted by admin]
Title: Re: Compile on Linux with this shellscript
Post by: MrTAToad on 2012-Aug-03
That'll be handy!
Title: Re: Compile on Linux with this shellscript
Post by: bigsofty on 2012-Aug-03
A nice insight to how to go about this! :good:
Title: Re: Compile on Linux with this shellscript
Post by: erico on 2012-Aug-03
Great!, just as long as your coffee is coffea arabica  :S
Title: Re: Compile on Linux with this shellscript
Post by: Hark0 on 2012-Aug-03
Bravo!

Hmmm... for MacOS... the method are the same?

:P
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2012-Aug-03
Ok, I updated the shellscript to take commandline arguments as to which files to compile. This way, only the ones entered as arguments get compiled, and for the rest the old object files are used for linking. Unless you enter no arguments, in which case all .gbas files from the variable get compiled.

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 Incredibuild, 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. .gbas files to pre-compile. start with main file, then add the rest.
GBAS_FILES="main.gbas file2.gbas file3.gbas"

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

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

CFLAGS="-c -Wall -static-libgcc -pipe -O3 -w  -I"$GLB_PATH/Include/""
LDFLAGS="-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"

$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 $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."


I'm leaving the old one up there in case this one doesn't work for anyone.

Quote from: Hark0 on 2012-Aug-03
Bravo!

Hmmm... for MacOS... the method are the same?

:P

I'd think so, I hear Max OS X is based on UNIX. But I'm no Mac guy, so I have no idea really.

[attachment deleted by admin]
Title: Re: Compile on Linux with this shellscript
Post by: Hark0 on 2012-Aug-03
Quote from: Hark0 on 2012-Aug-03
Bravo!

Hmmm... for MacOS... the method are the same?

:P

I'd think so, I hear Max OS X is based on UNIX. But I'm no Mac guy, so I have no idea really.
[/quote]

Well... don't worry.... If I have time I try on my Mac...  :D

It's time to BUILD directly on MacOS!!!

;)
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2012-Aug-04
Quote from: Hark0 on 2012-Aug-03
Quote from: Hark0 on 2012-Aug-03
Bravo!

Hmmm... for MacOS... the method are the same?

:P

I'd think so, I hear Max OS X is based on UNIX. But I'm no Mac guy, so I have no idea really.

Well... don't worry.... If I have time I try on my Mac...  :D

It's time to BUILD directly on MacOS!!!

;)
[/quote]

Try gpc-macosx and g++, with the compile & link options for Mac from [glbasic]/Compiler/platform/platform.ini, all the libraries and headers, and glblicence.inc. It should work.

Quote from: erico on 2012-Aug-03
Great!, just as long as your coffee is coffea arabica  :S

It is! How did you know?  :o
Title: Re: Compile on Linux with this shellscript
Post by: Albert on 2012-Sep-05
I'm trying to compile on linux a console app
my compile.sh:
Code (glbasic) Select

gcc -pipe -O3 -w -Wl,--allow-shlib-undefined,-rpath-link,./Linux/Lib -L./Linux/Lib -I./Include -DLINUX -DUNIX -DNDEBUG -DGLB_CONSOLE *.cpp -lGLBasicLinux-console -ldl -lc -lpthread


Output is:
Code (glbasic) Select

> ./compile.sh
/usr/bin/ld: skipping incompatible ./Linux/Lib/libGLBasicLinux-console.a when searching for -lGLBasicLinux-console
/usr/bin/ld: cannot find -lGLBasicLinux-console
collect2: ld returned 1 exit status
>

Maybe the problem is that this is an 64 bit linux?
Title: Re: Compile on Linux with this shellscript
Post by: MrTAToad on 2012-Sep-05
Most likely unfortunately are full 64-bit libraries are needed
Title: Re: Compile on Linux with this shellscript
Post by: Albert on 2012-Sep-05
Gernot: I think our games cannot be run on x64 linux, what is a shame as more and more linux user buy 64 bit computers.
It seems to me that only the GLBasic####.so and .a files need to be recompile to x64 and we good to go. There will be 64bit support for Linux in GLBasic?
Title: Re: Compile on Linux with this shellscript
Post by: MrTAToad on 2012-Sep-05
The problem is that various 64-bit SDL files need to be linked to their 32-bit versions.  It seems that the 64-bit versions (or perhaps how Linux deals with the conversion) tends to make GLBasic programs somewhat unstable unfortunately...
Title: Re: Compile on Linux with this shellscript
Post by: Cybermonkey on 2012-Sep-05
Sorry, I am the new one, and I tend to disagree ... I did several SDL based programs on Linux with 64 bit using SDL, SDL_ttf, SDL_image, SDL_mixer and even SDL_gfx and never had any problems. Of course OpenGL render context works, too.
So, yes, I am the new one but I watched closely the progress of GLBasic over the years and of course it is impressive but a lot of Linux users wait for 64 bit support. (It's rather usual to have > 4GB memory nowadays). Anyway, I am looking forward to use GLBasic for some (Windows  ;)) game projects.
BTW, is that captcha always active if I want to post?
Title: Re: Compile on Linux with this shellscript
Post by: Moru on 2012-Sep-12
So that is why my GLBasic programs all crashed on my Linux computer. I always used 64 bit even though I had less memory than 4 GB.
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2012-Oct-20
Ok guys. Problem.

I try to compile a program which uses NETWEBGET$ with the above script. The preprocessor needs proof I paid for GLBasic, else it won't do any NETWEBGETTIN'. I have bought the Premium version. On Windows I compile this code with no problem. How then, if possible, do I tell this preprocessor this when compiling from Linux?  O_O
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2013-Feb-26
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
Title: Re: Compile on Linux with this shellscript
Post by: MrTAToad on 2013-Feb-26
Ah, very handy!
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2013-Sep-27
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
Title: Re: Compile on Linux with this shellscript
Post by: MrTAToad on 2013-Sep-27
Very handy - do you also set the execute attribute for the resulting file too ?
Title: Re: Compile on Linux with this shellscript
Post by: r0ber7 on 2013-Sep-27
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"