| **Navigation:**  [[advanced topics 1.htm|Advanced Topics]] > Legacy Project System Reference >====== Project System Macros ====== | [[introduction 1.htm|{{btn_prev_n.gif|Previous page}}]][[advanced topics 1.htm|{{btn_home_n.gif|Return to chapter overview}}]][[basic compiling and linking.htm|{{btn_next_n.gif|Next page}}]] | | || [[project system macros.htm#setting macro values|Setting Macro Values]] [[project system macros.htm#special project system macros|Special Project System Macros]] Macros are special strings that indicate a variable substitution is required. You may find it useful to think of macros as variables. A sequence of characters enclosed by % characters indicates a macro name. The following characters are permitted in macro names: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z a b c d e f g h i j k l m n o p q r s t u v w x y z 0 1 2 3 4 5 6 7 8 9 _ The trailing % may be omitted provided the character following the macro name is not one of the characters above. Whenever a % delimited macro name is encountered, it is replaced either by the string associated with that macro, or by an empty string if there is no associated string. Substitution strings are associated with a macro by using the #set command. Two adjacent % characters may be used when a % character is required in the substituted string. This double % technique can be used to delay macro substitution. For example: **#set echo = '#message %%mymac' --'#message %mymac' associated with echo** **#set mymac = 'Hello' --'Hello' associated with mymac** **%echo --'#message %mymac' substituted for %echo** **-- and 'Hello' substituted for %mymac** **#set mymac = 'World' --'World' associated with mymac** **%echo --'#message %mymac' substituted for %echo** **-- and 'World' substituted for %mymac** If a single % had been specified in the first #set command, the macro %mymac would have been expanded (to the empty string) before defining the replacement text for the macro %echo. The double % results in the project system executing: **#message Hello** **#message World** The single % results in the project system executing: **#message ""** **#message ""** __**Setting Macro Values**__ **#set** #set macroname = string The #set command associates a macro name with a string. Any previous setting for the given macro is lost. The macro name in the #set command should not be delimited by % characters. The string should be enclosed in single quotes if it contains embedded spaces or project system keywords. For example: **#set cwindow = TopSpeed** **#set linkit = '#link myfile'** **...** **#if '%cwindow'= TopSpeed #then** **#pragma link(CS_GRAPH.LIB)** **#endif** **%linkit** **#expand <;file-name>** The filename is subjected to redirection analysis, and the following macros are defined: %cpath Is set to the fully expanded filename where the file would be created. %opath Is set to the fully expanded filename where the file would be opened. %ext  Is set to the extension of the filename. %tail  Is set to the filename, less extension, drive and path. %cdir  Is set to the directory where the file would be created. %odir Is set to the directory where the file would be opened for read (if the file does not exist %opath is set the same as %cpath). For example, suppose the redirection file has the line, ***.def : . ; c:\ts\include** and the file c:\ts\include\io.def exists, and the current directory is d:\test then, **#expand io.def** is equivalent to, **#set opath = d:\test\io.def** **#set cpath = c:\ts\include\io.def** **#set ext = .def** **#set tail = io** **#set odir = d:\test\** **#set cdir = c:\ts\include\** **#split <;filename>** The filename is split into its base and extension. The following macros are defined: %ext  Is set to the extension of the filename. %name1 Is set to the filename, less extension. For example: **#split d:\name.exe** is equivalent to, **#set ext = exe** **#set name = d:\name** __**Special Project System Macros**__ A number of macros are used for special purposes by the Project System, and you should avoid defining macros of the same name inadvertently. Similarly, you should not define macros using trailing underbars. The following is a list, in alphabetical order, of all such macros: %action Set to make, link, compile or run, depending on the mode of invocation. %cdir  Set by the **#expand** command. %compile_src In compile mode, this is set to the name of the file to be compiled, with path and extension where available. Otherwise, it is set to the empty string. %cpath Set by the **#expand** command. %devsys Set by the Clarion environment to win. %editfile Set to the name of the file being edited in the topmost window. If no window is open, or in batch mode, it is set to the empty string. %editwin Set to the window number (0-9) of the topmost window. If no window is open, or in batch mode, it is set to the empty string. %errors Count of errors produced by preceding compile or **#file adderrors** command. %ext  Set by the **#split** and **#expand** commands. %filetype Set by the **#system** command to its second argument, and examined by the **#link** command. %jpicall Set by the **#model** command to its second argument, and examined by the **#link** command. %L Set by the **#model** command to either '' (standalone) L (local) or ! (own). The **#link** command uses this to derive the name of any required library files. %link  Set to the current link list. %link_arg Set to its argument by the **#link** command. %main Set to the assumed name of the main source file. In make or link mode when not using UNNAMED.PR, this is derived from the project filename, with path and extension removed. Otherwise, it is the supplied source filename complete with path and extension if specified. %make Set to on or off by the **#compile**, **#link** and **#dolink** commands, to indicate whether the target file was up to date. %manual_export Set this macro on to indicate that the **#link** command should not construct a .LIB file when a DLL is linked. If this macro is not specified, a .LIB file is created automatically from the corresponding .EXP file if found (see Module Definition File below), or from the object files in the link list. %model Set by the **#model** command to its first argument, and examined by the #link command. %name Set by the **#split** command. %obj  Set to the object filename in a **#compile** command. %odir  Set by the **#expand** command. %opath Set by the **#expand** command. %pragmastring Will always expand to the current state of the #pragma settings - this is useful for debugging. %prjname Set to the assumed name of the project - this is usually derived from the project filename, but with the path and extension removed. Where UNNAMED.PR is being used, it is derived from main source filename without source and extension. %remake Used within **declare_compiler** macros to determine whether source/object dependencies require a remake. %remake_jpi Used within **declare_compiler** macros to determine whether source/object dependencies require a remake. %remake_jpi should be used for object files created by SoftVelocity compilers, which contain additional information. %reply Set by the **#prompt** command. %S Set by the **#system** command to 32 indicating the instruction set being used to build the project. The **#link** command uses this to derive the name of any required library files. %src  Set to the source filename in a **#compile** command. %system Set by the **#system** command to its first argument, and examined by the **#model** and **#link** commands. %tail  Set by the **#expand** command. %tsc  Set to on if a C or C++ source file is compiled. %tscpp Set to on if a C++ source file is compiled. %tsm2 Set to on if a Modula-2 source file is compiled. %tspas Set to on if a Pascal source file is compiled. The above macros are examined by the **#link** command to determine which libraries to include, and then set to off. %warnings Count of warnings produced by preceding compile or **#file adderrors** command. %X  The **#link** command uses this to derive the name of any required library files. It adds the letter 'X' to the library name, indicating a 32-bit link.