Nightly Cookbook

From CodeBlocks
Jump to: navigation, search

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 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 !!!