Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Optimized bash script compilation of QB64 for Linux
#1
This script was located in this post : why the qb64 editor is slow under linux

to simplify the updates, I created this dedicated post.


after reading some information about gcc, i decided to use the -O3 compiler option. it's a good compromise between security and speed.

if this is your first installation of qb64, it is advised to run the script setup_lnx.sh to install the package dependencies necessary for qb64...

this script allows to insert the -O3 compiler option of gcc g++ to optimize qb64. the original files are saved. i removed some useless sections of the original script setup_lnx.sh. download the source code of qb64, unzip, put the script in the directory where is setup_lnx.sh, make it executable and run it. the processing is automatic. if the compilation was successful, the qb64 executable will be created:

compile_qb64.sh
Code: (Select All)
#!/bin/bash
# QB64 Installer
# Argument 1: If not blank, qb64 will not be started after compilation

dont_run="$1"

#This checks the currently installed packages for the one's QB64 needs
#And runs the package manager to install them if that is the case
# *** SECTION ENLEVE ***


#Make sure we're not running as root
if [ $EUID == "0" ]; then
  echo "You are trying to run this script as root. This is highly unrecommended."
  echo "This script will prompt you for your sudo password if needed to install packages."
  exit 1
fi

GET_WGET=
#Path to Icon
#Relative Path to icon -- Don't include beginning or trailing '/'
QB64_ICON_PATH="internal/source"

#Name of the Icon picture
QB64_ICON_NAME="qb64icon32.png"

DISTRO=

lsb_command=`which lsb_release 2> /dev/null`
if [ -z "$lsb_command" ]; then
  lsb_command=`which lsb_release 2> /dev/null`
fi

#Outputs from lsb_command:

#Arch Linux  = arch
#Debian      = debian
#Fedora      = Fedora
#KUbuntu     = ubuntu
#LUbuntu     = ubuntu
#Linux Mint  = linuxmint
#Ubuntu      = ubuntu
#Slackware   = slackware
#VoidLinux   = voidlinux
#XUbuntu     = ubuntu
#Zorin       = Zorin
if [ -n "$lsb_command" ]; then
  DISTRO=`$lsb_command -si | tr '[:upper:]' '[:lower:]'`
elif [ -e /etc/arch-release ]; then
  DISTRO=arch
elif [ -e /etc/debian_version ] || [ -e /etc/debian_release ]; then
  DISTRO=debian
elif [ -e /etc/fedora-release ]; then
  DISTRO=fedora
elif [ -e /etc/redhat-release ]; then
  DISTRO=redhat
elif [ -e /etc/centos-release ]; then
  DISTRO=centos
fi

#Find and install packages
# *** SECTION ENLEVE ***

echo "Compiling and installing QB64..."

### Build process
find . -name "*.sh" -exec chmod +x {} \;
find internal/c/parts -type f -iname "*.a" -exec rm -f {} \;
find internal/c/parts -type f -iname "*.o" -exec rm -f {} \;
find internal/c/libqb -type f -iname "*.o" -exec rm -f {} \;
rm ./internal/temp/*

echo "Modification 'makeline*'"
cp ./internal/c/makeline_lnx.txt ./internal/c/makeline_lnx_ORG.txt
find ./internal/c -type f -name "makeline_lnx.txt" -print0 | xargs -0 sed -i 's/g++ -no-pie -w qbx.cpp/g++ -O3 -no-pie -w qbx.cpp/g'
cp ./internal/c/makeline_lnx_nogui.txt ./internal/c/makeline_lnx_nogui_ORG.txt
find ./internal/c -type f -name "makeline_lnx_nogui.txt" -print0 | xargs -0 sed -i 's/g++ -no-pie -w qbx.cpp/g++ -O3 -no-pie -w qbx.cpp/g'

echo "Building library 'LibQB'"
pushd internal/c/libqb/os/lnx >/dev/null
rm -f libqb_setup.o
cp setup_build.sh setup_build_ORG.sh
cp build_test.sh build_test_ORG.sh
find . -type f -name "*.sh" -print0 | xargs -0 sed -i 's/g++ -c -w -Wall/g++ -O3 -c -w -Wall/g'
./setup_build.sh
popd >/dev/null

echo "Building library 'FreeType'"
pushd internal/c/parts/video/font/ttf/os/lnx >/dev/null
rm -f src.o
cp setup_build.sh setup_build_ORG.sh
cp build.sh build.sh_ORG.sh
find . -type f -name "*.sh" -print0 | xargs -0 sed -i 's/g++ -s -c -w -Wall/g++ -s -O3 -c -w -Wall/g'
./setup_build.sh
popd >/dev/null

echo "Building library 'Core:FreeGLUT'"
pushd internal/c/parts/core/os/lnx >/dev/null
rm -f src.a
cp setup_build.sh setup_build_ORG.sh
cp build.sh build.sh_ORG.sh
find . -type f -name "*.sh" -print0 | xargs -0 sed -i 's/gcc -s -O2 -c/gcc -s -O3 -c/g'
./setup_build.sh
popd >/dev/null

echo "Building 'QB64'"
tar -czvf ./internal/source/main.tar.gz ./internal/source/main.txt
find ./internal/source -type f -name "main.txt" -print0 | xargs -0 sed -i 's/g++ -c -s -w -Wall libqb.cpp -D FREEGLUT_STATIC/g++ -O3 -c -s -w -Wall libqb.cpp -D FREEGLUT_STATIC/g'
cp -r ./internal/source/* ./internal/temp/
pushd internal/c >/dev/null
g++ -O3 -no-pie -w qbx.cpp libqb/os/lnx/libqb_setup.o parts/video/font/ttf/os/lnx/src.o parts/core/os/lnx/src.a -lGL -lGLU -lX11 -lpthread -ldl -lrt -D FREEGLUT_STATIC -o ../../qb64
popd

if [ -e "./qb64" ]; then
  echo "DISTRO: $DISTRO"
  echo "Done compiling!!"
  echo
  echo "QB64 is located in this folder:"
  echo "`pwd`"
else
  ### QB64 didn't compile
  echo "It appears that the qb64 executable file was not created, this is usually an indication of a compile failure (You probably saw lots of error messages pop up on the screen)"
  echo "Usually these are due to missing packages needed for compilation. If you're not running a distro supported by this compiler, please note you will need to install the packages listed above."
  echo "If you need help, please feel free to post on the QB64 Forums detailing what happened and what distro you are using."
  echo "Also, please tell them the exact contents of this next line:"
  echo "DISTRO: $DISTRO"
fi
echo
echo "Thank you for using the QB64 installer."
Reply
#2
note that this script is not compatible with version 0.7.x of qb64. i don't have time to modify it for the moment. i will continue to use version 0.5.0...
Reply




Users browsing this thread: 1 Guest(s)