Difference between revisions of "Nightly Cookbook"

From Code::Blocks
 
(40 intermediate revisions by 12 users not shown)
Line 1: Line 1:
[[Category:Installation]]
+
[[Category:Developer Documentation]]
 
This page is under construction by 'killerbot'. Just be patient, some day it will be finished.
 
This page is under construction by 'killerbot'. Just be patient, some day it will be finished.
  
 
== Introduction ==
 
== Introduction ==
This article will describe the process used in creating the nightly builds, and can be used as a guideline if you want to build Code::Blocks yourself. It is described as a sequence of 'manual' actions, it is surely possible to script automate several of these tasks. But that's beyond the scope of the original article.
+
This article will describe the process used in creating the nightly builds, and can be used as a guideline if you want to build Code::Blocks yourself. It is described as a sequence of 'manual' actions.  While it is possible to automate several of these tasks via script, that is beyond the scope of this article.
 
Current limitation : Windows unicode build.
 
Current limitation : Windows unicode build.
 
  
 
== Shopping List ==
 
== Shopping List ==
Line 22: Line 21:
 
== Shopping Time ==
 
== Shopping Time ==
 
=== Compiler ===
 
=== Compiler ===
Let's start by shopping for our first item on the list, a compiler. Several compilers are available, some free, some expensive. Since Code::Blocks is being build by the developers with GCC, we might as well use that one. It is very standard conformant, though not the fastest one around. GCC on windows is available in several flavors, there are CygWin ports, MingW ports. The most easiest and cleanest port is MingW, once again this is what Code::Blocks distributes itself, when you download the official package (the one including the compiler). We can find MingW at [http://www.mingw.org www.mingw.org]. [https://wiki.codeblocks.org/index.php?title=MinGW_installation#gcc_3.4.4_manual_install This] other post in the wiki describes what you need. Here we also stick to the 3.4.4 version, which works nicely.
+
Let's start by shopping for the first item on our list, a compiler. Several compilers are available; some free, some expensive. Since the Code::Blocks developers build Code::Blocks using GCC, we might as well use that one. It is very standards compliant, though not the fastest one around. GCC on windows is available in several flavors. There are CygWin ports and MingW ports.
Though let's put a very small explanation :
+
 
 +
The easiest and cleanest port is MinGW. This is the compiler distributed with Code::Blocks when you download the official package (the one including the compiler). We can find MinGW at [http://www.mingw.org www.mingw.org]. [https://wiki.codeblocks.org/index.php?title=MinGW_installation#gcc_3.4.4_manual_install This post] in the wiki describes how to install MinGW. We will stick to version 3.4.5, which works nicely. (Much has changed since this was originally written; if possible, use version 4.4.0 or newer.)
 +
 
 +
 
 +
First, a brief explanation of MinGW components:
 
* gcc-core : the core of the GCC suite
 
* gcc-core : the core of the GCC suite
 
* gcc-g++ : the c++ compiler
 
* gcc-g++ : the c++ compiler
 
* mingw Runtime : implementation of the run time libraries
 
* mingw Runtime : implementation of the run time libraries
* mingw utils : several utilities (implementation of smaller programs that GCC uses itself)
+
* mingw utils : several utilities (implementation of smaller programs that GCC itself uses)
* win32Api : if you want to create Windows programs, here's the headers/API.
+
* win32Api : the APIs for creating Windows programs
 
* binutils : several utilities used in build environments
 
* binutils : several utilities used in build environments
 
* make : the Gnu make program, so you can build from make files
 
* make : the Gnu make program, so you can build from make files
* GDB : the Gnu debugger : for hunting those nasty bugs
+
* GDB : the Gnu debugger : for hunting those nasty bugs (version 6.3.2 or above !!!)
 +
 
 +
 
 +
I would suggest extracting (and installing for the GDB) everything in the C:\MinGW directory. The remainder of this article will assume that this is where you have put it. If you already have an installation of Code::Blocks that came bundled with MinGW (for example RC2), I still advise you to install MinGW as described here. A compiler does not belong under the directory tree of an IDE; they are two separate things. Code::Blocks just brings it along in the official versions so that the average user does not need to bother with this process. But, since you are reading this, you are no longer an average user. :-)
 +
 
 +
You may need to add the 'bin' directory of your MinGW installation to your path (example : C:\MinGW\bin).  An easy way to do this is with the following command at the command prompt:
  
