📄 genemake.htm
字号:
<!DOCTYPE HTML PUBLIC "-//SoftQuad Software//DTD HoTMetaL PRO 5.0::19981217::extensions to HTML 4.0//EN" "hmpro5.dtd"> <HTML> <HEAD><meta http-equiv="Content-Language" content="en-nz"><META HTTP-EQUIV="content-type" CONTENT="text/html; charset=windows-1252"> <META NAME="generator" CONTENT="Microsoft FrontPage 5.0"> <meta name="ProgId" content="FrontPage.Editor.Document"><TITLE>Automatic make file generation</TITLE><link rel="stylesheet" type="text/css" href="rbd.css"></HEAD><BODY><H1><a name="Top"></a>Automatic make file generator</H1><p align="left"><i>Version of July, 2001</i></p><ul> <li><a href="#Overview">Overview</a></li> <li><a href="#Details">The details</a> <ul> <li><a href="#Command">The command line</a></li> <li><a href="#Library">Library generation</a></li> <li><a href="#Options">Options</a></li> <li><a href="#Test">Test option</a></li> </ul> </li> <li><a href="#Compiling">Compiling the program</a></li> <li><a href="#Make">Running a make file</a></li> <li><a href="#Compilers">Notes on compilers</a></li> <li><a href="#Files">Files</a></li> <li><a href="ol_doc.htm">To online documentation page</a></li> <li><a href="download.html">To download page</a></li></ul><h2><a name="Overview"></a>Overview</h2><P><I>Make files</I> are used to control the compiling and linking of programs.In particular they detect which files have been changed and so need to berecompiled.</P><P>They are used typically by people who don't have access to an IDE (interactivedevelopment environment), who don't like IDEs or are using an IDE whichrequires the use of a make file.</P><P>Make files are awkward to generate: you need to remember what depends onwhat and what files you need for your program; sometimes you need to enter quite a bit of information. If you use several differentcompilers then each will require a slightly different format.</P><P>The aim of the program described here is to generate make filesautomatically.</P><P>You tell <i>genemake</i> the name of the <i>.cpp</i> file containing the main function; it scans this file for <i>#includes</i> of <i>.h</i> files. These <i>.h</i> files need to have the <i>.cpp</i> files they need listed in comment statements in the format described below. The <i>.h</i> files are scanned for these <i>.cpp</i> files and more <i>.h</i> files and so on until all <i>.h</i> and <i>.cpp</i> files required are identified. Then <i>genemake</i> can generate the appropriate make file. </P><P>For example, the command</P><PRE> genemake -g tmt > tmt_gnu.mak</PRE><P>will work out what files are required to build <I> tmt</I> and generate themake file for compiling under the Gnu g++ compiler. In this case <I>tmt.cpp</I>contains the main program. To actually compile and link <i>tmt</i> you would use</P><pre> gmake -f tmt_gnu.mak</pre><p>where <i>gmake</i> is the version of make used by Gnu.</p><P>Naturally some conventions are required to make all this work.</P><UL><LI>Only c++ files are involved with the header files having type <i>.h</i>and the body files having type <i>.cpp</i>.</LI><LI>The <i>.h</i> header files include statements of the form <PRE> // body file: liststr.cpp // body file: gstring.cpp</PRE>which show which body files are required by that header. </LI><LI>All the header and body files are in the same directory (folder).</LI><LI>Include statements are of the form <PRE> #include "liststr.h"</PRE></LI><LI><i>#if</i> and <i>#endif</i> statements can be ignored in the searchprocess.</LI></UL><h2><a name="Details"></a>The details</h2><h3><a name="Command"></a>The command line</h3><P>Load the <i>genemake</i> and <i>sdiff</i> executables and the preamble files into the directory containing the C++ source files.</P><P>You run <i>genemake</i> from a console window. The command has the form</P><PRE> genemake -options files > file_name</PRE><P>where <i>options</i> is a sequence of option characters and <i>files</i> is a list of <i>target</i> names. <i>file_name</i> is the name of the make file to be generated. By <i>target</i> I mean the name of the executable file (without the<i>.exe</i> extension). This must also be the name of <i>.cpp</i> file containing the main program.</P><P>The files list can also include names like <i>@targets.txt</i>. In this case<i>targets.txt</i> must be a file containing a list of target names with one name per line.</P><h3><a name="Library"></a>Library generation</h3><P>The list of files can also include names of the form <i>library.lfl</i> where<i>library</i> is the name of a library to be generated. In this case <i>library.lfl</i> contains a list of names of <i>.h</i> files, one name per line. Then the make file will generate a library consisting of the compiled versions of the <i>.cpp</i> files required by those <i>.h</i> files and this library will be used for generating the executable files. At present this facility is available only for some compilers.</P><P>If an <i>.lfl</i> file is present, but <i>all</i> the .cpp files required to generate the corresponding library are missing you will get error messages but you will get a make file that assumes that the library is present and up-to-date.</P><h3><a name="Options"></a>Options</h3><P>The options show the compiler for which the make file is being generated.</P><table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber1"> <tr> <td width="40%"><b>Compiler</b></td> <td width="15%"><b>Option</b></td> <td width="30%"><b>Preamble file</b></td> <td width="15%"><b>Libraries OK</b></td> </tr> <tr> <td width="40%">Borland 5.0</td> <td width="15%">-b0</td> <td width="30%">pre_b0.txt</td> <td width="15%">no</td> </tr> <tr> <td width="40%">Borland 5.0, 16 bit</td> <td width="15%">-b0d</td> <td width="30%">pre_b0d.txt</td> <td width="15%">no</td> </tr> <tr> <td width="40%">Borland 5.5</td> <td width="15%">-b5</td> <td width="30%">pre_b5.txt</td> <td width="15%">yes</td> </tr> <tr> <td width="40%">CC</td> <td width="15%">-c</td> <td width="30%">pre_c.txt</td> <td width="15%">yes</td> </tr> <tr> <td width="40%">Gnu g++</td> <td width="15%">-g</td> <td width="30%">pre_g.txt</td> <td width="15%">yes</td> </tr> <tr> <td width="40%">Intel 5.0</td> <td width="15%">-i5</td> <td width="30%">pre_i5.txt</td> <td width="15%">yes</td> </tr> <tr> <td width="40%">Visual C++ 6</td> <td width="15%">-m6</td> <td width="30%">pre_m6.txt</td> <td width="15%">yes</td> </tr> <tr> <td width="40%">Watcom 10</td> <td width="15%">-w0</td> <td width="30%">pre_w0.txt</td> <td width="15%">no</td> </tr> <tr> <td width="40%">Watcom 10, 16 bit</td> <td width="15%">-w0d</td> <td width="30%">pre_w0d.txt</td> <td width="15%">no</td> </tr></table><P></P><p>The preamble file is inserted at the beginning of the make file. This includes the options for the compiler. I have chosen a reasonable set of options, nevertheless you may want to edit these. You may also need to edit the paths given in some of these files.</p><p>The last column in the table shows whether I have included the code for building and linking to a library file.</p><h3><a name="Test"></a>Test option</h3><p>Suppose <i>!</i> is also included in the option list. Then the make file includes the instructions to run each of the programs and send the results to a file with a name of the form <i>target.txx</i>. This is compared with file <i>target.txt</i> and the list of differences output.</p><p>The difference program used is a very simple line by line compare program called <i>sdiff</i>. You can edit the preamble file to use a more advanced difference program.</p><h2><a name="Compiling"></a>Compiling the program</h2><p>You need the files from my <a href="string.htm">string library</a>. Copy the files for genemake and sdiff into the same directory. Use an IDE to compile them. Alternatively use the make files for Gnu g++ and Borland 5.5 which are included in this package. As an example, I generated the Gnu version with the command</p><pre> genemake -g genemake sdiff > gm_gnu.mak</pre><p>Once you have managed to compile it once on some compiler you can use a command of the form</p><pre> genemake -xxx genemake sdiff > gm_xxx.mak</pre><p>to generate a make file where <i>xxx</i> denotes the option appropriate for your compiler.</p><p>The program uses the <i>GString</i> set of classes and so will <i>not</i> compile with older compilers such as the Watcom 10 compilers. It does not compile correctly with the 16 bit version of Borland 5.0.</p><h2><a name="Make"></a>Running a make file</h2><p>Most make files use the command syntax</p><pre> make -f makefile target</pre><p>where <i>makefile</i> is the name of your make file and <i>target</i> is the name of the file you want to generate. If you wanted to generate all the targets listed in the <i>everything</i> line in one of my make files omit the target. For example, if you had generated the make file for Borland Builder 5 with</p><pre> genemake -b5 genemake sdiff > gm_b55.mak</pre><p>but wish to generate only <i>sdiff.exe</i> you would use the command</p><pre> make -f gm_b55.mak sdiff.exe</pre><p>On the other hand, if you wished to generate both <i>genemake.exe</i> and <i>sdiff.exe</i> you would use</p><pre> make -f gm_b55.mak</pre><h2><a name="Compilers"></a>Notes on the compilers</h2><p>Here are some notes on the compilers.</p><h4>Borland 5.0</h4><p>I use version 5.02 that came with Builder 4. You may need to edit the preamble file. If I am running in batch mode I use the following batch file, <i>b0make.bat</i> to run make</p><pre> path C:\bc5\bin;%path% c:\bc5\bin\make %1 %2 %3 %4</pre><p>and the command</p><pre> b0make -f b0.mak</pre><p>where <i>b0.mak</i> is the make file generated by <i>genemake</i>, to make sure I get the Borland include and library files.</p><p>You cannot compile <i>genemake</i> with 16 bit version of this compiler.</p><h4>Borland 5.5</h4><p>This is the compiler that is free from Borland's web site and is the main compiler in Builder 5. You may need to edit the preamble file. My tests have been with the Builder 5 compiler.</p><h4>CC compiler</h4><p>My tests are on a compiler on a Sun. The preamble file might need editing for some compilers. I assume the C++ files have extension <i>.cpp</i>, but the compiler wants files with extension <i>.cxx</i>. So I make a link to the <i>.cpp</i> file with extension <i>.cxx</i> before calling the compiler. You can delete the linking commands if your compiler accepts <i>.cpp</i> extensions. I precede executable names with ./. This prevents my program <i>sdiff</i> getting mixed up with a different program on the Sun and may be required by some operating systems.</p><h4>Gnu compiler</h4><p>My tests are on Linux and on a Sun. On some Unix machines you will need to use <i>gmake</i> rather than <i>make</i>. I precede executable names with ./ as is required by my version of Linux.</p><h4>Intel compiler</h4><p>I am using the PC version that uses the Microsoft libraries and <i>nmake</i>. I use the following batch file to run <i>nmake</i>.</p><pre> path "C:\program files\intel\compiler50\ia32\bin";%path% set lib="C:\program files\intel\compiler50\ia32\lib";%lib% set include="C:\program files\intel\compiler50\ia32\include";%include% nmake %1 %2 %3 %4</pre><h4>Microsoft Visual C++</h4><p>Make with <i>nmake</i>. If you are trying this with version 5 of Visual C++ remember to edit my preamble file to turn off optimisation.</p><h4>Watcom</h4><p>I have version 10A of Watcom which is now very old. I don't know whether my make file will work with version 11. I use the following batch file to run Watcom's make.</p><pre> path C:\WATCOM\bin;C:\WATCOM\binb;C:\WATCOM\binw;%path% set include=C:\WATCOM\h;C:\WATCOM\h\win set watcom=C:\WATCOM\. wmake %1 %2 %3 %4</pre><p>You cannot compile <i>genemake</i> with Watcom's version 10A.</p><h2><a name="Files"></a>Files</h2><table border="1" cellspacing="1" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber2"> <tr> <td width="30%">genemake.htm</td> <td width="70%">This file</td> </tr> <tr> <td width="30%">genemake.cpp</td> <td width="70%">Body file for genemake</td> </tr> <tr> <td width="30%">sdiff.cpp</td> <td width="70%">Body file for sdiff</td> </tr> <tr> <td width="30%">pre_b0.txt</td> <td width="70%">preamble for Borland 5.0</td> </tr> <tr> <td width="30%">pre_b0d.txt</td> <td width="70%">preamble for Borland 5.0 - 16 bit version</td> </tr> <tr> <td width="30%">pre_b5.txt</td> <td width="70%">preamble for Borland 5.5</td> </tr> <tr> <td width="30%">pre_c.txt</td> <td width="70%">preamble for CC compiler</td> </tr> <tr> <td width="30%">pre_g.txt</td> <td width="70%">preamble for Gnu g++ compiler</td> </tr> <tr> <td width="30%">pre_i5.txt</td> <td width="70%">preamble for Intel 5.0 compiler</td> </tr> <tr> <td width="30%">pre_m6.txt</td> <td width="70%">preamble for VC++ 6</td> </tr> <tr> <td width="30%">pre_w0.txt</td> <td width="70%">preamble for Watcom 10.0</td> </tr> <tr> <td width="30%">pre_w0d.txt</td> <td width="70%">preamble for Watcom 10.0 - 16 bit version</td> </tr> <tr> <td width="30%">gm_g.mak</td> <td width="70%">make file for Gnu G++</td> </tr> <tr> <td width="30%">gm_b5.mak</td> <td width="70%">make file for Borland 5.5</td> </tr> </table><p> </p><ul> <li><a href="#Top">Top of page</a></li> <li><a href="ol_doc.htm">To online documentation page</a></li> <li><a href="download.html">To download page</a></li></ul><p> </p></BODY></HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -