]> git.saurik.com Git - wxWidgets.git/blame - build/bakefiles/wxpresets/bakefile_quickstart.txt
Use $(OutDir) instead of explicit directories in VC10 project files.
[wxWidgets.git] / build / bakefiles / wxpresets / bakefile_quickstart.txt
CommitLineData
e66439e3
KO
1-----------------------------------------------------------------------
2Creating a Cross-Platform Build System Using Bakefile
3The 10-minute, do-it-yourself wx project baking guide (with free sample recipes!)
4
5Status: DRAFT
6Author: Kevin Ollivier
7Date: 2/13/04
526954c5 8Licence: wxWindows Licence
e66439e3
KO
9-----------------------------------------------------------------------
10
72c1ea91
VS
11Supporting many different platforms can be a difficult challenge. The
12challenge for wxWidgets is especially great, because it supports a variety of
13different compilers and development environments, including MSVC, Borland C++,
14MinGW, DevCPP, GNU make/automake, among others. Maintaining such a large
15number of different project files and formats can quickly become overwhelming.
16To simplify the maintenance of these formats, one of the wxWidgets developers,
17Vaclav Slavik, created Bakefile, a XML-based makefile wrapper that generates
18all the native project files for wxWidgets. So now, even though wxWidgets
19supports all these formats, wxWidgets developers need only update one file -
20the Bakefile, and it handles the rest. But Bakefile isn't specific to
21wxWidgets in any way - you can use Bakefile for your own projects, too. This
0d61c167 22brief tutorial will take a look at how to do that.
72c1ea91
VS
23
24Note that this tutorial assumes that you are familiar with how to build
25software using one of the supported Bakefile makefile systems, that you have
26some basic familiarity with how makefiles work, and that you are capable of
27setting environment variables on your platform. Also note that the terms Unix
28and Unix-based refers to all operating systems that share a Unix heritage,
29including FreeBSD, Linux, Mac OS X, and various other operating systems.
e66439e3
KO
30
31-- Getting Started --
32
72c1ea91 33First, you'll need to install Bakefile. You can always find the latest version
0d61c167 34for download online at http://www.bakefile.org. A binary installer is provided
72c1ea91 35for Windows users, while users of Unix-based operating systems (OS) will need
0d61c167
VZ
36to unpack the tarball and run configure && make && make install. (binary
37packages for some Linux distributions are also available, check
38http://www.bakefile.org/download.html for details).
e66439e3
KO
39
40-- Setting Up Your wx Build Environment --
41
72c1ea91
VS
42Before you can build wxWidgets software using Bakefile or any other build
43system, you need to make sure that wxWidgets is built and that wxWidgets
44projects can find the wxWidgets includes and library files. wxWidgets build
45instructions can be found by going to the docs subfolder, then looking for the
46subfolder that corresponds to your platform (i.e. msw, gtk, mac) and reading
47"install.txt" there. Once you've done that, here are some extra steps you
48should take to make sure your Bakefile projects work with wxWidgets:
e66439e3
KO
49
50On Windows
51----------
72c1ea91
VS
52Once you've built wxWidgets, you should create an environment variable named
53WXWIN and set it to the home folder of your wxWidgets source tree. (If you use
54the command line to build, you can also set or override WXWIN at build time by
55passing it in as an option to your makefile.)
e66439e3
KO
56
57On Unix
58-------
72c1ea91
VS
59In a standard install, you need not do anything so long as wx-config is on
60your PATH. wx-config is all you need. (See the section of the book on using
61wx-config for more information.)
e66439e3
KO
62
63-- A Sample wx Project Bakefile --
64
72c1ea91
VS
65Now that everything is setup, it's time to take Bakefile for a test run. I
66recommend that you use the wx sample Bakefile to get you started. It can be
67found in the 'build/bakefiles/wxpresets/sample' directory in the wxWidgets
68source tree. Here is the minimal.bkl Bakefile used in the sample:
e66439e3
KO
69
70minimal.bkl
71-------------------------------------------------------------
72<?xml version="1.0" ?>
e66439e3
KO
73
74<makefile>
75
76 <include file="presets/wx.bkl"/>
77
92a93d46 78 <exe id="minimal" template="wxgui">
e66439e3
KO
79 <debug-info>on</debug-info>
80 <runtime-libs>dynamic</runtime-libs>
0d61c167 81
e66439e3 82 <sources>minimal.cpp</sources>
0d61c167 83
e66439e3
KO
84 <wx-lib>core</wx-lib>
85 <wx-lib>base</wx-lib>
86 </exe>
87
88</makefile>
89---------------------------------------------------------------
90
72c1ea91 91It's a complete sample ready to be baked, so go into the directory mentioned
0d61c167 92above and run the following command:
e66439e3
KO
93
94On Windows:
95bakefile -f msvc -I.. minimal.bkl
96
97On Unix:
98bakefile -f gnu -I.. minimal.bkl
99
72c1ea91
VS
100It should generate a makefile (makefile.vc or GNUmakefile, respectively) which
101you can use to build the software. Just build the software using the command
102"nmake -f makefile.vc" or "make -f GNUmakefile" respectively. Now let's take a
103look at some of the basic Bakefile concepts that you'll need to know to move
104on from here.
e66439e3
KO
105
106-- Project Types --
107
a70abf19 108As mentioned earlier, Bakefile builds makefiles for many different
72c1ea91
VS
109development environments. The -f option accepts a list of formats that you
110would like to build, separated by commas. Valid values are:
e66439e3
KO
111
112 autoconf GNU autoconf Makefile.in files
113 borland Borland C/C++ makefiles
e66439e3
KO
114 dmars Digital Mars makefiles
115 dmars_smake Digital Mars makefiles for SMAKE
116 gnu GNU toolchain makefiles (Unix)
117 mingw MinGW makefiles (mingw32-make)
118 msevc4prj MS eMbedded Visual C++ 4 project files
119 msvc MS Visual C++ nmake makefiles
120 msvc6prj MS Visual C++ 6.0 project files
121 watcom OpenWatcom makefiles
122
123TIP: autoconf Project Type
124---------------------------
72c1ea91
VS
125You may notice that in the sample folder, there is also a file called
126configure.in. That file is the input for autoconf, which creates the configure
127scripts that you often see when you build software from source on Unix-based
128platforms. People use configure scripts because they make your Unix makefiles
129more portable by automatically detecting the right libraries and commands to
130use on the user's machine and OS. This is necessary because there are many
131Unix-based operating systems and they all are slightly different in various
132small ways.
133
134Bakefile does not generate a configure or configure.in script, so if you want
135to use configure scripts with your Unix-based software, you will need to learn
136how to use autoconf. Unfortunately, this topic deserves a book all its own and
137is beyond the scope of this tutorial, but a book on the subject can be found
138online at: http://sources.redhat.com/autobook/. Note that you do not need to
139use automake when you are using Bakefile, just autoconf, as Bakefile
0d61c167 140essentially does the same thing as automake.
e66439e3
KO
141----------------------------
142
143-- Targets --
144
72c1ea91
VS
145Every project needs to have a target or targets, specifying what is to be
146built. In Bakefile, you specify the target by creating a tag named with the
147target type. The possible names for targets are:
e66439e3 148
72c1ea91 149 exe create an executable file
3103e8a9 150 dll create a shared library
72c1ea91
VS
151 lib create a static library
152 module create a library that is loaded at runtime (i.e. a plugin)
e66439e3 153
72c1ea91
VS
154Note the sample above is an "exe" target. Once you create the target, all the
155build settings, including flags and linker options, should be placed inside
156the target tag, as they are in the sample above.
e66439e3
KO
157
158-- Adding Sources and Includes --
159
72c1ea91
VS
160Obviously, you need to be able to add source and include files to your
161project. You add sources using the "<sources>" tag (as shown above), and add
162include directories using the "<include>" tag. You can add multiple <sources>
163and <include> tags to add multiple source files, or you can also add multiple
164sources and includes into one tag by separating them with a space, like so:
e66439e3
KO
165
166<sources>minimal.cpp minimal2.cpp minimal3.cpp</sources>
167
72c1ea91
VS
168If your sources are in a subfolder of your Bakefile, you use the slash "/"
169character to denote directories, even on Windows. (i.e. src/minimal.cpp) For
170more options and flags, please consult the Bakefile documentation in the 'doc'
171subfolder of Bakefile, or you can also find it on the Bakefile web site.
e66439e3
KO
172
173-- Build Options --
174
72c1ea91
VS
175What if you want to offer a DEBUG and a RELEASE build? Or a UNICODE/ANSI
176build? You can do this in Bakefile by creating options. To create an option,
177use the "<option>" tag. A typical option has three important parts: a name, a
178default value, and a comma-separated list of values. For example, here is how
179to create a DEBUG option which builds debug by default:
e66439e3
KO
180
181<option name="DEBUG">
72c1ea91
VS
182 <default-value>1</default-value>
183 <values>0 1</values>
e66439e3
KO
184</option>
185
72c1ea91
VS
186You can then test the value of this option and conditionally set build
187settings, flags, etc. For more information on both options and conditional
188statements, please refer to the Bakefile documentation.
e66439e3
KO
189
190-- Bakefile Presets/Templates and Includes --
191
72c1ea91
VS
192It is common that most projects will reuse certain settings, or options, in
193their makefiles. (i.e. DEBUG or static/dynamic library options) Also, it is
194common to have to use settings from another project; for example, any project
195that uses wxWidgets will need to build using the same flags and options that
196wxWidgets was built with. Bakefile makes these things easier by allowing users
0d61c167 197to create Bakefile templates, where you can store common settings.
72c1ea91
VS
198
199Bakefile ships with a couple of templates, found in the 'presets' subfolder of
200your Bakefile installation. The "simple.bkl" template adds a DEBUG option to
201makefiles so you can build in release or debug mode. To add this template to
202your project, simply add the tag "<include file="presets/simple.bkl"/>" to the
203top of your Bakefile. Then, when creating your target, add the
204"template="simple"" attribute to it. Now, once you build the makefile, your
205users can write commands like:
e66439e3
KO
206
207nmake -f makefile.vc DEBUG=1
208
209or
210
211make -f GNUmakefile DEBUG=1
212
213In order to build the software in debug mode.
214
0d61c167 215To simplify the building of wxWidgets-based projects, wxWidgets contains a
72c1ea91
VS
216set of Bakefiles that automatically configure your build system to be
217compatible with wxWidgets. As you'll notice in the sample above, the sample
92a93d46
VS
218project uses the "wxgui" template. Once you've included the template, your software
219will now build as a GUI application with wxWidgets support.
220
221There's also "wxconsole" template for building console-based wxWidgets applications
222and "wx" template that doesn't specify application type (GUI or console) and can be
223used e.g. for building libraries that use wxWidgets.
e66439e3 224
72c1ea91
VS
225But since the wx presets don't exist in the Bakefile presets subfolder,
226Bakefile needs to know where to find these presets. The "-I" command adds the
0d61c167 227wxpresets folder to Bakefile's search path.
e66439e3 228
72c1ea91
VS
229If you regularly include Bakefile presets in places other than the Bakefile
230presets folder, then you can set the BAKEFILE_PATHS environment variable so
231that Bakefile can find these Bakefiles and include them in your project. This
232way you no longer need to specify the -I flag each time you build.
e66439e3 233
72c1ea91
VS
234Lastly, it's important to note that the Win 32 wx project Bakefiles come with
235some common build options that users can use when building the software. These
0d61c167 236options are:
e66439e3 237
72c1ea91
VS
238 Option Values Description
239 ------ ------ -------------
0d61c167 240 WX_MONOLITHIC 0(default),1 Set this to 1 if you built wx
b41b09e2 241 as a monolithic library
72c1ea91 242 WX_SHARED 0(default),1 Specify static or dynamic wx libs
0d61c167 243 WX_UNICODE 0(default),1 Use ANSI or UNICODE wx libs
72c1ea91
VS
244 WX_DEBUG 0,1(default) Use release or debug wx libs
245 *WX_VERSION 25,26(default) Specify version of wx libs
e66439e3 246
72c1ea91 247*Note: Any version of wx past 2.5 will be allowed here, so 25/26 is not a
0d61c167 248complete list of values.
e66439e3 249
72c1ea91
VS
250These options are not needed under Unix as wx-config can be used to specify
251these options.
e66439e3
KO
252
253-- bakefile_gen - Automated Bakefile Scripts --
254
72c1ea91 255If you have a large project, you can imagine that the calls to Bakefile would
0d61c167 256get more and more complex and unwieldy to manage. For this reason, a script
72c1ea91
VS
257called bakefile_gen was created, which reads in a .bkgen file that provides
258all the commands needed to build all the makefiles your project supports. A
259discussion of how to use bakefile_gen is beyond the scope of this tutorial,
260but it deserves mention because it can be invaluable to large projects.
261Documentation on bakefile_gen can be found in the Bakefile documentation.
e66439e3
KO
262
263-- Conclusion --
264
72c1ea91
VS
265This concludes our basic tutorial of the cross-platform Bakefile build system
266management tool. From here, please be sure to take a good look at the Bakefile
267documentation to see what else it is capable of. Please post questions to the
268bakefile-devel@lists.sourceforge.net list, or if you have questions specific
269to the wx template Bakefile, send an email to wx-users@lists.wxwidgets.org.
e66439e3
KO
270
271Enjoy using Bakefile!