Difference between revisions of "Make"

From Christoph's Personal Wiki
Jump to: navigation, search
(PATH)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{lowercase|title=make}}
 
 
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 "<code>makefile</code>" or (later) "<code>Makefile</code>", which tells make all the files and other tools involved in generating the final output file (or files).
 
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 "<code>makefile</code>" or (later) "<code>Makefile</code>", which tells make all the files and other tools involved in generating the final output file (or files).
  
== PATH ==
+
Most of the article will disuces the '''GNU Make''' (or '''gmake''') version.
 +
 
 +
==Introduction==
 +
'''gmake''' is a system which allows one to automate tasks. In many cases, doing something involves several steps, such as converting files, calculating something, and making a graphic file of it all. When using gmake, one specifies what kind of file one wishes to end up with, and the computer figures out what steps need to be done to get to that point. For an example, one could have a [[genbank]] file and would only want the [[fasta]] sequence of the genome. If the file is named "foo.gbk", then one could use gmake to get the fasta sequence: execute "<code>gmake foo.fsa</code>" (i.e., replace the ending with what one wants to end up with).
 +
 
 +
==PATH==
 
You can store all of your personal makefiles in a single directory (e.g. <code>/home/bob/makefiles</code>) and set the environment variable <code>MAKFILES</code> to call these. Note that the make ''file'' itself, with the absolute path must be set in the environment, ''not'' just the path.
 
You can store all of your personal makefiles in a single directory (e.g. <code>/home/bob/makefiles</code>) and set the environment variable <code>MAKFILES</code> to call these. Note that the make ''file'' itself, with the absolute path must be set in the environment, ''not'' just the path.
  
Line 13: Line 17:
 
  include /home/bob/makefiles/foo.mk
 
  include /home/bob/makefiles/foo.mk
  
== Functions (built-in) ==
+
==Functions (built-in)==
 
* Here is a summary of the <tt>gmake</tt> built-in functions (see [http://www.gnu.org/software/make/manual/html_node/Functions.html Functions]):
 
* Here is a summary of the <tt>gmake</tt> built-in functions (see [http://www.gnu.org/software/make/manual/html_node/Functions.html Functions]):
  
Line 48: Line 52:
 
; <code>$(value var)</code> : Evaluates to the contents of the variable var, with no expansion performed on it
 
; <code>$(value var)</code> : Evaluates to the contents of the variable var, with no expansion performed on it
  
== Example makefile ==
+
==Example makefile==
 
''Note: A random mix of stuff for examples.''
 
''Note: A random mix of stuff for examples.''
 
<pre>
 
<pre>
Line 94: Line 98:
 
</pre>
 
</pre>
  
== Useful utilities ==
+
==Useful utilities==
=== Core ===
+
===Core===
 
  cat cmp cp diff echo egrep expr false grep install-info
 
  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
 
  ln ls mkdir mv pwd rm rmdir sed sleep sort tar test touch true
=== Extended ===
+
===Extended===
 
  [ basename bash cat chgrp chmod chown cmp cp dd diff echo
 
  [ basename bash cat chgrp chmod chown cmp cp dd diff echo
 
  egrep expand expr false fgrep find getopt grep gunzip gzip
 
  egrep expand expr false fgrep find getopt grep gunzip gzip
Line 105: Line 109:
 
  test touch true uname xargs yes
 
  test touch true uname xargs yes
  
== External links ==
+
==See also==
* [http://www.gnu.org/software/make/manual/html_node/index.html The GNU make manual]
+
*[[Autoconf]]
* [[wikipedia:make]]
+
 
 +
==External links==
 +
*[http://www.gnu.org/software/make/manual/html_node/index.html The GNU make manual]
 +
*[http://biowiki.org/MakefileManifesto MakefileManifesto] &mdash; on biowiki.org
 +
*[[wikipedia:make]]
  
 
[[Category:Scripting languages]]
 
[[Category:Scripting languages]]

Latest revision as of 03:38, 1 October 2009

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.

Introduction

gmake is a system which allows one to automate tasks. In many cases, doing something involves several steps, such as converting files, calculating something, and making a graphic file of it all. When using gmake, one specifies what kind of file one wishes to end up with, and the computer figures out what steps need to be done to get to that point. For an example, one could have a genbank file and would only want the fasta sequence of the genome. If the file is named "foo.gbk", then one could use gmake to get the fasta sequence: execute "gmake foo.fsa" (i.e., replace the ending with what one wants to end up with).

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