spmake — simple pattern based make command
spmake [−cfnrv] [−s dir] [−t targetdir] [−p rule] rulename ...
spmake [−fnrv] [−s dir] −T targetdir {−p rule| rulename}
spmake {−l|-V|-h}
spmake is a make(1) like command. It’s simpler because it doesn’t need a config file and supports only single rules. Pattern based means that the source directory is scanned about files which matches the source file extension. For every file matched, it is checked if a corresponding file with target extension exist in the target directory. If it not exist, or the target file is older than the source file, the rule command is run with "%sf" replaced by the name of the source file and "%tf" replaced by the name of the target file.
A pattern or
rule has three parts: A source file extension, a destination
file extension and a command string. Both the source- and
the target extension could be empty, but this requires that
source- and target directories are different. The pattern is
specified as an argument to option -p.
For example
spmake -p ’.md:.html:markdown %sf > %tf’
will run
markdown(1) in the current directory on every file with
extension .md if no .html file exist or if it
has an older modification time.
If the .html files are located in a separate directory, the
name of the directory can be set by option -t.
Beside setting the rule on the commandline, there are some built-in rules which are accessible via it’s name. The option -l print a list of all known rules on stdout.
spmake
-l
cheader 0 .h:.c:touch -c -r %sf %tf
cprog 0 .c::cc -o %tf %sf
backup 0 :.bak:cp %sf %tf
copy 0 ::cp %sf %tf
echo 0 ::echo ’%sf --> %tf’
echo 1 ::echo ’%sf --> %tf’
debug 0 ::echo ’%sf (%sd) --> %tf (%td)’
The copy rule for example, can be used to make a copy of all files in a different directory:
spmake −r −c −s data −t shadow copy
The command copies all (newer) files from the data directory into the shadow directory. Option −c is used to create the target directories if these are not already there. The option −r can be used to copy recursivley the whole tree starting from the source directory.
−l, −−list
Print a list of all built-in rules or rules read from .spmakerc files
−V, −−version
Output version information and exit
−h, −−help
Print a short description of the command options.
−c, −−create
Create target directory if necesssary.
−f, −−force
Force to run command even if the source file is not newer than the target file. In single file mode, the source list contains all files not only the ones which are newer than the target file.
−n, −−noexec
Do not execute commands. This is only useful in verbose mode.
−r, −−recursive
Run spmake(1) in subdirectories recursively
−v, −−verbose
Comment what is done
−s dir, −−srcdir=dir
Specify the source directory. Default is the current directory.
−t dir, −−targetdir=dir
Specify the target directory. Default is the source directory.
−T file, −−targetfile=file
This option runs spmake(1) in single target mode. All matching source files will be compared to this target file. The target extension in the rule is ignored. The rule command must handle multiple input files because "%sf" will be replaced by a list of file names.
−p rulestring, −−pattern=rulestring
Define a pattern rule. The pattern rule has three parts delimited by a colon: A source file extension, a target file extension, and a command string. The source or the target extension could be the empty string. In the command string, the special symbols "%sf", "%tf", "%sd" and "%td" will be replaced by the source file name (or list of file names in single target mode), the target file, the source file timestamp or the target file timestamp in ISO Time format
If option −P is given more than once, they will be added to the list of rules with name r1, r2, r3 etc. and can be referenced by this name later on in the argument list.
If option −T is given, all pattern options specified before will be defined in regular mode, while all options defined after option −T will be defined in single target mode.
The remaining arguments, are the name of rules which should be checked.
Exit
status:
If any file was newer than the target file the exit status
is 0. If nothing has to be done the exit status is 1. An
exit status of 2 or greater indicates an error.
spmake -p
’.md:.html:markdown %sf > %tf’ -p
’.md:.pdf:markdown %sf |
html2pdf > %tf’ -l
0 r1 0 .md:.html:markdown %sf
> %tf
1 r2 0 .md:.pdf:markdown %sf | html2pdf > %tf
2 cheader 0 .h:.c:touch -c -r %sf %tf
3 cprog 0 .c::cc -o %tf %sf
4 backup 0 :.bak:cp %sf %tf
5 copy 0 ::cp %sf %tf
6 echo 0 ::echo ’%sf --> %tf’
7 echo 1 ::echo ’%sf --> %tf’
8 debug 0 ::echo ’%sf (%sd) --> %tf
(%td)’
Print out the
list of known rules (including ones given on the command
line)
spmake backup
For each file
in the current directory create a backup file with extension
".bak".
spmake -c -t backups backup
Same as above
but put the backup files in the directory backups.
spmake cheader cprog
Compile each single C-source file in the current directory into a executable file. If a header file exist, the dependency of this will be honored.
.spmakerc
The local spmake(1) rule file
$HOME/.spmakerc
Your personal spmake(1) rule file
Some of the options are not meaningful in all of the spmake modes.
In single target mode the list of source files can grow easyly to a size larger than the maximum size for the argument list. In this case find(1) and xargs(1) fit probably better your needs.
The source file list in single target mode is unsorted.
For a description of the format of the .spmakerc file have a look at the example file. It should be better described here in the man page.
Written by Holger Zuleger
Copyright (c) 2014 by Holger Zuleger. Licensed under the BSD Licences. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
make(1), find(1), xargs(1)