📄 tmake.html
字号:
The lib.t template supports the same project variables as app.t, but also<code>VERSION</code>. <code>VERSION</code> is the version number of thetarget library, e.g. 1.40. The version is important for shared libraries.<h4>The Subdirs Template</h4>The subdirs template, subdirs.t, lets you invoke make in subdirectories.<p>The <code>SUBDIRS</code> variable contains the name of all subdirectories tobe processed.<h4>Special Templates for Microsoft Visual C++</h4>If you have Microsoft Visual C++ 5.0, you can use two special templates togenerate a MSVC++ IDE project (.dsp file). After you have generatede.g. hello.dsp, choose "File"->"Open Workspace" and select the hello.dspfile. Visual C++ will then create a workspace (.dsw file) for you.<p><table border="0"> <tr> <td> </td> <td>vcapp.t</td> <td> </td> <td>Creates an application project file (Microsoft Visual C++ 5.0 only).</td> </tr> <tr> <td> </td> <td>vclib.t</td> <td> </td> <td>Creates a library project file (Microsoft Visual C++ 5.0 only).</td> </tr></table><p>Run tmake to create a hello.dsp file (use -t to override the defaulttemplate):<pre> tmake -t vcapp -o hello.dsp hello.pro</pre><hr><h2>Project File Syntax</h2>The tmake project file has a very simple syntax. You may setproject variables, append to project variables, remove fromproject variable and substitute project variables.To set a project variable:<pre> HEADERS = gui.h xml.h url.h</pre>If you cannot fit everything on one line, use '\' to split it up:<pre> HEADERS = gui.h \ xml.h \ url.h</pre><p>Project variables contains lists of items (such as header files,compiler options etc.) and use whitespace to separate the items.This means that tmake cannot deal with items containing whitespace.The INCLUDEPATH variable is an exception. If INCLUDEPATH containsone or more semicolons (;), tmake uses the semicolon to separatethe include directories, hence you can have include directoriescontaining whitespace (this is quite common on Windows).<p>Here is an example:<pre> INCLUDEPATH = C:\Program Files\DBLib\Include;C:\qt\include</pre><p>tmake supports <em>project variable expension</em>. Use $$ to expandany project variable:<pre> ALLFILES = $$HEADERS $$SOURCES</pre><p>Most often you assign some value to a project variable, but you canalso add to, remove from or replace parts of a project variable.<pre> A = abc X = xyz A += def # A = abc def X *= xyz # X = xyz B = $$A # B = abc def B -= abc # B = def X /= s/y/Y/ # X = xYz</pre>The *= operation adds the value if the variable does not already contain it.The /= operation performs regular expression substitution.<p>You can also set variables from the command line when running the tmakeprogram. For instance, if you want to generate a makefile with debuginformation:<pre> tmake "CONFIG+=debug" hello.pro</pre><p>Use the <tt>unix:</tt> or <tt>win32:</tt> (conditional) qualifier if you want aplatform-specific variable:<pre> SOURCES = common.cpp # common for all platforms unix:SOURCES += unix.cpp # additional sources for Unix win32:SOURCES += win32.cpp # additional sources for Windows unix:LIBS += -lm # on Unix we need the math lib</pre>If none of the platforms match, tmake looks for the variable in CONFIGvariable:<pre> debug:SOURCES += dbgstuff.cpp # additional source for debugging</pre>Finally, you can set platform and compiler-dependent variables:<pre> linux-g++:TMAKE_CFLAGS = -fno-rtti</pre><p>You may define your own project variables to be used by custom templates. Aproject variable is stored in <code>%project</code>, which is an associativePerl array. Access it like this: <code>$project{"var"}</code> or via thefunction <code>Project("var")</code>. For example, after reading"hello.pro", <code>$project{"SOURCES"}</code> contains "hello.cppmain.cpp".<p><hr><h2><a name="usage"></a>Running tmake</h2>Usage:<pre> tmake [options] <em>project files or project settings</em></pre>Options:<pre> -e expr Evaluate the Perl expression. Ignores the template file. -nodepend Don't generate dependency information. -o <em>file</em> Write output to <em>file</em> instead of stdout. -t <em>file</em> Specify a template <em>file</em>. -unix Force tmake into Unix mode. -v Verbose/debugging on. -win32 Force tmake into Win32 mode.</pre>The -t option overrides any <code>TEMPLATE</code> variable in the project file.<p>The default project file extension is ".pro". The default template fileextension is ".t". If you do not specify these extension tmake willautomatically add them for you.<p>Example of basic use:<pre> tmake hello -o Makefile</pre><p>Example of how to create a makefile with debugging information:<pre> tmake hello "CONFIG+=debug" -o Makefile</pre><p>Exmaple of how to specify a TMAKEPATH:<pre> tmake "TMAKEPATH=/local/tmake/lib/hpux-g++" hello.pro -o Makefile</pre>Example of how to evaluate a perl expression (print names of headersand source files):<pre> tmake hello -e 'Expand("HEADERS","SOURCES")'</pre>Note that project settings on the command line must come after theproject file, otherwise they will be overridden by the settings in theproject file.<hr><h2><a name="progen"></a>The progen Utility</h2>The progen utility creates project files for you. It can be used likethis:<pre> progen -n hello -o hello.pro</pre>If no .cpp or .h files are specified on the command line, progensearches for .cpp and .h (except moc_*.cpp) in the current directoryand below.<p>Usage:<pre> progen [options] [<em>C/C++ header files and source files</em>]</pre>Options:<pre> -lower Lower-case letters in filenames (useful on Windows). -n <em>name</em> Specify a project name (<code>TARGET</code>). -o <em>file</em> Write output to <em>file</em> instead of stdout. -t <em>file</em> Specify a template <em>file</em>.</pre><hr><h2>Advanced Topics</h2>In most cases you will be happy with using tmake as described above, butsometimes you need to add special compiler options or even add newmakefile rules. This chapter describes how to customize your makefiles.<h4>Conditional Project Settings</h4>If you need a special compiler option etc., you can add platform-dependentsettings in your project file:<pre> solaris-cc:TMAKE_CC = /opt/bin/CC_5.0 solaris-cc:TMAKE_CFLAGS = -pts unix:TMAKE_LIBS = -lXext win32:INCLUDEPATH = c:\myinclude win32-borland:DEFINES = NO_BOOL</pre>You can prefix a project variable with unix: or win32: to make it specific foreither Unix or Windows. You can also prefix a variable with<em>platform-compiler</em> <h4>Your Own Templates</h4>If you know Perl programming, there is virtually no limitation to what youcan do with tmake. First you need to know how tmake works.<h4>Template Processing</h4>When you run tmake, it first reads the <tt>tmake.conf</tt> file.This configuration file has the same syntax as the project file.tmake then reads the project file and sets the project variables itfinds, e.g. <code>HEADERS</code>, <code>SOURCES</code> etc.All variables and values are stored in a global associative Perl hasharray called <code>project</code>. For example,<code>$project{"SOURCES"}</code> contains "hello.cpp main.cpp"after processing hello.pro.When both the <tt>tmake.conf</tt> and the project files have beenread, tmake starts reading the template file line by line andexecutes any Perl code it finds in the template.<ul><li>Anything after <code>#$</code> until newline is evaluated as perl code. The perl code is substituted with the contents of the <code>$text</code> variable.<li>Block of perl code: <code>#${</code> until <code>#$}</code>.<li>Comments; <code>#!</code> until newline is stripped.<li>Anything else is copied directly from the template to the output.</ul><p>Example:<pre> #! This is a comment which will be removed. This text will appear in the output. #$ $text = "The header file(s) are: " . $project{"HEADERS"}; # This text also appears in the output. #${ $a = 12; $b = 13; $text = $a * $b; #$} That's all.</pre>Output:<pre> This text will appear in the output. The header file(s) are: hello.h # This text also appears in the output. 156 That's all.</pre><h3>Using tmake With Lex and Yacc</h3>The standard tmake templates knows how to process C and C++ files, butsometimes you need to process additional files and link them into yourproject. A typical example is to process lex and yacc files when you'rebuilding a parser.<p>Parser template:<pre> #! #! parser.t: This is a custom template for building a parser #! #$ IncludeTemplate("app.t"); ####### Lex/yacc programs and options LEX = flex YACC = #$ $text = ($is_unix ? "yacc -d" : "byacc -d"); ####### Lex/yacc files LEXIN = #$ Expand("LEXINPUT"); LEXOUT = lex.yy.c YACCIN = #$ Expand("YACCINPUT"); YACCOUT = y.tab.c YACCHDR = y.tab.h PARSER = #$ Expand("PARSER"); ####### Process lex/yacc files $(LEXOUT): $(LEXIN) $(LEX) $(LEXIN) $(PARSER): $(YACCIN) $(LEXOUT) $(YACC) $(YACCIN) #$ $text = ($is_unix ? "-rm -f " : "-del ") . '$(PARSER)'; #$ $text = ($is_unix ? "-mv " : "-ren ") . '$(YACCOUT) $(PARSER)'; </pre>The parser template adds some extra rules to the application templatein order to build the lex and yacc portions of the project. Thistemplate is portable across Unix and Windows since it generates differentcommands depending on the <code>$is_unix</code> variable.<p>To learn more about the Expand() function and other Perl functions whichtmake provides, consult the <a href="tmake_ref.html">reference manual</a>.<p>Example project file:<pre> TEMPLATE = parser.t CONFIG = console release LEXINPUT = lexer.l YACCINPUT = grammar.y PARSER = parser.cpp SOURCES = $$PARSER \ node.cpp \ asmgen.cpp TARGET = parser</pre>Here we use macro expansion <code>$$PARSER</code> to avoid writing parser.cpptwo places.<h3>Counting the Number of Code Lines</h3>tmake is generic since it is based on Perl. You can create your owntemplates for other purposes than producing makefiles. Here is an exampletemplate that counts the number of code lines in our project.<p>Template wc.t:<pre> #! Template that count number of C++ lines. The number of C++ code lines for #$ $text=$project_name; #${ $files = $project{"HEADERS"} . " " . $project{"SOURCES"}; $text = `wc -l $files`; #$}</pre>Run it:<pre> tmake -t wc hello</pre>Output:<pre> The number of C++ code lines for hello.pro 25 hello.h 98 hello.cpp 38 main.cpp 161 total</pre>This will only work if the wc program is installed on your system.</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -