ct-create-makefile¶
Generate Makefile from compiletools magic¶
- Author:
- Date:
2024-11-24
- Version:
10.0.6
- Manual section:
1
- Manual group:
developers
SYNOPSIS¶
ct-create-makefile [options] [–dynamic lib.cpp] [–static lib.cpp] [–tests test.cpp] filename.cpp
DESCRIPTION¶
ct-create-makefile generates a Makefile from compiletools magic comments and automatic dependency detection. This is the underlying tool used by ct-cake and the ct-build shell scripts.
Unlike ct-cake, which generates and immediately executes the build,
ct-create-makefile only generates the Makefile. This is useful when you need
to customize the Makefile or inspect the generated rules. For other build
system formats, use ct-cake --backend=<name> (choices: ninja, cmake,
bazel, shake).
The tool analyzes source files for:
Header dependencies (automatic)
Magic flags (//#LDFLAGS, //#CXXFLAGS, //#PKG-CONFIG, etc.)
Library requirements
OPTIONS¶
- –dynamic LIB.cpp
Build a dynamic/shared library from the specified source file. Multiple –dynamic options can be specified.
- –static LIB.cpp
Build a static library from the specified source file. Multiple –static options can be specified.
- –tests TEST.cpp
Build and register test executables. Multiple –tests options can be specified.
- --makefilename NAME
Name of the generated Makefile. Default: Makefile
- --variant VARIANT
Use the specified build variant (e.g., gcc.debug, gcc.release). Default: blank
- --bindir DIR
Output directory for built binaries. Default: bin/<variant>
- --cas-objdir DIR
Output directory for object files. Default: bin/<variant>/obj
- --file-locking
Enable file locking for faster rebuilds across projects. Uses content-addressable storage with proper locking.
- --no-file-locking
Disable file locking. Default.
- --serialise-tests
Run tests sequentially rather than in parallel.
- --no-serialise-tests
Run tests in parallel. Default.
- --build-only-changed FILES
Only build binaries depending on the specified source or header files. FILES is a space-delimited list of absolute paths to changed files.
- --project-version VERSION
Opt in to
-DCT_PROJECT_VERSION="<version>"injection into CPPFLAGS/CFLAGS/CXXFLAGS. If neither this flag nor--project-version-cmdis set (on CLI, in ct.conf, or via env), no macro is injected.- --project-version-cmd CMD
Command to run to determine project version (e.g., “git describe”). Opts in to
-DCT_PROJECT_VERSIONinjection the same way as--project-version.- --project-name NAME
Opt in to
-DCT_PROJECT_NAME="<name>"injection into CPPFLAGS/CFLAGS/CXXFLAGS. If neither this flag nor--project-name-cmdis set (on CLI, in ct.conf, or via env), no macro is injected.- --project-name-cmd CMD
Command to run to determine project name. The first whitespace-separated token of the command’s stdout is used. Opts in to
-DCT_PROJECT_NAMEinjection the same way as--project-name.- -v, --verbose
Increase output verbosity. Use multiple times for more detail.
- --help, -h
Show help message and exit.
EXAMPLE¶
Generate a Makefile for a simple executable:
ct-create-makefile main.cpp
Generate Makefile and then build:
ct-create-makefile main.cpp
make -j$(nproc)
Generate with a shared library:
ct-create-makefile --dynamic mylib.cpp main.cpp
make
Generate for release variant with file locking:
ct-create-makefile --variant=release --file-locking main.cpp
make
COMPARISON WITH CT-CAKE¶
ct-cake and ct-create-makefile serve different purposes:
ct-cake: All-in-one tool that finds targets, generates build files, and runs the build. Supports multiple backends via
--backend(make, ninja, cmake, bazel, shake). Use for quick builds during development.ct-create-makefile: Only generates a Makefile. Use when you need more control over the Make-based build process or want to inspect and customize the generated Makefile.
The ct-build shell scripts use ct-create-makefile internally:
# ct-build is roughly equivalent to:
ct-create-makefile $(ct-findtargets --style=args) "$@"
make -j$(ct-jobs)
SEE ALSO¶
ct-cake (1), ct-findtargets (1), ct-magicflags (1)