Compile on Linux with this shellscript

Previous topic - Next topic

r0ber7

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 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]

MrTAToad


bigsofty

A nice insight to how to go about this! :good:
Cheers,

Ian.

"It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration."
(E. W. Dijkstra)

erico

Great!, just as long as your coffee is coffea arabica  :S

Hark0

Bravo!

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

:P
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

r0ber7

#5
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]

Hark0

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!!!

;)
http://litiopixel.blogspot.com
litiopixel.blogspot.com - Desarrollo videojuegos Indie · Pixel-Art · Retroinformática · Electrónica Development Indie Videogames · Pixel-Art · Retrocomputing · Electronic

r0ber7

#7
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

Albert

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?

MrTAToad

Most likely unfortunately are full 64-bit libraries are needed

Albert

#10
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?

MrTAToad

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

Cybermonkey

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?
Best regards.

Cybermonkey

Moru

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.

r0ber7

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