Tuesday, January 24, 2012

Few Things about Makefile

I read through this article, http://www.opussoftware.com/tutorial/TutMakefile.htm, today. And wrote down some notes.

target : sources
"The target depends on the sources."
: colon are called dependency lines.

The last-changed time is the time as it appears in the file-system directory = timestamp
if timestamp(target) is earlier than timestamp(sources) then build a new one.

include hearder
main.o : main.c def.h
io.o : io.c def.h
main.o io.o : def.h

Shell Lines

  • the  indented lines that follow each dependency line are called shell lines, which tell Make how to build the target.
  • Make checks the shell line exit status. If the first shell line returning a non-zero exit status, it will stop.
  • adding "-" prefix let Make ignore the exit status and continue.
  • macro definition: name = value
  • expressions form: $(name) or ${name}
  • if the name is a single letter, the parentheses or braces are optional, ex. $X
  • defining on the command line:
    • make CFLAGS=-ms
    • (including spaces) make "CFLAGS=-ms -z -p"
  • run-time macros
    • .TARGET is the name of the current target
    • .SOURCES is the name of the inferred source
  • macro modifiers
    • $(name, modifier[,modifier ...]), ex. SRCS = $(OBJS,.o=.c)
    • filename components, if PATH = /home/heron/test.txt
      • D, directory, $(PATH, D) = /home/heron
      • E, extensions, $(PATH, E) = .txt
      • F, file name, $(PATH, F) = test.txt
Conditional Directives
%if $(CC) == gcc
        CC = g++
%elif $(CC) == g++
        CC = gcc
        echo "haha"

For More Info : http://unixhelp.ed.ac.uk/CGI/man-cgi?make