tmake Reference Manual


Project Settings

tmake recognizes several project tags. The syntax for setting a project variable is:
    TAG = value
You can also do tag expansion using $$:
    ALLFILES = Project files: $$HEADERS $$SOURCES
Normally you assign to a tag, but you can also add to a tag, subtract from a tag or replace parts of the tag.
    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
The *= operation adds the value if the tag does not already contain it. The /= operation performs regular expression substitution.

You can also set tags from the command line when running the tmake program. For instance, if you want to generate a makefile with debug information:

    tmake hello.pro "CONFIG+=debug"

Use the unix: or win32: qualifier if you want a platform-specific tag:

    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
If none of the platforms match, tmake looks for the tag in CONFIG setting:
    debug:SOURCES  +=  dbgstuff.cpp # additional source for debugging
Finally, you can set platform and compiler-dependent tags:
    linux-g++:TMAKE_CFLAGS = -fno-rtti

You may define your own project tags to be used by custom templates. A project tag is stored in %project, which is an associative Perl array. Access it like this: $project{"tag"} or via the function Project('tag'). For example, after reading "hello.pro", $project{"SOURCES"} contains "hello.cpp main.cpp". One limitation of tmake is that it cannot handle file names with white space.


Project Tag Reference

ALL_DEPS

Specifies additional dependencies for the makefile target "all:".

CLEAN_FILES

Specifies additional files to be removed for "make clean".

Example:

  CLEAN_FILES = core *~

CONFIG

Sets the make configuration. It tells the tmake templates what compiler options to use and which extra libraries to link in.

These options control the compilation flags:

  release   Compile with optimization enabled, ignored if "debug" is specified.
  debug   Compile with debug options enabled.
  warn_on   The compiler should emit more warnings than normally, ignored if "warn_off" is specified.
  warn_off   The compiler should emit no warnings or as few as possible.

These options defines the application/library type:

  qt   The target is a Qt application/library and requires Qt header files/library.
  opengl   The target requires the OpenGL (or Mesa) headers/libraries.
  x11   The target is a X11 application (app.t only).
  windows   The target is a Win32 window application (app.t only).
  console   The target is a Win32 console application (app.t only).
  dll   The target is a shared object/DLL (app.t only).
  staticlib   The target is a static library (lib.t only).

DEF_FILE

Win32/app.t only: Specifies a .def file.

DESTDIR

Specifies where to put the target file. Example:
  DESTDIR = ../../lib
You must create this directory before running make.

HEADERS

Defines the header files of the project.

INCPATH

This tag is generated from INCLUDEPATH. The ';' or ':' separators have been replaced by ' ' (single space). This makes it easier to split. qtapp.t and other templates expand INCPATH to set -I options for the C++ compiler.

INCLUDEPATH

This tag specifies the #include directories. It can be set in the project file, or by the AddIncludePath() function.

Example:

  INCLUDEPATH = c:\msdev\include d:\stl\include
Use ';' or space as the directory separator.

LIBS

Defines additional libraries to be linked in when creating an application or a shared library. You probably want to use a platform qualifier since libraries are specified differently on Unix and Win32.

Example:

  unix:LIBS  = -lXext -lm
  win32:LIBS = ole32.lib

MOC_DIR

Specifies where to put the temporary moc output files. By default they are stored in the directory where the moc input files are.

Example:

  MOC_DIR = tmp
You must create this directory before running make.

See also: OBJECTS_DIR.

OBJECTS

This tag is generated from SOURCES by the StdInit() function. The extension of each source file has been replaced by .o (Unix) or .obj (Win32).

Example:

  SOURCES = a.x b.y
Then OBJECTS become "a.o b.o" on Unix and "a.obj b.obj" on Win32.

OBJECTS_DIR

Specifies where to put object files. By default they are stored in the directory where the source files are.

Example:

  OBJECTS_DIR = tmp
You must create this directory before running make.

See also: MOC_DIR.

OBJMOC

This tag is generated by the StdInit() function if $moc_aware is true. OBJMOC contains the name of all intermediate moc object files.

Example:

  HEADERS = demo.h
  SOURCES = demo.cpp main.cpp
If demo.h and main.cpp define classes that use signals and slots (i.e. the Q_OBJECT "keyword" is found in these two files), OBJMOC becomes:
  OBJMOC  = moc_demo.obj
See also: SRCMOC.

PROJECT

This is the name of the project. It defaults to the name of the project file, excluding the .pro extension.

RC_FILE

Win32/app.t only: Specifies a .rc file. Cannot be used with the RES_FILE tag.

RES_FILE

Win32/app.t only: Specifies a .res file. You can either specify a .rc file or one or more .res files.

SOURCES

Defines the source files of the project.

SRCMOC

This tag is generated by the StdInit() function if CONFIG contains "qt". SRCMOC contains the name of all intermediate moc files.

Example:

  HEADERS = demo.h
  SOURCES = demo.cpp main.cpp
If demo.h and main.cpp define classes that use signals and slots (i.e. the Q_OBJECT "keyword" is found in these two files), SRCMOC becomes:
  SRCMOC  = moc_demo.cpp main.moc
See also: OBJMOC.

TARGET

Sets the makefile target, i.e. what program to build.