I would also suggest to extract (and install for the GDB) everything in C:\MingW, the remainder of this article will assume this is where you have put it. In case you already had an installation of Code::Blocks (for example RC2) and you installed the version coming with MingW, I still would like to advice you to install MingW as described here. A compiler does not belong under the directory tree of an IDE, it are 2 seperate things. Code::Blocks just brings it along in the official versions, so the average user does not need to bother, but since you are reading this, you are no longer an average user. :-)
+
set path=%PATH%;C:\MinGW\bin;C:\MinGW\mingw32\bin;
It is advised to add your 'bin' directory of your MingW installation (example : C:\MingW\bin) to your path.
 
  
 
=== Initial Build System ===
 
=== Initial Build System ===
We could try to build Code::Blocks by using makefiles, but we can do this way nicer : let's build Code::Blocks by using ........ Code::Blocks. So no chicken and egg problem. All we need to do, is get hold of a pre-build Code::Blocks. Well, just download a nightly build, make your selection from [/index.php?board=20.0 here].
+
We could try to build Code::Blocks by using makefiles, but there is an easier way: let's build Code::Blocks by using ........ Code::Blocks. All we need to do is get hold of a pre-built version Code::Blocks.
The nighly builds are unicode versions, containing the core and contributed plug-ins.
+
 
Just unpack the 7-zip file to any directory you like (eg : C:\CodeBlocksTempNightly).
+
 
Go ahead, start up that Code::Blocks, it should discover the MingW compiler we installed just before.
+
First, download a nightly build.  You can make your selection from [/index.php?board=20.0 here]. The nightly builds are unicode versions, containing the core and contributed plug-ins.
Well, one more thing. Code::Blocks needs one more dll to work correclty, the wx widgets dll, you can also download it at the nightly builds forum. Just unzip it in the same directory as where you unpacked the Code::Blocks nightly build. To be really honest, it also needs the mingwm10.dll, but don't worry, we already have it : it's in the bin directory of our MingW installation. So make sure the bin directory of your MingW installation is in the path.
+
 
If you don't have 7-zip, you can download it for free from [http://www.7-zip.org here].
+
Next, unpack the 7-zip file to any directory you like (e.g. C:\CodeBlocksTempNightly). If you don't have 7-zip, you can download it for free from [http://www.7-zip.org the 7-zip website].
 +
 
 +
Now, Code::Blocks needs one more dll to work correctly: the WxWidgets dll. You can also download it at the nightly builds forum. Just unzip it into the same directory that you unpacked the Code::Blocks nightly build. It also needs the mingwm10.dll, but don't worry - we already have it. It's in the bin directory of our MinGW installation. So, it's important to make sure the bin directory of your MinGW installation is in your path variable (see above).
 +
 
 +
Finally, start up this new nightly build of Code::Blocks. It should discover the MinGW compiler we just installed.
  
 
== Version Control System ==
 
