home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / bakev100.zip / bake.doc next >
Text File  |  1995-05-22  |  16KB  |  360 lines

  1. Bake V1.0 docs, by Rob Landley.
  2.  
  3. 1) What is bake
  4. 2) How to use bake
  5. 3) The bake file "target" line
  6. 4) Bake file "source" lines.
  7. 5) Command line arguments to bake
  8. 6) Extra compiler arguments
  9. 5) bakefile.1 and bakefile.2
  10.  
  11. ******************************* What is Bake? *****************************
  12.  
  13. Bake is a project manager utility for quickly and easily compiling large,
  14. multi-file C/C++ programs with the EMX port of GCC under OS/2. The old way
  15. to do this was to use "Make" files, which were incredibly complex and a lot
  16. of work to maintain.
  17.  
  18. With bake, you make a very simple data file to tell it what to do, and
  19. it does all the work for you.  You don't have to learn the command line
  20. arguments to gcc, emxomfar, ar, rc, or any of the files bake shells to.
  21. You also don't have to list the dependencies in your C++ and Resource
  22. files, bake will look through the files and figure them out, recursively
  23. checking the headers for more included files when necessary.
  24.  
  25. The name "bake" is derived from "better make".  It also describes a
  26. process of combining ingredients and performing a strange ritual on them
  27. whereby you come up with a finished product, which seemed appropriate.
  28.  
  29. When learning how to use bake, the following rule of thumb may come in
  30. handy:  "If I don't understand something becuase I haven't learned about
  31. that yet (like .dll files or unix emulation), I'm probably not going to
  32. be using it yet, so don't worry about it."
  33.  
  34. This file won't teach you how to write OS/2 programs, just how to compile
  35. them easily via the EMX package.  I may write a text file on "How to
  36. program for OS/2 with the EMX package" if I get time, but I haven't yet.
  37.  
  38. *************************** How do I use bake? ****************************
  39.  
  40. For each project, you will need to create a text file to tell bake what to
  41. do.  The default name for this file is "bakefile", and there are only two
  42. types of lines in a bake file.  The first non-blank line is the "target"
  43. line, which tells bake what file it's creating.  The rest are "source" lines
  44. which tell it what files the to make the target out of.  Each file will be
  45. recognized by its extension, and processed accordingly.  Everything
  46. after a semicolon is ignored as a comment.
  47.  
  48. The following is a sample "bakefile":
  49.  
  50.    filename.exe      ; The target line  (32 bit native OS/2 executable)
  51.    file1.cc          ; The first source file
  52.    file2.cc          ; The second source file
  53.    file3.cc          ; The third source file
  54.  
  55. The following is a more complex sample "bakefile":
  56.  
  57.    compress.dll      ; This time the target is a ".dll" file.
  58.    compress.def      ; The module definition file (mandatory for ".dll"s)
  59.    toolkit.def       ; Another ".def" file (perhaps using another .dll)
  60.    compress.rc       ; The resource file (it's accessing the PM.)
  61.    main.cc           ; Some actual source code.
  62.    archive.cc        ; More C++ source code.
  63.    ..\huffman.obj    ; A pre-compiled .obj file.
  64.    dirtree.cxx       ; This is also a C++ file.
  65.    bsd.lib           ; Link with this library.
  66.  
  67. To use a bake file, type "bake" and press enter.  "bake.exe" must either be
  68. in your path somewhere, or in the current directory.
  69.  
  70. ********************** The bake file "target" line. **********************
  71.  
  72. The very first line of a bake file is the "target" line, which tells bake
  73. the name of the file it's trying to create.  The file name of the target
  74. file must end in one of the following extensions:
  75.  
  76.   OS/2 extensions:
  77.  
  78.   ".exe" : Bake a 32 bit native OS/2 executable.
  79.   ".lib" : Bake a 32 bit native OS/2 static library.
  80.   ".dll" : Bake a 32 bit native OS/2 dynamic link library.
  81.  
  82.   Unix emulation (via EMX) extensions:
  83.  
  84.   ".emx" : Bake a full Unix emulation executable.
  85.   ".a"   : Bake a unix static library file.
  86.   ".em2" : Bake a hybrid Unix & OS/2 executable.
  87.  
  88.  
  89. The ".emx" and ".em2" extension will actually create files with the
  90. extension ".exe", but they will require access to the EMX unix emulator
  91. to run.
  92.  
  93. Full Unix emulation executables are actually Unix executables, which call
  94. the Unix emulator "EMX.EXE" to run under DOS and "emx.dll" to run under
  95. OS/2.  These executables are compiled via Unix style ".o" object files
  96. and Unix style ".a" static library files.  Only this executable format
  97. uses those two types of files.  Full unix emulation produces big, slow
  98. executables, but they are extremely unix compatible (even producing core
  99. dump files after a crash), and can run under dos as well as OS/2.
  100.  
  101. Hybrid executables (which also end in the extension ".exe") contain some
  102. Unix code and some OS/2 code.  Because of this, they are smaller and
  103. faster than fully emulated executables, but can only be run under OS/2.
  104. Hybrid executables are still highly compatible with Unix, and require the
  105. Unix emulator "emx.dll" to run.  Hybrid executables use OS/2 style ".lib"
  106. and ".obj" files.
  107.  
  108. The target file can have a path, if necessary.  Bake doesn't care as
  109. long as it recognizes the extension and can open or create the file.
  110.  
  111. ************************ Bake file "Source" lines ************************
  112.  
  113. The rest of the lines in a bake file name one source file each.  These
  114. files will be compiled and linked as efficiently as possible to create the
  115. target file named on the first line.
  116.  
  117. Source files must have one of the following extensions:
  118.  
  119.   Source code files:
  120.  
  121.   ".cc"  : C++ source code
  122.   ".cxx" : C++ source code
  123.   ".cpp" : C++ source code
  124.   ".C"   : C++ source code    (capital C)
  125.   ".c"   : ANSI C source code (lower case C)
  126.  
  127.   Optional files:
  128.  
  129.   ".def" : Module definition file.
  130.   ".rc"  : Resource file.
  131.   ".res" : Pre-compiled binary resource file.
  132.   ".obj" : Pre-compiled OS/2 object module.
  133.   ".lib" : OS/2 static library.
  134.  
  135.   Full unix emulation only:
  136.  
  137.   ".o"   : Pre-compiled Unix style object file.
  138.   ".a"   : Unix style static library.
  139.  
  140. Each source code file will be compiled to create an object module file. If
  141. the corresponding object file already exists, the date of the file will be
  142. compared with the date of the source file, and (recursively) the header
  143. files included from the source file.  Only header files included with quotes
  144. (#include "file.h";) will be tested.  The library header files included with
  145. "#include <file.h>;" will not be tested.  If the object file is newer than
  146. all of the files it was created from, it will not need to be re-compiled.
  147.  
  148. If a source code file listed has a path, such as "..\common\file.cxx",
  149. the object module created/tested against will be in the same directory as
  150. the source file.  All files without a path will be expected to be in the
  151. same directory as the Bake file (except ".lib" files, which have their
  152. own search path defined in the environment variable "LIBRARY_PATH").
  153.  
  154. --- Module definition files in "source" lines:
  155.  
  156. Module definition files are required for creating Dynamically Linked
  157. Libraries (.DLL files), load-time linking with .DLL files, and creating
  158. Presentation Manager programs.  For text mode apps, module definition files
  159. are optional, although they do allow you to declare a larger stack than the
  160. default.  (A stack size of at least 32768 bytes is needed for any PM
  161. program.)  Module definition files are only used during the linking phase.
  162.  
  163. --- Resource files in "source" lines:
  164.  
  165. Resource files ("*.rc") will be compiled to binary format ("*.res") if
  166. the currently existing .res file is older than the .rc file itself, or
  167. older than any file #included (or rcincluded, or an icon file) from the
  168. .rc file.
  169.  
  170. You cannot list two resource files in the same bake file.  You must use
  171. the rcinclude statement in the resource file instead.
  172.  
  173. --- Object modules in "source" lines:
  174.  
  175. If a "source" line of a bake file actually names an object file (with the
  176. extension ".obj" or ".o"), the module cannot be recompiled, but will be
  177. linked into the target file.  It is best to only directly list object
  178. modules you do not have the source code to.  Otherwise just name the
  179. source code file, and if it doesn't need to be recompiled, it won't be.
  180.  
  181. --- Library files in "source" files:
  182.  
  183. Your program will be linked with any optional libraries given in the bake
  184. file (with the extension ".lib" or ".a").  These libraries will be checked
  185. in the order they appear in the bake file.  You do not have to mention
  186. the default libraries in the bake file, they are assumed.
  187.  
  188. If the target is a library, and you have another library as a source file,
  189. the entire second library will be included in the target.
  190.  
  191. Dynamic Link Libraries (".dll" files) do not need to be listed in the
  192. bake file.  If you want to link them at load time you must include
  193. a module definition file (".def") or static import library (".lib") for
  194. each one.  Run time .dll linking is handled manually by the C/C++ source
  195. code, not by bake.
  196.  
  197. An interesting library supplied with the EMX package is "wrap.lib", which
  198. is the static import library for the ".dll" version of the OS/2 API call
  199. library.  If you link with this library, your program will use the .dll
  200. version of the OS/2 API call library, reducing the .exe size at the expense
  201. of requiring an extra file at run time.  This is not recommended for ".emx"
  202. type executables.
  203.  
  204. --- Linking:
  205.  
  206. Once all the files that need to be recompiled have been, Bake will link
  207. them to form the target file.  If an existing target file is newer than
  208. all the component files it was created from, it will not need to be
  209. re-linked.
  210.  
  211. ************** Command line arguments to Bake (optional): ****************
  212.  
  213. You can probably safely ignore all of these.
  214.  
  215. Bake takes two command line arguments, both of which are optional:
  216.  
  217. -- The first argument
  218.  
  219. The first argument to bake is the the name of the bake file.  If you
  220. have a bake file called "herbert", type "bake herbert" and it'll use
  221. that file instead to compile your program.  If you run bake.exe with no
  222. arguments, it will look for a file (in the current directory) named
  223. "bakefile".
  224.  
  225. The default directory bake uses during compilation is the directory the
  226. bake file is in.  If you give it path to the bake file on the command line,
  227. bake will change to that directory, do its stuff, and then change back to
  228. the origional directory before exiting.  In other words, relative paths
  229. for source and target files, such as "..\file.cc", will be interpreted as
  230. starting from the directory the bake file resides in, not from the directory
  231. bake itself was run in.
  232.  
  233. -- The second argument:
  234.  
  235. The second argument to bake is a group of letters which select various
  236. optional features.  These letters are Q,V, and A.
  237.  
  238. Q)  Quiet mode.
  239.     Don't output anything that isn't an error message.
  240.  
  241. V)  Verbose mode.
  242.     Display lots of useless details about what bake is doing.
  243.  
  244. A)  Recompile all files.
  245.     Rebuild entire from scratch, ignoring all existing intermediate files.
  246.     This usually takes a lot longer than a normal run of bake, but may
  247.     be necessary if extra compiler arguments have been added to the bake
  248.     file.
  249.  
  250. C)  Clean up intermediate files.
  251.     Delete all .obj files and .res files created by bake.  Use this only
  252.     if you don't intend to recompile the project again any time soon, or
  253.     if you're really short of hard drive space.  If "C" appears more than
  254.     once in the options, (I.E. "bake filename cc",) no new compiling will
  255.     be done.  Otherwise bake will attempt to re-create the current project,
  256.     if it needs it, before deleting the temp files.
  257.  
  258.  
  259. Example:  bake ..\project1 acv
  260.  
  261. That would use "project1" as the bake file, to be found in the directory
  262. above the one bake was run in.  It also tells bake to re-compile all files
  263. from scratch, to delete all the intermediate files after it finishes,
  264. and to display verbose output.
  265.  
  266. ****************** Extra compiler arguments (optional) *******************
  267.  
  268. Bake automatically supplies most of the command line arguments GCC needs.
  269. You can also supply additional arguments to the compiler by putting them
  270. into the bake file.  Extra compiler arguments go after the file name on
  271. a given bake file line.
  272.  
  273. Arguments that go on the target line (the one that names the file to create)
  274. will take effect globally.  They will be supplied to the compiler for every
  275. source file in the project, and will also be supplied to the linker.  A
  276. few that might come in handy are:
  277.  
  278.   "-Zmt"     : Multi-threaded code (can use C runtime library functions)
  279.   "-Zcrtdll" : Use the ".dll" version of the C runtime library (".emx" and
  280.                ".em2" type executables only, not currently implemented for
  281.                OS/2 native executables.  That's an EMX package limitation.)
  282.   "-Zso"     : Make a ".dll" file "Stand Alone", with its own run-time
  283.                environment.
  284.  
  285. Arguments that go after a source file will be supplied only when that one
  286. file is being compiled.
  287.  
  288. Example:
  289.  
  290.   myfile.exe -Zcrtdll -Zmt
  291.   file1.cc
  292.   file2.cc -mprobe
  293.   file3.cc
  294.   file4.cc
  295.  
  296. GCC is to compile all four of the .cc files as multi-threaded code, and
  297. use the multi-threaded ".dll" version of the C runtime library.
  298.  
  299. Only file2.cc will generate "stack probes", which are extremely technical
  300. and have to do with allocating stack space properly under unusual conditions.
  301. Don't worry about it, it's just an example.
  302.  
  303. --- Default command lines arguments:
  304.  
  305. The following are approximately the default command line arguments for the
  306. various compilation modes (where * is a list of files of the type given).
  307.  
  308. You can safely ignore all of this:
  309.  
  310. ".exe"
  311. Compile: gcc -pipe -O2 -Zomf -c *.cc
  312. Link   : gcc -pipe -s -o target.exe -Zsys -Zomf *.obj *.res *.def -l*.lib
  313.  
  314. ".dll"
  315. Compile: gcc -pipe -O2 -Zomf -c *.cc
  316. Link   : gcc -pipe -s -o target.dll -Zdll -Zsys -Zomf *.obj *.res *.def -l*.lib
  317.  
  318. ".lib"
  319. Compile: gcc -pipe -O2 -Zomf -c *.cc
  320. Link   : del target.lib;emxomfar r target.lib *.obj
  321.  
  322. ".emx"
  323. Compile: gcc -pipe -O2 -c *.cc
  324. Link   : gcc -pipe -s -o target.exe *.obj *.res *.def -l*.lib
  325.  
  326. ".a"
  327. Compile: gcc -pipe -O2 -I. -DOS2 -c *.cc
  328. Link   : del target.lib;ar rs target.lib
  329.  
  330. ".em2"
  331. Compile: gcc -pipe -O2 -Zomf -c *.cc
  332. Link   : gcc -pipe -s -o target.exe -Zomf *.obj *.res *.def -l*.lib
  333.  
  334. **************************** bakefile.sam *******************************
  335.  
  336. Bake is compiled in "em2" mode (OS/2 optimized unix emulation) with the
  337. -Zcrtdll option (it uses the .dll version of the C runtime library), and
  338. linked with "wrap.lib" (the export library for the .dll version of the
  339. OS/2 API calls.)  This produces the smallest possible executables, but
  340. requires access to several .dll files (emx.dll, emxlibcs.dll, and
  341. emxwrap.dll).  All of these files are available in the EMX runtime package.
  342.  
  343. The actual bakefile used to compile bake.exe is provided as a sample
  344. (bakefile.1) as well as a variant used to compile an OS/2 native version
  345. that requires no .dll files (not distributed, just tested).  Look at them,
  346. make your own, and try it out.  There's really not much more to explain.
  347.  
  348. ************************* Contacting the Author **************************
  349.  
  350. My name is Rob Landley, and if you leave a message to me on the fidonet OS2
  351. echo, I'll probably get it.  My fidonet and internet email addresses are
  352. about to change, because I'm moving.  The old internet address was
  353. "landley@clam.rutgers.edu", but who knows how long they'll hold that now
  354. that I've graduated.  The next version of bake (of COURSE there will be
  355. bugs!) should have new email addresses I can be contacted at.
  356.  
  357. Have fun programming for OS/2 with EMX.
  358.  
  359. Rob
  360.