TMAKE Usage Guide (better choice than AutoConf, Automake)

zhaozj2021-02-11  238

TMAKE User Guide

Translator: One Wind (Lanzhou University High Performance Computer Laboratory CNYifeng@263.net) TMAKE is a very good way to generate and manage makefile tools. He is developed by Trolltech, written with Perl. Trolltech's main product, everyone knows that it is QT.

If you don't use Tmake to manage makefile, it will be a painful thing, although there is a tool such as AutoConf, but after all, it is still very complicated. Now Tmake will completely free from the cumbersome generation of Makefile, as long as it is very Simple steps can generate makefile. In fact, TMAKE originally written on QT, but do not have QT, we can also enjoy his benefits, Perl fully reflects his power here, I always thought that Perl is a good for system management. language. If you will be Perl, you can try to modify Tmake yourself. Since Tmake is Perl based on Perl, please confirm that your machine is installed. TMAKE has support on Windows and UNIX. And it is free. This article describes Linux as a platform. Ok, let me begin to introduce the installation of Tmake 1. Confirm that you have a version after Perl5 and install (Windows users optional) 2. Decompress the TMAKE TAR.GZ on Linux, decompress the .zip file on Windows. 3. Set good TMAKE path parameters (see below) 4. Join TMAKE / BIN to go to your execution path.

Here are some examples: UNIX Bourne Shell:

TMAKEPATH = / LOCAL / TMAKE / LIB / Linux-G Path = $ PATH: / LOCAL / TMAKE / BIN EXPORT TMAKEPATH PATH

Unix c shell: setENV TMAKEPATH / LOCAL / TMAKE / LIB / Linux-G Setenv Path $ PATH: / LOCAL / TMAKE / BIN

Microsoft Windows: Set TmakePath = C: / Tmake / lib / win32-MSVC SET PATH =% path%; C: / TMAKE / BIN Inside the path set, there are various platform support files and TMAKE execution files. Tmake supporting platforms include: AIX, Data General, FreeBSD, HPUX, SGI Irix, Linux, NetBSD, OpenBSD, OSF1 / DEC, SCO, Solaris, Sunos, ULTRIX, UNIXWARE AND WIN32

Unix users Note: TMAKE The default is Perl installation below / usr / bin, if you are not, modify the parameters of the first line of the Tmake file.

Below we start learning TMAKE: I assume that you have a small QT program, which consists of a C header and two Source File. First, you have to create a TMAKE project file, such as: hello.proheaders = hello.hsources = hello.cpp main.cpptarget = Hello Let's generate makefiletmake hello.pro -o makefile Finally we execute the make command to compile the Hello.

