5.4 Macros

To provide the greatest modularity for code, and avoid hard-coding directory paths and other strings that could change if you change your platform or other build conditions. Instead, use a macro that will be replaced with the appropriate value at build time. Conary has several built-in macros in /etc/conary/macros, outlined in the sections that follow:

You can also reate and use your own macro. The following code creates and uses a macro called exampledir to represent the directory where software files are unpacked:

        r.macros.exampledir = '%(servicedir)s/%(name)s'
        r.addArchive('%(name)s-%(version)s.tgz', dir='%(exampledir)s')
        r.SetModes('%(exampledir)s/Settings.php', 0644)
            

5.4.1 Directory Path Macros

Directory path macros expand to directory paths expected on your build system, and on the target/destination system where your package or group is ultimately installed. Use the following directory path macros in your recipes where appropriate:

Table 5.9. Directory Path Macros

MacroTypically expands to...Usage Tips and Examples
%(bindir)s %(exec_prefix)s/bin (/usr/bin in most Linux systems) This is the directory of executables that are available to users on the underlying system.
r.Install('example.exe','%(bindir)s/')
%(builddir)s The buildPath value in Conary configuration in the context (current working directory) where you're running your package build command; to check this value, use: conary config | grep buildPath This is the directory defined for Conary's source building/compiling operations, primarily when packaging from source code. Source code is unpacked to %(builddir)s, and you can use the macro where appropriate to reference your unpacked source.
r.Environment('EXAMPLEPATH', '%(builddir)s/example')
%(buildlogpath)s %(debugsrcdir)s/buildlogs/%(name)s-%(version)s-log.bz2 (/usr/src/debug/buildlogs/<name>-<version>-log.bz2) This location is used internally by Conary. This macro should not be changed in your recipes, and it is not typically explicitly specified.
%(cachedir)s %(localstatedir)s/cache (/var/cache in most Linux systems) This is the location for cached application data.
r.MakeDirs('%(cachedir)s/{local,X11R6}')
%(datadir)s %(prefix)s/share (/usr/share in most Linux systems) The location where architecture-independent data resides. This directory contains subdirectories and data sharable among all architectures.
r.ComponentSpec('apidox', '%(datadir)s/%(qt)s/doc/')
%(debuglibdir)s /usr/lib/debug This location is used in assembling packages for a :debuginfo component. This macro should not be changed in your recipes, and it is not typically explicitly specified.
%(debugsrcdir)s /usr/src/debug This location is used in assembling packages for a :debuginfo component. This macro should not be changed in your recipes, and it is not typically explicitly specified.
%(destdir)s Set as needed by Conary based on the value of %(builddir)s This is the installation directory used to install package files during a package build, imitating the files' organization on the target filesystem.
r.MakeInstall('PREFIX=%(destdir)s/%(prefix)s')
%(docdir)s %(datadir)s/doc (/usr/share/doc in most Linux systems) This location contains miscellaneous documentation in various formats used by applications on the system.
r.ComponentSpec('doc', '%(docdir)s/.*')
%(essentialbindir)s /bin on a system that follows the Linux filesystem hierarchy This is the directory for essential system binaries. This directory contains executables used for critical system operations, such as booting and mounting partitions.
r.Symlink('bash', '%(essentialbindir)s/sh')
%(essentialsbindir)s /sbin on a system that follows the Linux filesystem hierarchy This is the location of essential system administration binaries. This directory contains executables used by the root user and utilites that run as the root user.
r.Move('/dev/MAKEDEV', '%(essentialsbindir)s/')
%(essentiallibdir)s /%(lib)s (/lib or /lib64 in most Linux systems, depending on the architecture for which the recipe is built) This is the directory for essential shared data files. This directory subdirectories, data files, and shared libraries.
r.MakeDirs('%(essentiallibdir)s/firmware')
%(exec_prefix)s %(prefix)s (/usr in most Linux systems) This is the installation prefix for architecture-dependent files. This directory contains subdirectories of architecture-dependent executables, libraries, and other files.
r.ManualConfigure('--prefix=%(prefix)s --exec-prefix=%(exec_prefix)s')
%(groupinfodir)s %(sysconfdir)s/conary/groupinfo (/etc/conary/groupinfo on most Linux systems) This location has Conary user group info used to provide Linux system group information to info recipes (see Creating System Users and Groups with Info Packages at docs.rpath.com/conary).
r.Install('samplegroup', '%(groupinfodir)s/')
%(includedir)s %(prefix)s/include (/usr/include in most Linux systems) This is the location that contains header files used by applications on the system.
r.Symlink('%(x11includedir)s/X11', '%(includedir)s/X11')
%(infodir)s %(datadir)s/info (/usr/share/info in most Linux systems) This is the primary location for the GNU info system. This directory contains subdirectories and compressed GNU info pages.
r.InitialContents('%(infodir)s/dir')
%(initdir)s %(sysconfdir)s/init.d (/etc/init.d in most Linux systems) This indicates the location for init scripts used by SysVinit.
r.TagSpec('initscript', '%(initdir)s/')
%(krbprefix)s %(exec_prefix)s/kerberos (/usr/kerberos in most Linux systems) This is the installation location for kerberos.
r.Remove('%(krbprefix)s/man/cat*', recursive=True)
%(lib)s lib or lib64 This is just a text replacement used in other directory paths that is determined by how the recipe is built, specifically whether or not it is built with the x86_64 architecture flavor specification.
%(libdir)s %(exec_prefix)/%(lib)s (/usr/lib or /usr/lib64 in most Linux systems, depending on the architecture for which the recipe is built) This is the directory for shared data files. This directory subdirectories, data files, and shared libraries.
r.Remove('%(libdir)s/libss.a')
%(libexecdir)s %(exec_prefix)s/libexec (/usr/libexec in most Linux systems) This is the location of helper binaries. This directory contains small helper executables called by other applications.
r.SetModes('%(libexecdir)s/pt_chown', 0755)
%(prefix)s /usr on a system that follows the Linux filesystem hierarchy This is the system resources directory, which contains subdirectories of executables, libraries, documentation, and other files which do not change during normal operations.
r.Make("PREFIX=%(prefix)s")
%(localstatedir)s /var on a system that follows the Linux filesystem hierarchy This is the dynamic files location. This directory contains subdirectories of files that change with the system state, such as temporary files and log files.
r.Make Dirs('%(localstatedir)s/run/radvd/')
%(mandir)s %(datadir)s/man (/usr/share/man in most Linux systems) This is the location of the online manual files used by the man utility on Linux systems. This directory contains subdirectories associated with each manual section, and each manual file is installed in its appropriate section.
r.Install('anacron.8', '%(mandir)s/man8/')
%(sbindir)s %(exec_prefix)s/sbin (/usr/sbin in most Linux systems) This is the location of system administration binaries. This directory contains executables used by the root user for system administration tasks such as network configuration.
r.Install('inputattach', '%(sbindir)s/')
%(servicedir)s /srv on a system that follows the Linux filesystem hierarchy This is the location for data related to services offered by the system. This directory contains subdirectories, each with data associated with a given service.
r.SetModes('%(servicedir)s/example', 0640)
%(sharedstatedir)s %(prefix)/com (/usr/com on most Linux systems) The location for architecture-independent data files which are modified by applications when they run.
r.Make('--sharedstatedir=%(sharedstatedir)s')
%(sysconfdir)s /etc on a system that follows the Linux filesystem hierarchy This is the system configuration directory, which contains subdirectories and system-wide configuration files.
r.Create('%(sysconfdir)s/example/example.conf')
%(tagdatadir)s %(datadir)s/conary/tags (/usr/share/conary/tags in most Linux systems) This is the location of the data used by Conary tag handlers. This macro should not be modified in your recipes.
r.addSource(catalog, dest='%(tagdatadir)s/xml-catalog/desc.d/')
%(tagdescriptiondir)s %(sysconfdir)s/conary/tags (/etc/conary/tags on most Linux systems) This is the location of the Conary tag description files. This macro should not be modified in your recipes.
r.addSource('info-file.tagdescription', macros=True, dest='%(tagdescriptiondir)s/info-file'))
%(taghandlerdir)s %(libexecdir)s/conary/tags (/usr/libexec/conary/tags in most Linux systems) This is the location of the Conary tag handler files. This macro should not be modified in your recipes.
r.Requires('grep:runtime', '%(taghandlerdir)s/')
%(testdir)s %(localstatedir)s/conary/tests (/var/conary/tests on most Linux systems) This macro is specified internally by the r.TestSuite() recipe action
%(thisdocdir)s %(docdir)/%(name)s-%(version)s (/usr/share/doc/<package_name>-<package_version> on most Linux systems) This is a location in the documentation directory that contains documentation specific to your package, using the name and version variables from your package recipe in the subdirectory name.
r.Move('%(docdir)s/html/*', '%(thisdocdir)s/html/')
%(thistestdir)s %(testdir)/%(name)s-%(version)s (/var/conary/tests/<name>-<version> on most Linux systems) This is a location in the test suite directory that contains test data specific to your package, using the name and version variables from your package recipe in the subdirectory name.
r.Replace(('^#!example', '#!%(thistestdir)s/example')
%(userinfodir)s %(sysconfdir)s/conary/userinfo (/etc/conary/userinfo on most Linux systems) This location has Conary user info used to provide user information to info recipes (see Creating System Users and Groups with Info Packages at docs.rpath.com/conary).
r.Install('jqsample', '%(userinfodir)s/')
%(x11prefix)s %(exec_prefix)s/X11R6 (/usr/X11R6 in most Linux systems) This is the installation location for X11.
r.MakeDirs('%(x11prefix)s/lib/X11/app-defaults')

5.4.2 Executable and Option Macros

Executable and option macros expand to the commands and/or options you might use. The default values for these macros are commands and options common on most Linux systems, and which you might use to direct a package build on your build system. Use the following executable and option macros in your recipes where appropriate:

Table 5.10. Executable and Option Macros

MacroDefault ValueWhat This Represents
%(cc)s gcc C compiler
%(cxx)s g++ C++ compiler
%(cxxflags)s (no default value) Flags specific to %(cxx)s
%(cflags)s %(optflags)s %(dbgflags)s Combined C compiler optimization and debug flags
%(cppflags)s (no default value) C-processor options
%(dbgflags)s -g Assembly of %(cflags)s and %(cppflags)s macros
%(debugedit)s debugedit Utility for generating debuginfo files
%(optflags)s -O2 C compiler optimization options
%(os)s linux Operating system
%(ldflags)s %(dbgflags)s Linker flags
%(mflags)s (no default value) make flags
%(monodis)s %(bindir)s/monodis Utility for determining Mono dependencies
%(parallelmflags)s (no default value) parallel make flags
%(strip)s eu-strip Method for stripping symbols from object files (macro not typically used explicitly)
%(strip_archive)s strip -g Method for stripping debugging symbols from object files (macro not typically used explicitly)
%(sysroot)s (no default value) Alternate system root for libraries and executables when cross-compiling

5.4.3 Build and Cross-compile Macros

Build-time macros expand to complete certain Conary configuration information. You should never reset these macros in your recipe. Cross-compile macros expand to useful strings used when cross-compiling, meaning that the recipe is packaging from source and needs to compile that source for a target platform does not resemble your build system (such as embedded systems).

Use the following build-time and cross-compile macros in your recipe where appropriate:

Table 5.11. Build-time Macros

MacroDefault ValueUsage Tips and Examples
%(major_version)s same value as %(version)s Isolates the major version fo software from the Conary-provided version value based on expected structure of that version. In Python, the operation performed on the version is '.'.join(r.version.split('.')[0,2]). This prevents the copy/paste issues from recipe to recipe and allows easier maintenance for those unfamiliar with Python.
%(buildbranch)s (no default value) Repository branch associated with the package or group you're building
/example.rpath.org@corp:example-1-devel//example-1/
%(buildlabel)s (no default value) Label of the branch associated with the package or group you're building
example.rpath.org@corp:example-1

Table 5.12. Cross-compile Macros

MacroDefault ValueUsage Tips and Examples
%(buildcc)s %(cc)s This is the C compiler that will create executables that you can use on the build system's architecture
r.Run('%(buildcc)s %(optflags)s -o foo foo.c')
%(buildcxx)s %(cxx)s This is the C++ compiler that will create executables that you can use on the build system's architecture
r.Configure(buildconf, bootstrapFlags=, preConfigure='CC=%(buildcc)s CXX=%(buildcxx)s')
%(build)s %(buildarch)s-%(buildvendor)s-%(buildos)s This is the combined macro that includes values related to the build system. This is used to define values in the %(buildcc)s macro.
%(buildos)s ulinux This is the build system's operating system. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(buildvendor)s unknown This is the build system's vendor. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(host)s %(hostarch)s-%(hostvendor)s-%(hostos)s This is the combined macro that includes values related to the host system. This is used to define values in the %(buildcc)s macro.
%(hostos)s linux This the operating system of the host system, where the compiled application will run. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(hostvendor)s unknown This the vendor of the host system, where the compiled application will run. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(target)s %(targetarch)s-%(targetvendor)s-%(targetos)s This is the combined macro that includes values related to the target system. This is used to define values in the %(buildcc)s macro.
%(targetos)s linux This the operating system of the target system, where your completed package or group will be installed and managed. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(targetvendor)s unknown This the vendor of the target system, where your completed package or group will be installed and managed. This is not specified explicitly, but rather used to define values in the %(buildcc)s macro.
%(crossdir)s cross-target-%(target)s This is the cross-compiling tools installation directory.
%(crossprefix)s /opt/%(crossdir)s The cross-compiler location with directory prefix.
%(crossprefix)s might expand to something like /opt/cross-target-x86_64
%(headerpath)s %(sysroot)s/%(includedir)s This is the location of the cross-compile target header files.
%(headerpaths)s might expand to something like /opt/cross-target-x86_64/sys-root/usr/include
%(sysroot)s %(crossprefix)s/sys-root This is the location of cross-compiled libraries and executables.
%(sysroot)s might expand to something like /opt/cross-target-x86_64/sys-root