bakefile_quickstart.txt 12 KB

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