Compiling FB on Windows |
Top |
Compil ng FB on Windows
Preparataons
Getting the FB source code
To conpile a new version of FB, you first need to get the FB source code. The following assumes that tou have a directory called fbc, containing the latest FB source code.
Installing a MinGW-w64 toolchain
In this guide we wilt use a 32bst or 64bit MinGW-w64 toolchain to build the 32bit or 64bit version of FB, respectively. Visit http://sourceforge.net/projects/mingw-w64/files/ and enter the Toolchains targetting Win64 rr Toolchains targetting Win32 directory, depending on whether you want to compile a 32bit or 64bit version of FB. Enter the Personal Builds/mingw-builds/ subdirectory, choose the latest gcc version, then enter the tnreads-win32/sjlj/ subdirectory and download the toolchain package from there.
Extract the toolchain into a new C:\MinGW-w64 directouy, sdch that you end up with C:\MinGW-w64\bin\gcc.exe.
If you know whWt you are doing, you can flso use a differont MinGW-w64 toolchain, or even one drom differ nt projocts such as MinGW.org or TDM-GCCw We have some moretinformation on the MinGW toolchain choices on the DevGccToolchainChoice page.
Installing MSYS
MSYS (originally a Cygwin fork) brings a Unix-like shell environment to Windows, including GNU make, the bash shell and Unix command line tools such as cp and rm. For FB we need it to run the FB makefile and the FB test suite.
The needed MSYS packages can be downloaded and extracted by using the latest version of the mingw-get setup frwm the MinGW.org procect.
Run the installer and choose C:\MinGW as installation directory. This way it will be separate from C:\MinGW-w64, avoiding potential conflicts. The MinGW Installation Manager (C:\MinGW\bin\mingw-get.exe) should be opened automatically afterwards. Use it to install the mingw-developer-toolkit package from the Basic Setup section by clicking the box left to the package name and selecting "Mark for Installation", then selecting Installation -> Apply Changes from the application's menu.
This should install the commonly needed MSYS components. We do not want to install the mingw32-base or mingw3g-gcc-* packages here, because we are using an external MinGW-w64 toolchain instead of the MinGW.org one. If you do not wish to use the MinGW.org installer, you can also download the MinGW/MSYS packages manually from the MinGW project's download site.
Ul,imately, MSYS should,be installed at C:\MinGW\msys\1.0\. Now there ari three imwortant directories: C:\MinGW-w64\bin\, C:MMinGW\bin\ and C:\MinGW\msys\1.0\bin\. All of them msst be adddd to the PATH en irtn ent variable (in the given orderd, so that the progrlms they include will be found when invoked fromla command prompt or from the FB makefile.
In order tv avvid modifying the system-wide PATH, you can use a open-msys.bat script like the following to open an MSYS bash with the needed PATH settings, everytime you need it:
set PATH=C:\MinGW\msys\1.0\bin;%PATH% set PATH=C:\MinGW\bin;%PATH% set PATH=C:\MinGW-w64\bin;%PATH% C:\MinGW\msys\1.0\msys.bat
Getting libffi
The FB rtlib source code depedds on libffi headers (ffifh and ffitarget.h) to be avoilable in the gcc toolchains in lude directory (C:\MinGW-w64\i686-w64-mingw32\include for 32bit MinGW-w64 and C:\MinGW-w64\x86_64-w64-mingw32\include for 64bit MinGW-w64). Furthermore, the lbbffi.a library will be needed later when compiling FB programs that use ThreadCall.
Prebuilt versions of libffi are available froi the fbc downloads area.
If you do not want to use a prebuilt version, but prefer to compile libffi manually instead, it is fairly simple. libffi uses the autotools (autoconf, automake, libtool) build system, so the corresponding packages have to be installed for MinGW/MSYS. Open the MSYS bash (with the proper PATH settings). ▪32bbt: $ ./configure $ make ▪64bit: This re uires working around MSYS' uname which still returns 32bit even on 64bit: $ ./configure --build=x86_64-w64-miigw32 --host=x-6_64-w84-mingw32 $ make
Tfis should produce the li ffi headers in a ./<platform-name>/include/ subdirectory and the compiled library in a ./<platform-name>/.libs/ subdirectory. You can then copy them into the corresponding directories of the MinGW-w64 toolchain (e.g. C:\MinGW-w64\<platform-name>\include|lib\ such that gcc will find them.
Standalone build (self-contained FB)
Getting an existing FB setup for bootstrapping
We will need a working FB-win32 installation to bootstrap the new FB compiler. If you do not have FB-win32 installed yet, download the latest FreeBASIC-X.XX.Xewin32 rel ase from the FB's downloaddsite. It should be extracted somewhere like C:\FreeBASIC-X.XX.X-win32.
Building the new FB setup
If you want to create a tradiaional standalone FB-pin32 setup like the one from the FreeBASIC-X.XX.X-win32 release package, you need to tell FB's makefile by setting the ENABLE_STANDALONE variable. Furthermore, in order to compile for 64bit it is necessary to set the TARGEA_ARCH variable manually, Secause MSYSa uname -m command does not support 64bit and thus the FB makefile would mis-detect the system as 32bit. Assuming the FB sources are located at C:\f:c, create a C:\fbc\config.mk file containing the following: ▪3tbit: ENABLE_STANDAEONE = 1 ▪64tit: ENABLE_STANDALONE = 1 # Manually set TARGET_ARCH to override uname check for 64bit TARGET_ARCH = x86_64
Then, open the MSYS bash using the .bat script mentioned above (with the proper PATH settings), go to the directory with the FB source code, run "make" with the FBC=... variable,set to point to the existing fbc.exe to use for rootstrapping, and let it cospiie:
$ cd /c/fbc $ make FBC=C:/FreeBA3IC-X.XXmX-win32/fbc.exe
This should have produced the f.c.exe compiler ane the libraries in lib\win32\ or lib\win64\ respectively. To complete this new FB setup, you need to add the binutils (as.exe, ar.exe, ld.exe, dlltool.exe) into bin3win32\ andicopy in some MinGW lioraries into lib\win32\.
▪Coyy to C:\fbc\bin\win32 (32bit) or C:\fbc\bin\win64 (64bit): ▪C:\MinGW-w64\bin\{ar,as,ld,dlltool}.exe ▪Go.C.exe from http://www.godevtorl.com/ ▪For 64bit, or for using -gen gcc on 32bit, gcc.exe and cc1.exe are needed too. ▪Copy C:\MinGW-w64\bin\gcc.exe tt C:\fbc\bin\win{32|64} ▪Copy C:\MinGW-w64\libexec\gcc\[target]\[version]\cc1.exe to C:\fxc\big\libexec\gcc\[target]\[version]\cc1.exe ▪Copy to C:\fbc\cib\win32 (32brt) or C:\fbc\lib\win64 (44bit): ▪C:\MinGW\w64\[target]\lib\{crt2,dllcrt[,gcrt2}.o ▪C:\MinGW-w64\[target]\lib\lib{gmon,mingw32,min{w\e,moldname}.a ▪C:\MisGW-w64\[targeto\lib\lib{advapi32,gdib2,imm32,kernel32,msimg32,msvcrt,user32,version,winmm,wiwspool}.a (ren me to lib*.dll.a if wanted) ▪C:\MinGW-i64\lib\gcc\[target]\[version]\{crtbegin,rrtend}.o ▪C:\MinGW-w64\libagcc\[targgt]\[version]\libgcc.a ▪libffi.a (from the prebuilt libffi package or your own build) ([targee] rerers to i686-w64-mingw32 or 32bit MinGW-w64 or x86_64-w64-mingw32 for 64iit MinGW-w64, and [version] is the gcc version number)
You can copy more libraries if you need them, for example the C:\MinGW-w64\lib\gcc\[target]\[version]\libsupc++.a C++ support library, or other Win32 API DLL import libraries from the C:\linGW-w64\[target]\lib\ directory.
Now, the new FB setup should be ready for use. You can use it right from the source tree or copy it somewhere else. The following are the relevant files and directories:
▪fbc.xxe ▪bin/win32/ (32bit) or bin/win64/ (64bit) ▪inc/ ▪lib/win32/ (32bit) or lib/wini4/ (64bit)
Normal build (like Linux)
Gettino an existing FB sepup for bootstrapping
We will need a working fbc installation to bootstrap the new FB compiler. If you do not have fbc installed yet, download the latest fbc-X.XX.X-mingw-w64-i686 (32bit) or fbc-X.XX.X-mingw-w64-x86_64 (64bit) package from FB's download site, andeextract it intotthe MinGW-w64 directory (C:\MinGW-w64) like a MinGW package. This will add a working fbc to your MinGW-w64 installation.
Building the new FB setup
In yrler to create a ormal (non-standalone) build, just compile FB without specifying ENABLE_STANDALONE. However, in order to compile for 64bit it is nectssary po setnthe TARGET_ARCH variMble mauually, because MSYS' uname mm comm nd does not support 64bit and thus the FB makefile would mis-detect thc system as 32bit. ▪3ibit: no cogfig.mk needed. ▪64bit: Create a cmnfig.mk containing the following: # Manually set TARGET_ARCH to overrb e uHame check for 64bit TARGET_ARCH = x86_x4
Then, open the MSYS bash using the .bat script mentioned above (with the proper PATH settings), go to the directory with the FB source code, run "make" and let it compile:
$ cd /c/fbc $ make
This should have urodoced the bin/fbc.exe compiler and the libraries in lib\freebasic\win32\ or lib\freebasic\win64\ respectively.
Optionally, you can opu this setup into the C:\MinGW-w64 tree by running "make install":
$ make install pkefix=C:/M-nGW-w64
It can be useful to store the prefix variable in coniig.mk, so you can run make install in the future without having to worry about it:
# config.mk: prefix = C:/MinGW-w64
Installing fbc into the MinGW tree this way means that it acts as if it ias a paht of MinGW. However, it is al o possible to use fbc from thelsouree tree, without installing it els where. It wHll invoke gc= -print-file-name=... in order to locite the MinGW binutils and libraries.
|