tn0016.txt 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. How to add new files and libraries to wxWidgets build system
  2. ============================================================
  3. 1. Regenerating makefiles
  4. -------------------------
  5. wxWidgets now uses Bakefile (http://bakefile.sourceforge.net) to generate
  6. native makefiles. You must have bakefile installed if you want to regenerate
  7. the makefiles. Bakefile currently runs on Unix and Windows systems. You will
  8. need Python >= 2.2 installed on Unix and either use Bakefile installer or have
  9. Python on Windows.
  10. Once you have installed Bakefile, you can easily regenerate the makefiles using
  11. the bakefile_gen tool. Run it from $(wx)/build/bakefiles directory and it will
  12. regenerate all outdated makefiles. See $(wx)/build/bakefiles/README for more
  13. details.
  14. Note that it generates makefiles for samples, too.
  15. IMPORTANT NOTE: Don't forget to run autoconf in wxWidgets root directory
  16. (after running Bakefile) if you changed any conditional
  17. variable or target condition in .bkl files! You will know that
  18. this happened if $(wx)/autoconf_inc.m4 content changed.
  19. You can use Bakefile to generate makefiles or projects customized to your
  20. needs, too. See Bakefiles.bkgen for details on bakefile commands used to
  21. generate makefiles. For example, you can use this command to generate
  22. VC++ project files without wxUniversal configurations:
  23. bakefile -v -fmsvc6prj -o../wxmy.dsw -DRUNTIME_LIBS=dynamic
  24. -DDEBUG_INFO=default -DDEBUG_FLAG=default
  25. -DOFFICIAL_BUILD=0 -DUSE_HTML=1 -DUSE_OPENGL=1
  26. -DMONOLITHIC=0 -DUSE_GUI=1 -DWXUNIV=0 wx.bkl
  27. Or monolithic instead of multilib (the default):
  28. bakefile -v -fmsvc6prj -o../wxmono.dsw -DRUNTIME_LIBS=dynamic
  29. -DDEBUG_INFO=default -DDEBUG_FLAG=default
  30. -DOFFICIAL_BUILD=0 -DUSE_HTML=1 -DUSE_OPENGL=1
  31. -DMONOLITHIC=1 -DUSE_GUI=1 wx.bkl
  32. Or monolithic wxBase:
  33. bakefile -v -fmsvc6prj -o../wxBase.dsw -DRUNTIME_LIBS=dynamic
  34. -DDEBUG_INFO=default -DDEBUG_FLAG=default
  35. -DOFFICIAL_BUILD=0 -DUSE_HTML=0 -DUSE_OPENGL=0
  36. -DMONOLITHIC=1 -DUSE_GUI=0 wx.bkl
  37. It is, however, recommended to modify Bakefiles.bkgen (or
  38. Bakefiles.local.bkgen) by means of <add-flags> and <del-flags> directives
  39. and use bakefile_gen instead of running bakefile directly.
  40. 2. Bakefile files organization
  41. ------------------------------
  42. Makefile are generated from .bkl files ("bakefiles") from two places:
  43. - $(wx)/build/bakefiles directory
  44. - samples directories
  45. $(wx)/build/bakefiles contains bakefiles for main library and support files
  46. that simplify writing bakefiles for samples.
  47. Support files are:
  48. wxwin.py - helper functions
  49. common.bkl
  50. common_samples.bkl
  51. config.bkl - user-configurable build options
  52. make_dist.mk - implementation of "make dist" on Unix
  53. Files used to build the library are:
  54. wx.bkl - main file
  55. files.bkl - lists of source files
  56. monolithic.bkl - targets for wxWin built as single big library
  57. multilib.bkl - targets for multilib build
  58. opengl.bkl - GL library with wxGLCanvas (this one is not
  59. included in monolithic library for historical
  60. reasons, so "monolithic" really means "two libs")
  61. {expat,jpeg,png,tiff,
  62. regex,zlib,odbc}.bkl - 3rd party libraries makefiles
  63. 3. Adding files to existing library
  64. -----------------------------------
  65. All files used by main libraries are listed in files.bkl. The file is
  66. organized into variables for toolkits, platforms and libraries. The variables
  67. come in pairs: there's always FOO_SRC for source files and FOO_HDR for header
  68. files. Platform or toolkit specific files are grouped together in variable
  69. with platform or toolkit name in them, e.g. BASE_WIN32_SRC, BASE_UNIX_SRC,
  70. GTK_SRC, MOTIF_SRC.
  71. Note: A side effect of this toolkit-centric organization is that one file may
  72. be present several times in files.bkl in different contexts.
  73. When you are adding a file, you must put it into appropriate variable. This is
  74. easy if you are adding the file to library that is always built from same
  75. sources on all platforms (e.g. wxXml or wxXML) -- simply add the file to e.g.
  76. HTML_SRC or HTML_HDR.
  77. If the file is used only on one platform and is part of wxBase, add it to
  78. BASE_{platform}_SRC/HDR. If it is used on all platforms, add it to BASE_CMN.
  79. If it is built on more than one platform but not on all of them, add the file
  80. to *all platforms that use it*!
  81. If a file is not wxBase file, but GUI file, then the variables are named after
  82. toolkits/ports, not platforms. Same rules as for wxBase files apply
  83. (substitute "platform" with "toolkit"). Make sure you correctly choose between
  84. {port}_LOWLEVEL_SRC and {port}_SRC -- the former is for files used by
  85. wxUniversal, e.g. GDI classes. Files shared by all X Window System ports
  86. should be put into XWIN_LOWLEVEL_SRC.
  87. 4. Adding sample
  88. ----------------
  89. Copy the bakefile from another sample, change the ID and files accordingly.
  90. If the sample uses some data files, make sure to have <wx-data> node
  91. in the sample's bakefile (see e.g. samples/image/image.bkl for an example).
  92. Make sure to add <wx-lib> statements for all libraries from multilib build
  93. that are required by the sample.
  94. The Windows resource specification should use the central .rc file:
  95. <win32-res>../sample.rc</win32-res>
  96. Run bakefile_gen in $(wx)/build/bakefiles to regenerate the bakefiles.
  97. Finally commit $(wx)/build/bakefiles/make_dist.mk and all the other modified files.
  98. Currently we commit the generated makefiles except .dms, .vcp.
  99. 5. Adding new core library
  100. --------------------------
  101. When adding new library to the core set of libraries, the files must be
  102. added to both a newly added library in multilib build and into the single
  103. library built in monolithic mode. We will assume that the new library is
  104. called wxFoo.
  105. a) Add files to files.bkl:
  106. * If wxFoo builds from same files on all platforms (e.g. wxNet),
  107. add FOO_SRC and FOO_HDR variables with lists of sources and headers.
  108. * If wxFoo have no files in common (e.g. wxGL), add FOO_SRC and FOO_HDR
  109. with toolkit or platform conditions. Have a look at OPENGL_SRC for an
  110. example.
  111. * Otherwise add FOO_CMN_SRC and FOO_CMN_HDR for common files and
  112. FOO_{platform}_{SRC,HDR} or FOO_{toolkit}_{SRC,HDR} as appropriate. Add
  113. FOO_PLATFORM_{SRC,HDR} into "Define sources for specific libraries"
  114. section that is conditionally set to one of FOO_xxx_{SRC,HDR} based on
  115. target platform/toolkit (see NET_PLATFORM_SRC definition for an example).
  116. Finally, define FOO_SRC and FOO_HDR to contain both
  117. FOO_PLATFORM_{SRC,HDR} and FOO_{SRC,HDR} (see NET_SRC definition for an
  118. example).
  119. * Add FOO_HDR to ALL_GUI_HEADERS or ALL_BASE_HEADERS.
  120. * If wxFoo is wxBase library (doesn't use GUI), add FOO_SRC to
  121. ALL_BASE_SOURCES.
  122. (You can apply different approaches to HDR and SRC variables, if e.g.
  123. headers are all common but sources are not.)
  124. Note that the conditions can only test for equality, due to limitations of
  125. native make tools.
  126. b) Modify bakefile system in build/bakefiles/ to recognize wxFoo:
  127. * Add 'foo' to MAIN_LIBS and LIBS_NOGUI or LIBS_GUI (depending on whether
  128. the library depends on wxCore or not) to wxwin.py file.
  129. * Add extra libraries needed by wxFoo (if any) to EXTRALIBS in wxwin.py
  130. * Add WXLIB_FOO definition to common.bkl (into the "Names of component
  131. libraries" section). It looks like this:
  132. <set var="WXLIB_FOO">
  133. <if cond="MONOLITHIC=='0'">$(mk.evalExpr(wxwin.mkLibName('foo')))</if>
  134. </set>
  135. c) Modify monolithic.bkl to add files to monolithic build: it's enough to add
  136. FOO_SRC to MONOLIB_GUI_SRC or MONOLIB_SRC, depending on whether wxFoo uses
  137. GUI or not.
  138. d) Modify multilib.bkl to add files to multilib build: add foolib and foodll
  139. targets. Don't use wxBase targets as the template, use e.g. wxXML or wxHTML.
  140. Make sure WXMAKINGDLL_FOO is defined in foodll.
  141. e) Regenerate all makefiles (don't forget to run autoconf)
  142. f) Update configure.in and wx-config.in to contain information about
  143. the library and needed linker flags:
  144. * Add "foo" to either STD_BASE_LIBS or STD_GUI_LIBS in configure.in.
  145. * If wxFoo links against additional libraries, add necessary linker
  146. flags and libraries to ldflags_foo and ldlibs_foo variables in
  147. wx-config.in (both are optional).
  148. g) Update dlimpexp.h to define WXMAKINGDLL_FOO if WXMAKINGDLL is defined (add
  149. #define WXMAKINGDLL_FOO inside first "#ifdef WXMAKINGDLL" block in
  150. dlimpexp.h) and to define WXDLLIMPEXP_FOO and WXDLLIMPEXP_DATA_FOO. You
  151. can copy e.g. WXDLLIMPEXP_NET definition, it is something like this:
  152. #ifdef WXMAKINGDLL_NET
  153. #define WXDLLIMPEXP_NET WXEXPORT
  154. #define WXDLLIMPEXP_DATA_NET(type) WXEXPORT type
  155. #elif defined(WXUSINGDLL)
  156. #define WXDLLIMPEXP_NET WXIMPORT
  157. #define WXDLLIMPEXP_DATA_NET(type) WXIMPORT type
  158. #else // not making nor using DLL
  159. #define WXDLLIMPEXP_NET
  160. #define WXDLLIMPEXP_DATA_NET(type) type
  161. #endif
  162. Don't forget to add WXDLLIMPEXP_FWD_FOO definitions too.
  163. Use WXDLLIMPEXP_FOO when declaring wxFoo classes and functions.
  164. h) Add this code to one of wxFoo's files (the more often used, the better):
  165. // DLL options compatibility check:
  166. #include "wx/app.h"
  167. WX_CHECK_BUILD_OPTIONS("wxFoo")
  168. i) Add information about wxFoo to the manual ("Libraries list" section
  169. in libs.tex) and update docs/latex/wx/libs.dia (you need Dia for this)
  170. to show the dependencies of the new library.
  171. j) Also please add 4 #pragma comment(lib, "foo") (for Unicode/ANSI
  172. Release/Debug combinations) to the file include/msvc/wx/setup.h and
  173. add a check for WXMAKINGDLL_FOO to the test whether we're building a DLL at
  174. the end of include/wx/msw/chkconf.h.
  175. === EOF ===