Skip to content

Instantly share code, notes, and snippets.

@csukuangfj
Last active January 18, 2019 05:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save csukuangfj/92b30530d9fd045f22777f5706c0ca0f to your computer and use it in GitHub Desktop.
Save csukuangfj/92b30530d9fd045f22777f5706c0ca0f to your computer and use it in GitHub Desktop.
makefile notes

Table of Contents

Automatic Variables

Implicit Rules and Variables

Use make --print-data-base | less to view impicit rules

Include Path

my_include_path = a b c
my_path = $(addprefix -I,$(my_include_path))
  • my_path is -Ia -Ib -Ic

Substitution

a = feet on the.c stree.ct.c
b = $(patsubst %.c,%.o,$(a))
  • b is feet on the.o stree.ct.o

a = feet on the.c stree.ct.c
b = $(a:.c=.o)
  • b is feet on the.o stree.ct.o

a = feet on the.c stree.ct.c
b = $(subst ee,EE,$(a))
  • b is fEEt on the.c stEE.ct.c

a = feet on the.c stree.ct.c
b = $(subst .c,.o,$(a))
  • b is feet on the.o stEE.ot.o

Environment Variables

foo += bar
  • make, then foo is bar
  • make foo=abc, then foo is abc
  • foo=abc make, then foo is abc bar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment