Changes between Initial Version and Version 1 of CaffeinatedMake


Ignore:
Timestamp:
01/18/11 13:26:30 (13 years ago)
Author:
jdreed
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • CaffeinatedMake

    v1 v1  
     1The `rules` file in a Debian package uses GNU Make syntax.  Most `make` syntax is straightforward, but there are several places where it differs from shell syntax. 
     2 
     3== Tabs vs Spaces == 
     4 
     5In Makefiles, tabs are used to delineate rules inside a target (see below).  When intending code (within a conditional, for example), use spaces, not tabs.   Emacs can either make this simple or more confusing.  If you get lost, or get weird syntax errors, try `M-x whitespace-mode` in Emacs, which will represent spaces as "·" and tabs as "»" 
     6 
     7== Targets == 
     8 
     9Makefiles primarily contain "targets", which specify what actions to take to build a certain component of the package.  You generally don't care about the names of rules, with some exceptions: 
     10 
     11 * `common-build-indep` 
     12 * `clean` 
     13 
     14When referring to targets like these, you use a double-colon after the target name.  (TODO: explain why, or is that out of scope?) 
     15 
     16When creating your own targets, you use single colons. 
     17 
     18== Variables == 
     19 
     20Variable names are generally in all caps by convention. 
     21 
     22`FOO = bar` 
     23 
     24would set variable FOO to bar. 
     25 
     26You can append to a variable with += 
     27 
     28`FOO += baz` 
     29 
     30Variable FOO now contains "bar baz". 
     31 
     32To refer to variables, you enclose them with parens and a dollar sign: 
     33 
     34$(FOO) 
     35 
     36== Functions == 
     37 
     38Functions in make are called with $(function argument0 argument1).   
     39 
     40=== Common Functions === 
     41 
     42The `shell` function allows you to run a shell command and returns the output. 
     43 
     44ARCH = $(shell uname -m)  
     45 
     46would set ARCH to the hardware type. 
     47 
     48The `wildcard` function is a shell function that supports globbing, but also can be used to test for files.  For example, `$(wildcard /etc/gdm/gdm.conf-custom)` could be used to test for the presence of that file on the build system.  You can compare its output against the empty string to see if the file is absent. 
     49 
     50== Conditionals == 
     51 
     52The most common conditionals are ifeq and ifneq which test for equality and inequality, respectively.  Using the ARCH variable from the example above, you could do the following: 
     53 
     54{{{ 
     55ifeq ($(shell uname -m),x86_64) 
     56        #  do 64-bit stuff 
     57else 
     58        #  do something else 
     59endif 
     60}}} 
     61 
     62As in most languages, the `else` clause is optional. 
     63