Skip to content
Shardik-PB edited this page Mar 9, 2021 · 7 revisions

Introduction

The following script allows you to compile a new PureBasic IDE on MacOS. You don't need to use Git or download anything manually. Simply start the script and it will download the IDE sourcecode from GitHub's master branch, compile a new IDE and start the new IDE.

System Requirements

The script was tested to work on MacOS Mavericks, El Capitan, High Sierra, Mojave, Catalina and Big Sur. However, currently I would advise to don't compile the PureBasic IDE on Mojave, Catalina or Big Sur because of a weird shift behaviour bug in the editor which always shifts the source code about 4 characters to the left whenever pressing the 'Enter' key. You may take a look into the bug report in the PureBasic forum: https://www.purebasic.fr/english/viewtopic.php?f=24&t=75178

Compilation of a new PureBasic IDE

  • Please copy the following script code into TextEdit and save it (for example as ~/CompilePureBasicIDE.bash)
  • The script needs to know the path to a working PureBasic installation on your Mac. You have 3 ways to do this:
    1. Change the Variable PBAppFolder to contain the path to your PureBasic folder containing the PureBasic app.
    2. When starting the script, specify the path to your PureBasic folder containing the PureBasic app behind the script name: ./CompilePureBasicIDE.bash /Path_to_your_PureBasic_folder
    3. You may start the script without any change: in this case you will be prompted for the path.
  • In specifiying your working PureBasic installation you also determine whether you will compile a 32 bit or 64 bit version of your new IDE. The compilation of a 32 bit version requires an Xcode version of 9 or lower because Apple removed the compilation of 32 bit programs in Xcode 10 or higher.
  • Start your Terminal.app
  • Change into your home folder: cd ~
  • Start the script: ./CompilePureBasicIDE.bash
  • If the error message "-bash: ./CompilePureBasicIDE.bash: /bin/bash: bad interpreter: Operation not permitted" should be displayed, you have to disable the automatically generated quarantine of your script file: xattr -d com.apple.quarantine CompilePureBasicIDE.bash
  • The newly compiled file PureBasic.app will be located in your home directory in the new folder PureBasic-IDE/PBv.nn-xyy where v.nn denotes the current IDE version and xyy denotes the x86 (32 bit) or x64 (64 bit) version of your IDE. Your old PureBasic.app will not be overwritten and remains intact.
  • After a successful compilation the newly compiled IDE will be started automatically.

Script to compile a new PureBasic IDE on MacOS

#!/bin/bash

echo ""
echo "--------------------------------------------"
echo "Compilation of a new PureBasic IDE for MacOS"
echo "--------------------------------------------"
echo ""

# ----- Set base folder to receive files of new PureBasic IDE (default: home folder)

BaseFolder=~

# ----- Set folder containing current PureBasic installation

PBAppFolder="/Your_path_to_your_PureBasic_installation"

# ----- Check if 1st script parameter contains PureBasic installation folder

if [ "$1" != "" ]; then
  PBAppFolder="$1"
fi

# ----- If no valid PureBasic installation folder is specified (either as the 1st
#       parameter of the script's start command or in the declaration above) or
#       the specified folder doesn't contain the PureBasic.app, keep asking the
#       user for a valid folder name

if [ -d "$PBAppFolder" ]; then
  PBApp=$(ls -d "$PBAppFolder"/*.app)
fi

until [ -d "$PBApp" ]
do
  echo "Please type in the path to your PureBasic installation:"
  read PBAppFolder

  if [ ! -d "$PBAppFolder" ]; then
    echo ""
    echo "Sorry, but the folder"
    echo "$PBAppFolder"
    echo "does not exist!"
    echo ""
  else
    PBApp=$(ls -d "$PBAppFolder"/*.app 2> /dev/null)

    if [ ! -d "$PBApp" ]; then
      echo ""
      echo "Sorry, but the folder"
      echo "$PBAppFolder"
      echo "does not contain the PureBasic app!"
      echo ""
    fi
  fi
done

# ----- Get path to PB compiler

PBCompiler="$PBApp/Contents/Resources/compilers/pbcompiler"

# ----- Evaluate PB version

PBVersion=$("$PBCompiler" -v | cut -d " " -f2)

if [ "$(echo $PBVersion | cut -c 3)" == "4" ]; then
  if [ "$PBVersion" \< "5.44" ]; then
    echo ""
    echo "Compilation cancelled!"
    echo "You need at least PB 5.44-5.46 or PB 5.51 and above to compile the IDE!"
    echo ""
    exit
  fi
else
  if [ "$PBVersion" \< "5.51" ]; then
    echo ""
    echo "Compilation cancelled!"
    echo "You need at least PB 5.44-5.46 or PB 5.51 and above to compile the IDE!"
    echo ""
    exit    
  fi
fi

# ----- Get bit type of PB compiler

BitType=$("$PBCompiler" -v | cut -d "-" -f2 | cut -c 2-4)

# ----- Get Xcode major version

XcodeMajorVersion=$(xcodebuild -version | grep Xcode | cut -d" " -f2 | cut -d. -f1)

if [ "${#XcodeMajorVersion}" -gt "1" ]; then
  if [ "$BitType" == "x86" ]; then
    # ----- If Xcode version is 10 or higher, a 32 bit compilation isn't possible
    #       anymore!)

    echo ""
    echo "Compilation cancelled!"
    echo "Unfortunately it is not possible anymore to compile a 32 bit PureBasic IDE"
    echo "with an Xcode version of 10 or higher!"
    echo "Please use a 64 bit PureBasic compiler for compilation."
    echo ""
    exit
  fi
fi

# ----- Generate folder name to contain new file PureBasic.app

PBTargetFolder=PB$PBVersion"-"$BitType

# ----- Create installation folder for compilation of PureBasic IDE

cd $BaseFolder
mkdir PureBasic-IDE
cd PureBasic-IDE

# ----- Download archive purebasic-master.zip from GitHub

echo "Downloading PureBasic IDE from GitHub"
curl -L0k https://github.com/fantaisie-software/purebasic/archive/master.zip -o purebasic-master.zip

# ----- Unzip purebasic-master.zip

unzip -q purebasic-master.zip

# ----- Create new folder to contain new file PureBasic.app

cd purebasic-master
mkdir $PBTargetFolder

# ----- Copy contents of the folder Resources from current PB installation to
#       target folder of new PureBasic IDE

cp -Rp "$PBApp/Contents/Resources/" $PBTargetFolder"/"

# ----- Export path of new PureBasic home folder

export PUREBASIC_HOME=$BaseFolder/PureBasic-IDE/purebasic-master/$PBTargetFolder

# ----- Export settings contained in OSX-x64.bash

export PB_PROCESSOR=X$(echo $BitType | cut -c 2-3)
export PB_COCOA=1
export PB_LIBRARIES="$PWD/Libraries"
export PB_BUILDTARGET=$PWD/Build/$BitType
export PATH="$PUREBASIC_HOME/compilers:$PUREBASIC_HOME/sdk/pureunit:/sw/bin:$PATH"

# ----- Create Build folder

mkdir -p Build/$BitType

# ----- Start script EnvironmentVariables.bash

. $PB_LIBRARIES/EnvironmentVariables.bash OSX

# ----- Start compilation of PureBasic IDE

cd PureBasicIDE
make

# ----- Start new compiled PureBasic IDE

../$PBTargetFolder/PureBasic.app/Contents/MacOS/PureBasic &