The Makefile Template TMAKE release has the following three templates app.t to create makefilelibdirs.t for generating libraries to create libraries to create Libraries, MakeFileSubDirs.t used to create target documents MakefiletMake.conf this Configuration file contains The completion options and various resource libraries We have the Hello.Pro project files you have above do not include templates or configuration options. The default template is app.t, the default configuration is "Qt Warn_on Release". The following configuration file and the above function are the same template = appconfig = qt waro.hsources = hello.cpp main.cpptarget = hellomakefile configuration option configuration options can be used in app.t and lib.t, they use To indicate what compile options and connection files are used. They have the following: 1. The release option is used to generate the optimized compilation (for publishing software), if "debug" is selected, this option ignores the use of this option while debugging, open the debug function warn_on Open the warning option, which is more than normal Warning. If "WARN_OFF" is selected, this option ignores WARN_OFF to close the warning option 2. QT of the control program / library file type If you generate a QT program, open him (the option is the default support) OpenGL does not say that it is also known to support the thread X11 to support X11Windows Support WindowsConsole is also Windows The lower console program DLL generates a dynamic connection library When using StaticLib to generate a static connection library, use an example: If our Hello program requires Qt and OpenGL support, but also open debug, then our configuration is like this template. = Appconfig = Qt OpenGL Debug (Note Bank's change) Headers = Hello.hsources = Hello.cpp Main.cpptarget = Hello Application Template (App.t) This template supports the following option Headers header file Sources original file Target target file Directory devices in destdir devices defines inform the C pre-processed compiler Open "-d" Options IncludePath Settings Library File Path (-i Options) DependPath Settings Related Search Path DEF_FILE Windows Special: Connect a .def File RC_File Windows Special: Use .rc Document (compiled as .res) res_file windows dedicated: Connection .RES file library template (lib.t) This template allows you to create a dynamic or static library. LIB.T supports the same option as app.t, and also supports an option that is not supported by app.t: Version. Version is a version number. For example: 1.40, version number is very important for dynamic libraries. SubDirs Template (Subdirs.t) When your program file is too much, you can use it. He will all include all the folders you are in and compiled.

The grammatical engineering file of the project file is very easy to add, you can add or delete each option at will. Set an option as follows: Headers = gui.h Xml.h Url.h If your options can not be written in one line, you can use '/' to split him, for example: headers = gui.h / xml.h / url .h engineering documents use blank to divide each element, which means that you cannot use space-free elements in the project file (except for the includePath option, he uses ";" to divide the element). For example: includepath = c: / program files / dblib / include; c: / qt / includetmake supports variable extension, use "$$" to extend engineered variables AllFiles = $$ headers $$ Sources You can assign a value to the engineering variable, you can also Adding variables, for example: a = abcx = xyza = def # a = abc defx * = xyz # x = xyzb = $$ a # b = ABC DEFB - = ABC # b = DEFX / = S / Y / Y / # x = XYZ * = Operator adds a value to the variable (if the variable does not have this value). / = Perform a rule expression. Of course, you can also assign a value under the command line (when running Tmake). For example, if you want to open the debug option, you can use the teMake "config = debug" hello.pro When you want to compile different platforms, use UNIX: or WIN32: Signature Sources = Common.cpp # Common for All Platformsunix: Sources = UNIX.cpp # additional sources for unixwin32: Sources = Win32.cpp # additional Sources for WindowsUnix: libs = -lm # on unix we need the Math Lib and you can set the platform compiler related options, the method is as follows Linux-g : tmake_cflags = -fno-rtti can also customize the template, but you want to know the TMAKE. Running Tmake wrote so much how to create a project file, the following is how to run TMAKE.

The use of Tmake is as follows: tmake [option] Project Files or project settings option: -e expr Explustered, ignoring template file -Nodepend does not generate association information -o file specified output file (common) -t file formulated template file ( Template variables in overlay project files) -unix enforces UNIX mode -V Open Debug and Warn_ON option -Win32 Forced use Win32 mode default engineering file suffix name ".pro", the default template file suffix ".t". If you don't specify them, Tmake will automatically add this is a basic way: (Engineering file is hello) Tmake Hello -o Makefile The following is the way you open debug: Tmake Hello "config = debug" -o Makefile This is a TMAKEPATH to use: Tmake "TMAKEPATH = / LOCAL / TMAKE / LIBEPATH = / LOCAL / TMAKE / LIB / HPUX-G " Hello.Pro -o Makefile This is the usage of Perl expressions (printhead file and source file name) TMAKE Hello -e 'Expand ("Headers", "Sources")' Please note: All command line variable settings are placed behind the project file, otherwise the project file will overwrite them. Other Gadgets ProgenProgen creates an engineering file for you, using the following: Progen -n hello -o hello.pro If you do not specify .cpp or .h file, Progen, or search all files in the current directory and his subdirectory ( In addition to MOC _ *. CPP) Usage: Progen [Option] [C / C Header File and Source File] Options: -lower Put the file name lowercase (more useful under Windows) -N name definition project (ie the target name) -o file definition output file -t file formulates template file

Advanced Topics If you still want to develop a special option or if you want to add a Makefile rule, please continue to see if you want the platform to associate settings, you can write Solaris-Cc: tmake_cc = in the project file /opt/bin/cc_5.0solaris-cc :tmake_cflags = -ptsunix: tmake_libs = -lxextwin32: includepath = c: / myincluden32-borland: defines = no_bool Create your own template If you know Perl, then Tmake will be tmake. There is no limit to it. But first you have to learn how Tmake works. Template Processing When you run TMAKE, he first reads the TMAKE.CONF file, the syntax of this profile and the engineering file is the same. The TMAKE is then read the engineering file and set the variables read from the project file. For example: Headers, Sources, etc. All variables are stored in a global hash array called Project. For example, $ Project {"Sources"} contains "hello.cpp main.cpp" after processing TMAKE.PRO. When Tmake.conf and engineering files are finished, TMAKE starts a line of reading template files and executes any perl script he discovers? All characters of the line be considered when Perl scripts after "# $"? From " All characters of # {"#}" are also considered to be Perl scripts? "#!" The line is all notes? Other direct output examples: #! 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. Output statement: this text will appear in the output. The header file (s) area: hello.h # this text Also Appers in the Output. 156THAT'S ALL. Knowing the TMAKE with Lex and Yacc using standard TMAKE templates how to process C and C files, but maybe you have to handle other files and to connect them into your project. A typical example is when you build an analyzer, you have to handle the Lex and Yacc files. Analysis Template: #! #! Parser.t: this is a custom template for building a paser #! # $ 有 Template ("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) $ (lexin)

$ (Parser): $ (YACCIN) $ (YACC) $ (YACC) # $ $ TEXT = ($ I_UNIX? "-Rm -f": "-del"). '$ (Parser)'; # $ tEXT = ($ I_UNIX? "-mv": "-ren"). '$ (Yaccout) $ (Parser)'; Analysis Template adds some rules for building the Lex and YACC. This template can be used in UNIX or Windows, which should produce different rules based on $ IS_UNIX variables. For more information, please refer to Reference Manual (unrelated) Example Project File: Template = Parser.t config = console release lexinput = lexer.l Yaccinput = grammar.l yaccinput = grammar.y Parser = Parser.cpp Sources = $$ Parser / Node. CPP / asmgen.cpp target = parse

Here we use macro variables to avoid writing Parser.cpp twice. Calculating the code line Because Tmake is Perl based, it allows you to create your own template for other purposes (ie, a template that is not used to generate Makefile) template wc.t (a template for calculating the number of code) #! Template That Count Number Of C Lines. The Number Of C Code Lines for # $ TEXT = $ Project_name; # $ {$ files = $ project {"headers"}. ""}}} "}; $ Text {" Sources "}; $ text = `wc -l $ files`; # $} This run: TMAKE -T WC Hello output is: The Number of C code lines for hello.pro 25 Hello.cpp 161 Total only when you You can do this after you have installed wc.t.

转载请注明原文地址:https://www.9cbs.com/read-4809.html

New Post(0)