== Version Control System ==
In order to be able to retrieve the Code::Blocks sources we need to install a Version Control System. The Code::Blocks developers provide their sources through the "SVN" version control system. Therefor we need a client to access that 'svn'-repository of sources. A nice and easy client for Windows is TortoiseSvn, which is freely available from [http://tortoisesvn.tigris.org/ here]. Download and install it, keep all suggested settings.
+
In order to be able to retrieve the latest and greatest Code::Blocks sources, we need to install a Version Control System.
Now go create a directory wherever you like, for example D:\projects\CodeBlocks. Right click on that directory and choose from the pop-up menu : svn-checkout.
+
 
In the dialog that pop's up fill in the following fields :  
+
The Code::Blocks developers provide their sources through the SVN version control system. So, we need a client to access their svn repository of sources. A nice, easy client for Windows is TortoiseSVN, which is freely available from [http://tortoisesvn.tigris.org/ here]. Download and install it, keeping all suggested settings.
   - Url of Repository : svn://svn.berlios.de/codeblocks/trunk
+
 
 +
Now, go create a directory wherever you like, for example D:\projects\CodeBlocks. Right click on that directory and choose from the pop-up menu : svn-checkout. In the dialog that pops up, fill in the following information:  
 +
 
 +
   - Url of Repository : <strike> svn://svn.berlios.de/codeblocks/trunk </strike> http://svn.code.sf.net/p/codeblocks/code/trunk
 
   - leave all other settings as they are
 
   - leave all other settings as they are
Now be patient wil svn is retrieving all recent sources from the repository and is copying them into our directory. Yes, yes, all those Code::Blocks sources are coming your way.
 
More info on svn settings : [http://codeblocks.org/source_code.shtml Info on svn settings].
 
  
All righty, time to continue are shopping session.
+
Now be patient while TortoiseSVN retrieves the most recent source files from the Code::Blocks repository into our local directory. Yes; all those Code::Blocks sources are coming your way!
 +
 
 +
For more info on SVN settings, see [https://www.codeblocks.org/downloads/svn info on SVN settings]. If you don't like an Explorer integration or look for a cross-plattform client you might want to have a look at [http://rapidsvn.tigris.org/ RapidSVN] (which is btw. also written using wxWidgets).
 +
 
 +
All righty, time to continue our shopping session.
  
 
== wxWidgets ==
 
== wxWidgets ==
wxWidgets is a platform abstraction that provides an API that covers amongst many things, GUI, sockets, files, registry functionality. In that way when using this API you can create a platform independent program.
+
WxWidgets is a platform abstraction that provides an API to support many things such as GUI, sockets, files, registry functionality. By using this API, you can create a platform independent program.
Code::Blocks is a wxWidgets (here after : wx ) application, that means if you want to run Code::Blocks you needed the wx functionality, this can be provided in many flavours, could be a dll, or a static library, Code::Blocks uses wx as a dll, this dll can also be downloaded from the nightly build section of the forum.
+
 
However if we want to build a wx application, we need to be able to include the headers of the wx sources, they will tell the compiler what (and how) the wx functionality is. So we need at least those headers, but next to this before we can use the dll to build our application, our application will need to link with the import libraries. So in addition we need those import libraries. Well, let's take it step by step. wx is provided as a zip file of it's sources, so we need to build that ourselves, well we already shopped for the MingW compiler, so we have all the tools we need at hand.
+
Code::Blocks is a wxWidgets (here after: wx ) application, that means if you want to run Code::Blocks you needed the wx functionality. This can be provided in a couple of ways. It could be a .dll or a static library. Code::Blocks uses wx as a dll and this dll can also be downloaded from the nightly build section of the forum.
Go download the wx sources (at time of writing : version 2.6.2) [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.6.2.zip here], let's unzip it in D:\Projects, so we will end up with wx root directory D:\Projects\wxWidgets-2.6.2.
+
 
We are going to mention the wx root directory from now on as <wxDir>
+
However, if we want to build a wx application, we need to include the headers of the wx sources. They tell the compiler about the functionality of wx. In addition to those header files, our application needs to link to the wx import libraries. Well, let's take it step by step.  
Now we are gonna build the wxWidgets, yes we are. This is how we do it (make sure C:\MingW\bin is in your path, during the build some programs will be called that reside in the the MingW\bin directory), especially make has to be version 3.80 or above.
+
 
   - open up a console in <wxDir>\build\msw
+
Wx is provided as a zip file of it's sources, so we need to build that ourselves. We already shopped for the MinGW compiler, so we have all the tools we need at hand.
  - clean up the source tree : mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 clean
+
 
   - actual build : mingw32-make -f makefile.gcc USE_XRC=1 SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1
+
Download the [http://www.wxwidgets.org/downloads/ wx sources] (at time of writing : version 2.8.12) [http://prdownloads.sourceforge.net/wxwindows/wxMSW-2.8.12.zip in this .zip here].
This is going to take some time, got get yourself a nice ice-cream, a beer, ...
+
 
Did you enjoy your refreshment, in the meantime have a little look in the direcory <wxDir>\lib\gcc_dll : the import libraries and the dll have shown up, there's also a mswu\wx subdirectory at that position containing setup.h .
+
Next, let's unzip the wx sources into C:\Projects so we will end up with a wx root directory like this: C:\Projects\wxWidgets-2.8.12. Note that we are going to refer to the wx root directory from now on as <wxDir>
Congratulations, you have build wxWidgets, let's do some more preliminary tasks before we get to the read deal of compiling Code::Blocks.
+
 
 +
Now, we are going to build the wxWidgets. This is how we do it:
 +
 
 +
First, make sure C:\MingGW\bin is in your path, during the build some programs will be called that reside in the the MinGW\bin directory. Also, Make has to be version 3.80 or above.
 +
 
 +
Now it is time to compile wxWidgets. Open the command prompt and change to the wxWidgets directory:
 +
   <tt>cd /D <wxDir>\build\msw</tt>
 +
''Note: the ''<code>/D</code>'' flag after ''<code>cd</code>'' may be omitted from the command; it simply allows command prompt to change drives if necessary.''
 +
 
 +
We are now in the right place. We are first going to clean up the source:
 +
  <tt>mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 clean</tt>
 +
 
 +
Once everything is clean, we can compile wxWidgets:
 +
   <tt>mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1</tt>
 +
 
 +
If you are using TDM-gcc 4.8.1, you will have to add the following option on the command line :
 +
  <tt>CXXFLAGS+=-fpermissive</tt>
 +
 
 +
This is going to take some time, so go get yourself a nice ice-cream, a beer, ...
 +
 
 +
Note: For making the debug build, follow these steps:
 +
  First clean any previous compilation with:
 +
  <tt>mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=1 clean</tt>
 +
 
 +
  And then compile with:
 +
  <tt>mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=1</tt>
 +
 
 +
  ... If you are not on diet, get another ice-cream, a beer, ....
 +
 
 +
 
 +
Did you enjoy your refreshment? Well have a little look in the directory (<wxDir>\lib\gcc_dll) now. The import libraries and the dll have shown up and there should also a mswu\wx subdirectory at that position containing setup.h.
 +
 
 +
Congratulations! You have just built wxWidgets!
 +
 +
 
 +
Let's do some more preliminary tasks before we get to the real deal of compiling Code::Blocks.
  
 
== Zip ==
 
== Zip ==
During the build of Code::Blocks several resources are going to be zipped in zip files, therefor the build process should have access to a zip.exe. We have to download that zip.exe and put it somewhere in our path (how about MingW\bin).
+
During the build of Code::Blocks, several resources are going to be zipped in zip files. Therefore, the build process should have access to a zip.exe. We have to download that zip.exe and put it somewhere in our path.  A good place is: MingW\bin.
Yo can download it for free from [http://www.info-zip.org/pub/infozip/Zip.html here] and this is a [ftp://ftp.info-zip.org/pub/infozip/WIN32/zip231xN.zip direct link(32bit)] to the most recent version at the time of writing. From the downloaded zip files it is sufficient to extract the zip.exe.
+
 
 +
You can download zip.exe for free from [http://www.info-zip.org/Zip.html this site] and this is a [ftp://ftp.info-zip.org/pub/infozip/win32/zip232xn.zip direct link(32bit)] to the most recent version at the time of this writing.  
  
 +
Once downloaded, simply extract zip.exe to the appropriate location.
  
 
== Workspace ==
 
== Workspace ==
This brings us to the last preliminary task. The Code::Blocks code can be divided in 2 major parts : the core with internal plug-ins, and the contributed plug-ins. You always need to build the core/internal parts before building the contrib part. To build the internal part, you can use the Code::Blocks project file which you can find at (our Code::Blocks master directory is from now one mentioned as <cbDir>) <cbDir>\src\CodeBlocks.cbp. A workspace (which groups several projects together) for building the contrib plug-ins can be found at <cbDir>\src\ContribPlugins.workspace.
+
This brings us to the last preliminary task. The Code::Blocks code can be divided into 2 major parts: the core with internal plug-ins, and the contributed plug-ins. You always need to build the core/internal parts before building the contrib part.  
But let's create a worksapce containing everything, and let's put that workspace in the master directory <cbDir>. Just use a regular text editor and create a file with the name "CbProjects.workspace" and give it the following content :  
+
 
 +
To build the internal part, you can use the Code::Blocks project file which you can find at: <cbDir>\src\CodeBlocks.cbp. Our Code::Blocks master directory is from now one mentioned as <cbDir>, by the way. A workspace is something that groups several projects together. To build the contrib plug-ins, they can be found at <cbDir>\src\ContribPlugins.workspace.
 +
 
 +
But, let's create a workspace containing everything. Let's put that workspace in the master directory <cbDir>. Just use a regular text editor and create a file with the name "CbProjects.workspace" and give it the following content :  
  
 
  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
 
  <?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
Line 82: Line 138:
 
   <Workspace title="Workspace">
 
   <Workspace title="Workspace">
 
     <Project filename="src\CodeBlocks.cbp" active="1" />
 
     <Project filename="src\CodeBlocks.cbp" active="1" />
 +
    <Project filename="src\plugins\contrib\AutoVersioning\AutoVersioning.cbp" />
 +
    <Project filename="src\plugins\contrib\BrowseTracker\BrowseTracker.cbp" />
 +
    <Project filename="src\plugins\contrib\byogames\byogames.cbp" />
 +
    <Project filename="src\plugins\contrib\cb_koders\cb_koders.cbp" />
 +
    <Project filename="src\plugins\contrib\codesnippets\codesnippets.cbp" />
 
     <Project filename="src\plugins\contrib\codestat\codestat.cbp" />
 
     <Project filename="src\plugins\contrib\codestat\codestat.cbp" />
 
     <Project filename="src\plugins\contrib\copystrings\copystrings.cbp" />
 
     <Project filename="src\plugins\contrib\copystrings\copystrings.cbp" />
 +
    <Project filename="src\plugins\contrib\devpak_plugin\DevPakPlugin.cbp" />
 
     <Project filename="src\plugins\contrib\dragscroll\dragscroll.cbp" />
 
     <Project filename="src\plugins\contrib\dragscroll\dragscroll.cbp" />
     <Project filename="src\plugins\contrib\devpak_plugin\DevPakPlugin.cbp" />
+
     <Project filename="src\plugins\contrib\envvars\envvars.cbp" />
 +
    <Project filename="src\plugins\contrib\headerfixup\headerfixup.cbp" />
 
     <Project filename="src\plugins\contrib\help_plugin\help-plugin.cbp" />
 
     <Project filename="src\plugins\contrib\help_plugin\help-plugin.cbp" />
 
     <Project filename="src\plugins\contrib\keybinder\keybinder.cbp" />
 
     <Project filename="src\plugins\contrib\keybinder\keybinder.cbp" />
 
     <Project filename="src\plugins\contrib\profiler\cbprofiler.cbp" />
 
     <Project filename="src\plugins\contrib\profiler\cbprofiler.cbp" />
 +
    <Project filename="src\plugins\contrib\regex_testbed\RegExTestbed.cbp" />
 
     <Project filename="src\plugins\contrib\source_exporter\Exporter.cbp" />
 
     <Project filename="src\plugins\contrib\source_exporter\Exporter.cbp" />
 +
    <Project filename="src\plugins\contrib\symtab\symtab.cbp" />
 +
    <Project filename="src\plugins\contrib\ThreadSearch\ThreadSearch.cbp" />
 
     <Project filename="src\plugins\contrib\wxSmith\wxSmith.cbp" />
 
     <Project filename="src\plugins\contrib\wxSmith\wxSmith.cbp" />
 +
    <Project filename="src\plugins\contrib\wxSmithContribItems\wxSmithContribItems.cbp" />
 +
    <Project filename="src\plugins\contrib\wxSmithAui\wxSmithAui.cbp" />
 +
    <Project filename="src\plugins\contrib\lib_finder\lib_finder.cbp" />
 +
    <Project filename="src\plugins\contrib\HexEditor\HexEditor-win.cbp" />
 +
    <Project filename="src\tools\cb_share_config\cb_share_config.cbp" />
 +
    <Project filename="src\plugins\contrib\IncrementalSearch\IncrementalSearch.cbp" />
 +
    <Project filename="src\plugins\contrib\MouseSap\MouseSap.cbp" />
 
   </Workspace>
 
   </Workspace>
 
  </CodeBlocks_workspace_file>
 
  </CodeBlocks_workspace_file>
  
  
 
+
We will use this workspace to build all of Code::Blocks.
We will use this workspace to build all parts of Code::Blocks.
 
 
 
  
 
== Building Code::Blocks ==
 
== Building Code::Blocks ==
Finally we have arrived at the final step, our final goal. Run the Code::Blocks executable from your nightly build download. Choose from the File menu : Open, and browse for our above created workspace, and open it up. be a little patient while Code::Blocks is parsing everything, and Code::Blocks will ask us for 2 global variables, these global variables will the the nightly Code::Blocks where it can find wxWidgets (remember : header files and import libraries) and where it can find .... Code::Blocks, this is needed for the contrib plug-ins, they need to know (as for any user created plug-in) where the sdk (Code::Blocks header files) are.
+
Finally we have arrived at the final step; our final goal. Run the Code::Blocks executable from your nightly build download. Choose Open from the File menu and browse for our above created workspace, and open it up. Be a little patient while Code::Blocks is parsing everything, and Code::Blocks will ask us for 2 global variables, these global variables will tell the nightly Code::Blocks where it can find wxWidgets (remember : header files and import libraries) and where it can find .... Code::Blocks, this is needed for the contrib plug-ins, they need to know (as for any user created plug-in) where the sdk (Code::Blocks header files) are.
 
These are the values in our case :  
 
These are the values in our case :  
 
  - wx : <wxDir>
 
  - wx : <wxDir>
 
  - Code::Blocks (cb) : <cbDir>\src
 
  - Code::Blocks (cb) : <cbDir>\src
  
Now go to the Project Menu and choose (re)build workspace, and off you go, watch how Code::Blocks is building Code::Blocks.
+
Now go to the Project Menu and choose (re)build workspace, and off you go. Watch how Code::Blocks is building Code::Blocks.
Once everything has build, open up a console in <cbDir>\src and run the command "update.bat', this will transfer all builded deliverables from <cbDir>\src\devel to <cbDir>\src\output and in the meantime strip of all debugging symbols. Note this step is very important, do never ever forget it. Now you can copy the wx dll builded before both in that output and devel directory.
+
 
You can close your Code::Blocks now (that was the downloaded nightly remember).
+
Once the build is complete, open up a console in <cbDir>\src and run the command "update.bat". This will transfer all built deliverables from <cbDir>\src\devel to <cbDir>\src\output. In addition, it will strip out all debugging symbols. This step is very important - never ever forget it.  
 +
 
 +
Now you can copy the wx dll in both that output and the devel directory.
 +
 
 +
Then you can close Code::Blocks. That was the downloaded nightly remember?
 +
 
 +
Time to test it. In the output directory, start up the CodeBlocks.exe. If everything went well, you'll have your very own home-built Code::Blocks running.
  
Time to test : in that output directory start up the CodeBlocks.exe, and there you go, your home-build Code::Blocks is running. Enjoy !!!
+
Enjoy !!!

Latest revision as of 16:08, 12 February 2015

This page is under construction by 'killerbot'. Just be patient, some day it will be finished.

Introduction

This article will describe the process used in creating the nightly builds, and can be used as a guideline if you want to build Code::Blocks yourself. It is described as a sequence of 'manual' actions. While it is possible to automate several of these tasks via script, that is beyond the scope of this article. Current limitation : Windows unicode build.

Shopping List

In order to perform our build tasks, we will need several tools. Let's create an ingredient list for our cooking experiments :

  • a compiler
  • an initial build system
  • the Code::Blocks sources
  • zip program
  • svn (version control system)
  • wxWidgets

While we are at it, maybe someday we want to debug our programs, so let's add a debugger to the list :

  • debugger

Shopping Time

Compiler

Let's start by shopping for the first item on our list, a compiler. Several compilers are available; some free, some expensive. Since the Code::Blocks developers build Code::Blocks using GCC, we might as well use that one. It is very standards compliant, though not the fastest one around. GCC on windows is available in several flavors. There are CygWin ports and MingW ports.

The easiest and cleanest port is MinGW. This is the compiler distributed with Code::Blocks when you download the official package (the one including the compiler). We can find MinGW at www.mingw.org. This post in the wiki describes how to install MinGW. We will stick to version 3.4.5, which works nicely. (Much has changed since this was originally written; if possible, use version 4.4.0 or newer.)


First, a brief explanation of MinGW components:

  • gcc-core : the core of the GCC suite
  • gcc-g++ : the c++ compiler
  • mingw Runtime : implementation of the run time libraries
  • mingw utils : several utilities (implementation of smaller programs that GCC itself uses)
  • win32Api : the APIs for creating Windows programs
  • binutils : several utilities used in build environments
  • make : the Gnu make program, so you can build from make files
  • GDB : the Gnu debugger : for hunting those nasty bugs (version 6.3.2 or above !!!)


I would suggest extracting (and installing for the GDB) everything in the C:\MinGW directory. The remainder of this article will assume that this is where you have put it. If you already have an installation of Code::Blocks that came bundled with MinGW (for example RC2), I still advise you to install MinGW as described here. A compiler does not belong under the directory tree of an IDE; they are two separate things. Code::Blocks just brings it along in the official versions so that the average user does not need to bother with this process. But, since you are reading this, you are no longer an average user. :-)

You may need to add the 'bin' directory of your MinGW installation to your path (example : C:\MinGW\bin). An easy way to do this is with the following command at the command prompt:

set path=%PATH%;C:\MinGW\bin;C:\MinGW\mingw32\bin;

Initial Build System

We could try to build Code::Blocks by using makefiles, but there is an easier way: let's build Code::Blocks by using ........ Code::Blocks. All we need to do is get hold of a pre-built version Code::Blocks.


First, download a nightly build. You can make your selection from [/index.php?board=20.0 here]. The nightly builds are unicode versions, containing the core and contributed plug-ins.

Next, unpack the 7-zip file to any directory you like (e.g. C:\CodeBlocksTempNightly). If you don't have 7-zip, you can download it for free from the 7-zip website.

Now, Code::Blocks needs one more dll to work correctly: the WxWidgets dll. You can also download it at the nightly builds forum. Just unzip it into the same directory that you unpacked the Code::Blocks nightly build. It also needs the mingwm10.dll, but don't worry - we already have it. It's in the bin directory of our MinGW installation. So, it's important to make sure the bin directory of your MinGW installation is in your path variable (see above).

Finally, start up this new nightly build of Code::Blocks. It should discover the MinGW compiler we just installed.

Version Control System

In order to be able to retrieve the latest and greatest Code::Blocks sources, we need to install a Version Control System.

The Code::Blocks developers provide their sources through the SVN version control system. So, we need a client to access their svn repository of sources. A nice, easy client for Windows is TortoiseSVN, which is freely available from here. Download and install it, keeping all suggested settings.

Now, go create a directory wherever you like, for example D:\projects\CodeBlocks. Right click on that directory and choose from the pop-up menu : svn-checkout. In the dialog that pops up, fill in the following information:

 - Url of Repository :  svn://svn.berlios.de/codeblocks/trunk  http://svn.code.sf.net/p/codeblocks/code/trunk
 - leave all other settings as they are

Now be patient while TortoiseSVN retrieves the most recent source files from the Code::Blocks repository into our local directory. Yes; all those Code::Blocks sources are coming your way!

For more info on SVN settings, see info on SVN settings. If you don't like an Explorer integration or look for a cross-plattform client you might want to have a look at RapidSVN (which is btw. also written using wxWidgets).

All righty, time to continue our shopping session.

wxWidgets

WxWidgets is a platform abstraction that provides an API to support many things such as GUI, sockets, files, registry functionality. By using this API, you can create a platform independent program.

Code::Blocks is a wxWidgets (here after: wx ) application, that means if you want to run Code::Blocks you needed the wx functionality. This can be provided in a couple of ways. It could be a .dll or a static library. Code::Blocks uses wx as a dll and this dll can also be downloaded from the nightly build section of the forum.

However, if we want to build a wx application, we need to include the headers of the wx sources. They tell the compiler about the functionality of wx. In addition to those header files, our application needs to link to the wx import libraries. Well, let's take it step by step.

Wx is provided as a zip file of it's sources, so we need to build that ourselves. We already shopped for the MinGW compiler, so we have all the tools we need at hand.

Download the wx sources (at time of writing : version 2.8.12) in this .zip here.

Next, let's unzip the wx sources into C:\Projects so we will end up with a wx root directory like this: C:\Projects\wxWidgets-2.8.12. Note that we are going to refer to the wx root directory from now on as <wxDir>

Now, we are going to build the wxWidgets. This is how we do it:

First, make sure C:\MingGW\bin is in your path, during the build some programs will be called that reside in the the MinGW\bin directory. Also, Make has to be version 3.80 or above.

Now it is time to compile wxWidgets. Open the command prompt and change to the wxWidgets directory:

 cd /D <wxDir>\build\msw

Note: the /D flag after cd may be omitted from the command; it simply allows command prompt to change drives if necessary.

We are now in the right place. We are first going to clean up the source:

 mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1 clean

Once everything is clean, we can compile wxWidgets:

 mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=release UNICODE=1

If you are using TDM-gcc 4.8.1, you will have to add the following option on the command line :

 CXXFLAGS+=-fpermissive

This is going to take some time, so go get yourself a nice ice-cream, a beer, ...

Note: For making the debug build, follow these steps:
 First clean any previous compilation with:
  mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=1 clean
 
 And then compile with:
  mingw32-make -f makefile.gcc SHARED=1 MONOLITHIC=1 BUILD=debug UNICODE=1
 
  ... If you are not on diet, get another ice-cream, a beer, ....


Did you enjoy your refreshment? Well have a little look in the directory (<wxDir>\lib\gcc_dll) now. The import libraries and the dll have shown up and there should also a mswu\wx subdirectory at that position containing setup.h.

Congratulations! You have just built wxWidgets!


Let's do some more preliminary tasks before we get to the real deal of compiling Code::Blocks.

Zip

During the build of Code::Blocks, several resources are going to be zipped in zip files. Therefore, the build process should have access to a zip.exe. We have to download that zip.exe and put it somewhere in our path. A good place is: MingW\bin.

You can download zip.exe for free from this site and this is a direct link(32bit) to the most recent version at the time of this writing.

Once downloaded, simply extract zip.exe to the appropriate location.

Workspace

This brings us to the last preliminary task. The Code::Blocks code can be divided into 2 major parts: the core with internal plug-ins, and the contributed plug-ins. You always need to build the core/internal parts before building the contrib part.

To build the internal part, you can use the Code::Blocks project file which you can find at: <cbDir>\src\CodeBlocks.cbp. Our Code::Blocks master directory is from now one mentioned as <cbDir>, by the way. A workspace is something that groups several projects together. To build the contrib plug-ins, they can be found at <cbDir>\src\ContribPlugins.workspace.

But, let's create a workspace containing everything. Let's put that workspace in the master directory <cbDir>. Just use a regular text editor and create a file with the name "CbProjects.workspace" and give it the following content :

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<CodeBlocks_workspace_file>
 <Workspace title="Workspace">
   <Project filename="src\CodeBlocks.cbp" active="1" />
   <Project filename="src\plugins\contrib\AutoVersioning\AutoVersioning.cbp" />
   <Project filename="src\plugins\contrib\BrowseTracker\BrowseTracker.cbp" />
   <Project filename="src\plugins\contrib\byogames\byogames.cbp" />
   <Project filename="src\plugins\contrib\cb_koders\cb_koders.cbp" />
   <Project filename="src\plugins\contrib\codesnippets\codesnippets.cbp" />
   <Project filename="src\plugins\contrib\codestat\codestat.cbp" />
   <Project filename="src\plugins\contrib\copystrings\copystrings.cbp" />
   <Project filename="src\plugins\contrib\devpak_plugin\DevPakPlugin.cbp" />
   <Project filename="src\plugins\contrib\dragscroll\dragscroll.cbp" />
   <Project filename="src\plugins\contrib\envvars\envvars.cbp" />
   <Project filename="src\plugins\contrib\headerfixup\headerfixup.cbp" />
   <Project filename="src\plugins\contrib\help_plugin\help-plugin.cbp" />
   <Project filename="src\plugins\contrib\keybinder\keybinder.cbp" />
   <Project filename="src\plugins\contrib\profiler\cbprofiler.cbp" />
   <Project filename="src\plugins\contrib\regex_testbed\RegExTestbed.cbp" />
   <Project filename="src\plugins\contrib\source_exporter\Exporter.cbp" />
   <Project filename="src\plugins\contrib\symtab\symtab.cbp" />
   <Project filename="src\plugins\contrib\ThreadSearch\ThreadSearch.cbp" />
   <Project filename="src\plugins\contrib\wxSmith\wxSmith.cbp" />
   <Project filename="src\plugins\contrib\wxSmithContribItems\wxSmithContribItems.cbp" />
   <Project filename="src\plugins\contrib\wxSmithAui\wxSmithAui.cbp" />
   <Project filename="src\plugins\contrib\lib_finder\lib_finder.cbp" />
   <Project filename="src\plugins\contrib\HexEditor\HexEditor-win.cbp" />
   <Project filename="src\tools\cb_share_config\cb_share_config.cbp" />
   <Project filename="src\plugins\contrib\IncrementalSearch\IncrementalSearch.cbp" />
   <Project filename="src\plugins\contrib\MouseSap\MouseSap.cbp" />
 </Workspace>
</CodeBlocks_workspace_file>


We will use this workspace to build all of Code::Blocks.

Building Code::Blocks

Finally we have arrived at the final step; our final goal. Run the Code::Blocks executable from your nightly build download. Choose Open from the File menu and browse for our above created workspace, and open it up. Be a little patient while Code::Blocks is parsing everything, and Code::Blocks will ask us for 2 global variables, these global variables will tell the nightly Code::Blocks where it can find wxWidgets (remember : header files and import libraries) and where it can find .... Code::Blocks, this is needed for the contrib plug-ins, they need to know (as for any user created plug-in) where the sdk (Code::Blocks header files) are. These are the values in our case :

- wx : <wxDir>
- Code::Blocks (cb) : <cbDir>\src

Now go to the Project Menu and choose (re)build workspace, and off you go. Watch how Code::Blocks is building Code::Blocks.

Once the build is complete, open up a console in <cbDir>\src and run the command "update.bat". This will transfer all built deliverables from <cbDir>\src\devel to <cbDir>\src\output. In addition, it will strip out all debugging symbols. This step is very important - never ever forget it.

Now you can copy the wx dll in both that output and the devel directory.

Then you can close Code::Blocks. That was the downloaded nightly remember?

Time to test it. In the output directory, start up the CodeBlocks.exe. If everything went well, you'll have your very own home-built Code::Blocks running.

Enjoy !!!