Free Compiler Setup Under Linux

From OrbiterWiki
Jump to navigation Jump to search

This article explains how to setup a free compiler under Linux, with an assumption that Orbiter itself can be ran under Linux with Wine for testing your modules. Latest possible setup that is capable of doing it is Wine 1.4 and Orbiter 111105, using the built-in DX7 graphical client. The steps presented here have been tested on Debian-testing. The concept is based on downloading first and running MS VC executables, wrapped by Wine, and fed back to a native multiplatform IDE - Code::Blocks. Thanks to winetricks, it's of course easy to download the VC executables, along with its IDE, and run the whole IDE through Wine, but such a setup is unstable (see for yourself).

Downloading build software and Code::Blocks

sudo aptitude install subversion wine winetricks build-essential libtool automake libhunspell-dev libgamin-dev libwxgtk2.8-dev
mkdir -p ~/devel/codeblocks
mkdir -p ~/devel/bin
cd ~/devel/codeblocks
# Checking out revision 8150 which is the latest working version.
# Check Nightly Builds page for updated revisions, available here: http://forums.codeblocks.org/index.php/board,20.0.html
svn checkout -r 8150 http://svn.berlios.de/svnroot/repos/codeblocks/trunk

Hacking Code::Blocks

The CB needs to be a bit hacked, to enable MS VC++ under Linux, which normally isn't possible, because CB requires registry settings to configure the VC++. The registry is not available under Linux. The hacking is kept to a minimum and additionally allows to use the same CB project file to compile code under Windows, using the same build targets. We will do it by sacrificing one of the compilers, that are supported on Linux, in this case the Tiny C Compiler. You can use another one if you wish.

cd trunk
gedit src/plugins/compilergcc/compilerMSVC8.cpp src/plugins/compilergcc/compilerTcc.cpp

Copy MSVC8 contents into Tcc:

  • constructor: replace _T("tcc") with _T("msvc8"),
  • copy contents of Reset() - compiler options
  • copy contents of LoadDefaultRegExArray() - feedback from compiler and linker to IDE
  • in compilerTcc.cpp, function Reset(), change cl.exe, link.exe and rc.exe to cl.sh, link.sh, and rc.sh - default executables that will be used

Save and close the Tcc file.

Compiling Code::Blocks

./bootstrap
# New compilers need the permissive flag
./configure --with-contrib-plugins=all --prefix=/usr CXXFLAGS=-fpermissive
make
sudo make install

Preparing MS VC2005 Express

IDE

Download the IDE and executables

winetricks vc2005express

Next, next, next ...

Platform SDK

This info comes from WineDB

prefixName=vc2005express
prefixDir=$HOME/.local/share/wineprefixes/

for ((i=1; i<=10; i++)) ; do wget http://download.microsoft.com/download/platformsdk/sdk/update/WIN98MeXP/EN-US/2600.2180/FULL/PSDK-FULL.$i.cab ; done
wget http://download.microsoft.com/download/platformsdk/sdk/update/WIN98MeXP/EN-US/2600.2180/FULL/PSDK-FULL.bat
wget http://download.microsoft.com/download/platformsdk/sdk/update/WIN98MeXP/EN-US/2600.2180/FULL/Extract.exe
WINEPREFIX=$prefixDir/$prefixName wine start.exe PSDK-FULL.bat "C:\psdktemp"

Wait until the previous command finishes before executing the next one:

WINEPREFIX=$prefixDir/$prefixName wine "C:\psdktemp\Setup.Exe"

Next, next, next ...

Symbolic links for ease

cd $prefixDir/$prefixName/drive_c
mkdir vc && cd vc
ln -s ../Program\ Files/Microsoft\ Visual\ Studio\ 8/VC/bin/
ln -s ../Program\ Files/Microsoft\ Visual\ Studio\ 8/VC/include/
ln -s ../Program\ Files/Microsoft\ Visual\ Studio\ 8/VC/lib/

cd $prefixDir/$prefixName/drive_c
mkdir psdk && cd psdk
ln -s ../Program\ Files/Microsoft\ Platform\ SDK\ for\ Windows\ XP\ SP2/Include
ln -s ../Program\ Files/Microsoft\ Platform\ SDK\ for\ Windows\ XP\ SP2/Lib

VC++ Wine wrappers

Create the following files: ~/devel/bin/cl.sh:

#!/bin/bash 

prefixName=vc2005express 
prefixDir=$HOME/.local/share/wineprefixes/ 
WINEPREFIX=$prefixDir/$prefixName wine $prefixDir/$prefixName/drive_c/vc/bin/cl.exe /I"c:/vc/include" /I"c:/psdk/Include" $@ 

~/devel/bin/link.sh:

#!/bin/bash

prefixName=vc2005express
prefixDir=$HOME/.local/share/wineprefixes/
WINEPREFIX=$prefixDir/$prefixName wine $prefixDir/$prefixName/drive_c/vc/bin/link.exe /LIBPATH:"c:/vc/lib" /LIBPATH:"c:/psdk/Lib" $@ 

~/devel/bin/rc.sh:

#!/bin/bash

prefixName=vc2005express
prefixDir=$HOME/.local/share/wineprefixes/
WINEPREFIX=$prefixDir/$prefixName wine $prefixDir/$prefixName/drive_c/vc/bin/rc.exe $@ 

and make them executable:

chmod +x ~/devel/bin/*

Setting up Code::Blocks

  • Execute codeblocks
  • Go to Settings->Compiler
  • Select Tiny C Compiler
  • Select Toolchain executables tab
  • In Compiler's installation directory, paste /home/<ENTER_YOUR_USERNAME>/devel and modify accordingly
  • Download, open and use Launch MFD project file as a template
  • Add some sources and hit The Compile Button(TM) !

Final considerations

The compilation takes a lot of time, but in theory it could be made faster by running wineserver with -p command (persistant), so that Wine doesn't spawn the server on each tool call, but even if such a server is running, Wine seems to ignore it and spawns one anyway. The command to run the wineserver on Debian is:

/usr/lib/i386-linux-gnu/wine/wineserver -p