genmake
simple makefile generator
The genmake script is a simple bash script for generation of Makefile's
based on C/C++ source code files in current directory, using gcc -MM.
The genmake script supports:
- executables, static libraries, and dynamic link libraries, based on the output file format,
- automatic increment of build number on each build (the header file including the version and build number is automatically generated),
- several build targets - debug, debug profile, release, release profile,
- simple way to specify additional flags passed to compiler,
- passing list of link libraries used for build,
- selectively excluding files from build, and more...
Source code
View genmake.sh - download genmake.sh (18.59 kB)
Documentation
Introduction
The usage info is also available via genmake.sh -h.
Requirements
- The script requires gcc, bash, ls, and mkdir.
- For make profile target, gprof, gprof2dot.py, and dot (graphwiz) are required.
- For make debug target, gdb is required.
- For automatic build number increment, awk is required.
Details
Usage:
genmake.sh [options] exec
The resulting Makefile is printed to
stdout.
genmake currently supports building of executables,
static libraries, and shared libraries. This choice is done based on format of exec parameter.
- exec
name of the output binary file to build
Options:
- -h
- --help
Prints this help message.
- -s
Silent mode. On default, genmake script prints out some info about selected
configuration to stderr, this switch prevents this.
- -t target
Build target. genmake supports targets d, dp, r, rp:
- debug
- debug profile
- release (default)
- release profile
For profile targets, make profile command is included, that creates
profile.txt using gprof(1), and profile.png using gprof2dot.py
script and dot.
- -f flags
Additional flags to pass to compiler.
- -l libs
Link libraries. Use -l 'mylib urlib' for '-lmylib -lurlib'.
- -c compiler
Select compiler. Default is g++.
- -bn
Enable build number. If selected, genmake will create BuildNum.h header
file, if it does not exist yet, and will include script to automatically increment
the build number on each build.
- -od dir_name
Output directory. genmake chooses name of output directory based on the selected
build target, and creates the directory. This switch allows you to override this.
- -exc files
List of files excluded from build. E.g. -exc 'file1.cpp file2.cpp'.
- -par parameters
Run parameters for the executable. genmake includes make run and make debug
for executables, for executing and debugging using gdb(1). Here you can provide
any parameters to the executable for these purposes.
- -post command
Provide any command that should be executed as a post-build step. E.g.
-post 'echo We are done...' (single quotes). Command itself is not
echoed by the make.