TEMPLATE

Sets the default template. This can be overridden by the tmake -t option.

TMAKE_CC

Contains the name of the compiler.

TMAKE_CFLAGS

Contains the default compiler flags.

TMAKE_FILETAGS

Tells tmake which tags contain file names. This is because tmake on Windows replace the directory separator / with \.

Function Reference

This section contains a brief description of some important tmake functions used by the templates.

AddIncludePath(path)

Adds path to the include path variable, INCLUDEPATH. The include path is used for two purposes:
  1. Searching files when generating include dependencies.
  2. Setting -I options for the C/C++ compiler.

Example:

  #$ AddIncludePath('$QTDIR/include;/local/include');

BuildMocObj(objects,sources)

Creates build rules for moc source files. Generates include dependencies.

Example:

  #$ BuildMocObj($project{"OBJMOC"},$project{"SRCMOC"});
Output:
  moc_hello.o: moc_hello.cpp \
		hello.h \
		...

BuildMocSrc(files)

Creates moc source files from C++ files containing classes that define signals and slots. For a header file x.h, the generated moc file is called moc_x.h. For a source file y.cpp, the generates moc file is called y.moc and should be #include'd by y.cpp.

Example:

  #$ BuildMocSrc($project{"HEADERS"});
  #$ BuildMocSrc($project{"SOURCES"});
Output:
  moc_hello.cpp: hello.h
	$(MOC) hello.h -o moc_hello.cpp

BuildObj(objects,sources)

Creates build rules for source files. Generates include dependencies.

Example:

  #$ BuildObj($project{"OBJECTS"},$project{"SOURCES"});
Output:
  hello.o: hello.cpp \
		hello.h \
		...

  main.o: main.cpp \
		hello.h \
		...

Config(string)

Returns true if the CONFIG tag contains the given string.

Example:

  #$ if ( Config("release") { }

DisableOutput()

Call this function to force tmake to generate no output until EnableOutput() is called.

Example:

  #$ Config("debug") && DisableOutput();
      Anything here is skipped if CONFIG contains "debug".
  #$ Config("debug") && EnableOutput();

EnableOutput()

Enables tmake output after DisableOutput() was called.

Expand(tag)

Expands a project tag. Equivalent to $text = $project{$tag}.

Example:

  VERSION = #$ Expand("VERSION");
Output:
  VERSION = 1.1

ExpandGlue(tag,prepend,glue,append)

Expands a $project{} tag, splits on whitespace and joins with $glue. $prepend is put at the start of the string and $append is put at the end of the string. The resulting string ($text) becomes "" if the project tag is empty or not defined.

Example:

  clear:
          #$ ExpandGlue("OBJECTS","-del","\n\t-del ","");
Output (Windows NT):
  clear:
          -del hello.obj
          -del main.obj

ExpandList(tag)

This function is suitable for expanding lists of files. Equivalent with ExpandGlue($tag,""," \\\n\t\t","").

Example:

  OBJECTS = #$ ExpandList("OBJECTS");
Output:
  OBJECTS = hello.o \
	    main.o

IncludeTemplate(file)

Includes a template file. The ".t" extension is optional.

Example:

  #$ IncludeTemplate("mytemplate");

Now()

Sets $text to the current date and time.

Example:

  # Generated at #$ Now()
Output:
  # Generated at 12:58, 1996/11/19

Project(strings)

This is a powerful function for setting and reading project variables. Returns the resulting project variables (joined with space between).

Examples:

# Get a project variable:
    $s = Project("TEMPLATE");	    -> $s = "TEMPLATE"

# Set a project variable:
    Project("TEMPLATE = lib");	    -> TEMPLATE = lib
    Project("CONFIG =";)	    -> CONFIG empty

# Append to a project variable:
    Project("CONFIG = qt");	    -> CONFIG = qt
    Project("CONFIG += debug");	    -> CONFIG = qt debug

# Append to a project variable if it does not contain the value already:
    Project("CONFIG = qt release"); -> CONFIG = qt release
    Project("CONFIG *= qt");	    -> CONFIG = qt release
    Project("CONFIG *= opengl");    -> CONFIG = qt release opengl

# Subtract from a project variable:
    Project("THINGS = abc xyz");    -> THINGS = abc xyz
    Project("THINGS -= abc");	    -> THINGS = xyz

# Search/replace on a project variable:
    Project("CONFIG = tq opengl");  -> CONFIG = tq opengl
    Project("CONFIG /= s/tq/qt/");  -> CONFIG = qt opengl

# The operations can be performed on several project variables at a time.

    Project("TEMPLATE = app", "CONFIG *= opengl", "THINGS += klm");

ScanProject(file)

Scans a project file and stores the project tags and values in the global associative %project array.

StdInit()

Standard initialization of tmake. StdInit() should be called from one of the first lines in the template.

This function creates some new project tags:

The moc-related tags are created only if CONFIG contains "qt"

Substitute(string)

This function takes a string and substitutes any occurrence of $$tag with the actual content of the tag. Returns the substituted string. Also sets $text.

Important: Use single quotes around the string, otherwise perl will expand any $tags it finds.

Example:

    Substitute('Project name: $$PROJECT, uses template $$TEMPLATE');