Difference between revisions of "Make"

From Christoph's Personal Wiki
Jump to: navigation, search
Line 105: Line 105:
 
  mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
 
  mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
 
  test touch true uname xargs yes
 
  test touch true uname xargs yes
 +
 +
==See also==
 +
*[[Autoconf]]
  
 
==External links==
 
==External links==

Revision as of 02:10, 25 August 2007

In computing, make is a utility that automates the process of generating ("making") a file (or files). The make is most commonly used to generate an application. For each application, a programmer writes a file named "makefile" or (later) "Makefile", which tells make all the files and other tools involved in generating the final output file (or files).

Most of the article will disuces the GNU Make (or gmake) version.

PATH

You can store all of your personal makefiles in a single directory (e.g. /home/bob/makefiles) and set the environment variable MAKFILES to call these. Note that the make file itself, with the absolute path must be set in the environment, not just the path.

For an example, in bash you would add the following to your ~/.bashrc file:

export MAKEFILES=/home/bob/makefiles/makefile 

where makefile is your "master" makefile.

You can then call sub-makefiles (or dependencies) by adding their absolute path and filename to your master makefile:

include /home/bob/makefiles/Makeconfig
include /home/bob/makefiles/foo.mk

Functions (built-in)

  • Here is a summary of the gmake built-in functions (see Functions):
$(subst from,to,text) 
Replace from with to in text
$(patsubst pattern,replacement,text) 
Replace words matching pattern with replacement in text
$(strip string) 
Remove excess whitespace characters from string
$(findstring find,text) 
Locate find in text
$(filter pattern...,text) 
Select words in text that match one of the pattern words
$(filter-out pattern...,text) 
Select words in text that do not match any of the pattern words
$(sort list) 
Sort the words in list lexicographically, removing duplicates
$(word n,text) 
Extract the nth word (one-origin) of text
$(words text) 
Count the number of words in text
$(wordlist s,e,text) 
Returns the list of words in text from s to e
$(firstword names...) 
Extract the first word of names
$(lastword names...) 
Extract the last word of names
$(dir names...) 
Extract the directory part of each file name
$(notdir names...) 
Extract the non-directory part of each file name
$(suffix names...) 
Extract the suffix (the last '.' and following characters) of each file name
$(basename names...) 
Extract the base name (name without suffix) of each file name
$(addsuffix suffix,names...) 
Append suffix to each word in names
$(addprefix prefix,names...) 
Prepend prefix to each word in names
$(join list1,list2) 
Join two parallel lists of words
$(wildcard pattern...) 
Find file names matching a shell file name pattern (not a '%' pattern)
$(realpath names...) 
For each file name in names, expand to an absolute name that does not contain any ., .., nor symlinks
$(abspath names...) 
For each file name in names, expand to an absolute name that does not contain any . or .. components, but preserves symlinks
$(error text...) 
When this function is evaluated, make generates a fatal error with the message text
$(warning text...) 
When this function is evaluated, make generates a warning with the message text
$(shell command) 
Execute a shell command and return its output
$(origin variable) 
Return a string describing how the make variable variable was defined
$(flavor variable) 
Return a string describing the flavor of the make variable variable
$(foreach var,words,text) 
Evaluate text with var bound to each word in words, and concatenate the results
$(call var,param,...) 
Evaluate the variable var replacing any references to $(1), $(2) with the first, second, etc. param values
$(eval text) 
Evaluate text then read the results as makefile commands. Expands to the empty string
$(value var) 
Evaluates to the contents of the variable var, with no expansion performed on it

Example makefile

Note: A random mix of stuff for examples.

SHELL   = /bin/sh

AWK     = awk
SED     = sed
RM      = rm

# Clear out pre-defined suffixes
.SUFFIXES:
.SUFFIXES:      .seg .pdb .dat .log

%.seg:  %.log
        $(SED) -n '/^[0-9]/{n;p;}' $< | \
        $(SED) -e 's/  [0-9].*\.\(.*\)//' >$@

SEG     = 01 02 03 04 05

%.seg.s:        %.seg
        for n in $(SEG);\
        do \
        head -$$n $< | \
        tail -1 | \
        $(SED) 's/[)|;]/\n/g' - | \
        head -$$n | \
        $(SED) 's/[(('$(CH)':)| ]//g' - | \
        $(SED) 's/-/\t/g' - | \
        sort -nk1 - | \
        $(SED) = - | $(SED) 'N;s/\n/\t/' >$@$$n ;\
        done

show:
        @echo "***************************************"
        @echo SED       = $(SED)

LIST = one two three
blah:
        @for i in $(LIST); do \
                echo $$i; \
        done

clean:
        $(RM) *.seg.s*

Useful utilities

Core

cat cmp cp diff echo egrep expr false grep install-info
ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true

Extended

[ basename bash cat chgrp chmod chown cmp cp dd diff echo
egrep expand expr false fgrep find getopt grep gunzip gzip
hostname install install-info kill ldconfig ln ls md5sum
mkdir mkfifo mknod mv printenv pwd rm rmdir sed sort tee
test touch true uname xargs yes

See also

External links