| prev | Version 1107 (Mon Nov 27 20:45:57 2006) | next |
gcc -c -Wall -ansi -I/pkg/chempak/include dat2csv.c once is bad enoughMakeMake is freely available for every major platform, and very well documentedMake's syntaxTime: 1.2271 Concentration: 0.0050 Yield: 11.41 Time: 2.5094 Concentration: 0.0055 Yield: 11.20 Time: 3.7440 Concentration: 0.0060 Yield: 10.90
dat2csvhello.mk:hydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv
make -f hello.mkmake -f hello.mk againhydroxyl_422.csv is newer than hydroxyl_422.dat, Make does not run the command again![[Structure of a Make Rule]](./img/build/rule_structure.png)
Figure 6.1: Structure of a Make Rule
hydroxyl_422.csv is the target of the rulehydroxyl_422.dat is its prerequisiteMake runs them on your behalf, just as the shell runs the command you typehydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv methyl_422.csv : methyl_422.dat dat2csv methyl_422.dat > methyl_422.csv
make -f double.mk, only hydroxyl_422.csv is compiledMake will updatemake -f double.mk methyl_422.csv to build methyl_422.csvMake separately for each target would hardly count as “automation”all : hydroxyl_422.csv methyl_422.csv hydroxyl_422.csv : hydroxyl_422.dat dat2csv hydroxyl_422.dat > hydroxyl_422.csv methyl_422.csv : methyl_422.dat dat2csv methyl_422.dat > methyl_422.csv
make -f phony.mk all now creates both .csv filesall depends on hydroxyl_422.csv and methyl_422.csv.dat fileMake's built-in processing cycle:Make can execute actions in any order it wants to, as long as it doesn't violate dependency orderinghydroxyl_422.cv or methyl_422.csv firstallmake with no arguments, it automatically looks for a file called Makefilemake only updates the first one it finds"all": recompile everything"clean": delete all temporary files, and everything produced by compilation"install": copy files to system directoriesmake configuremakemake testmake installMake defines automatic variables to represent parts of rules"$@" | The rule's target |
"$<" | The rule's first prerequisite |
"$?" | All of the rule's out-of-date prerequisites |
"$^" | All prerequisites |
| Table 6.1: Automatic Variables in Make | |
|---|---|
all : hydroxyl_422.csv methyl_422.csv hydroxyl_422.csv : hydroxyl_422.dat @dat2csv $< > $@ methyl_422.csv : methyl_422.dat @dat2csv $< > $@ clean : @rm -f *.csv
Make echoes actions before executing them"@" at the start of the action line prevents thisclean to tidy up generated filesrm -f instead of just rm?all : hydroxyl_422.csv methyl_422.csv %.csv : %.dat @dat2csv $< > $@ clean : @rm -f *.csv
"%" represents the stem of the file's name in the target and prerequisitessummarize to combine data from hydroxyl_422.csv and hydroxyl_480.csvhydroxyl_all.csvall : hydroxyl_all.csv methyl_all.csv %_all.csv : %_422.csv %_480.csv summarize $^ > $@ %.csv : %.dat dat2csv dat2csv $< > $@ clean : @rm -f *.csv
%_all.csv takes precedence over the rule for %.csvMake uses the most specific rule available$ make -f depend.mkdat2csv hydroxyl_422.dat > hydroxyl_422.csvdat2csv hydroxyl_480.dat > hydroxyl_480.csvsummarize hydroxyl_422.csv hydroxyl_480.csv > hydroxyl_all.csvdat2csv methyl_422.dat > methyl_422.csvdat2csv methyl_480.dat > methyl_480.csvsummarize methyl_422.csv methyl_480.csv > methyl_all.csvrm hydroxyl_480.csv methyl_422.csv hydroxyl_422.csv methyl_480.csv
Make automatically removes intermediate files created by pattern rules when it's doneMake is a little programming languageINPUT_DIR = /lab/gamma2100
OUTPUT_DIR = /tmp
all : ${OUTPUT_DIR}/hydroxyl_all.csv ${OUTPUT_DIR}/methyl_all.csv
${OUTPUT_DIR}/%_all.csv : ${OUTPUT_DIR}/%_422.csv ${OUTPUT_DIR}/%_480.csv
@summarize $^ > $@
${OUTPUT_DIR}/%.csv : ${INPUT_DIR}/%.dat
@dat2csv $< > $@
clean :
@rm -f *.csv
"$" in front of the name and parentheses or braces around it$(XYZ) or ${XYZ}Make interprets "$XYZ" as the value of "X", followed by the characters "YZ"Make when invoking itname=value pairs on the command linemake -f macro.mk sets INPUT_DIR to /lab/gamma2100make INPUT_DIR=/newlab -f macro.mk uses /newlabMake also looks at environment variables${HOME} in a Makefile without having defined itVAL = original
echo :
@echo "VAL is" ${VAL}
$ make -f env.mk echoVAL is original$ make VAL=changed -f env.mk echoVAL is changed
addprefix and addsuffix to build a list of filenameshydroxyl into /tmp/hydroxyl_all.csv and methyl into /tmp/methyl_all.csvINPUT_DIR = /lab/gamma2100
OUTPUT_DIR = /tmp
CHEMICALS = hydroxyl methyl
SUMMARIES = $(addprefix ${OUTPUT_DIR}/,$(addsuffix _all.csv,${CHEMICALS}))
all : ${SUMMARIES}
${OUTPUT_DIR}/%_all.csv : ${OUTPUT_DIR}/%_422.csv ${OUTPUT_DIR}/%_480.csv
@summarize $^ > $@
${OUTPUT_DIR}/%.csv : ${INPUT_DIR}/%.dat
@dat2csv $< > $@
clean :
@rm -f *.csv
| Function | Purpose |
|---|---|
$(addprefix prefix,filenames) | Add a prefix to each filename in a list |
$(addsuffix suffix,filenames) | Add a suffix to each filename in a list |
$(dir filenames) | Extract the directory name portion of each filename in a list |
$(filter pattern,text) | Keep words in text that match pattern |
$(filter-out pattern,text) | Keep words in text that don't match pattern |
$(patsubst pattern,replacement,text) | Replace everything that matches pattern in text |
$(sort text) | Sort the words in text, removing duplicates |
$(strip text) | Remove leading and trailing whitespace from text |
$(subst from,to,text) | Replace from with to in text |
$(wildcard pattern) | Create a list of filenames that match a pattern |
| Table 6.2: Commonly-Used Functions | |
echo to print things as Make executesdel or rm to delete files?Ant: primary for Java, but equivalent tools now exist for .NETSConsCruiseControl and BittenExercise 6.1:
Make gets definitions from environment variables,
command-line parameters, and explicit definitions in Makefiles.
What order does it check these in?
| prev | Copyright © 2005-06 Python Software Foundation. | next |