Programming - Make - Custom Rules

Default rule

hello : hello.c
  gcc -g -O hello.c

% : %.c
  $(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@

NOTE:

  • The % (percent signs) match anything.
  • The $< gets the name of the first (and in this case, only) prerequisite which is hello.c.
  • The $@ variable gives you the name of the target (hello, for this example).

There are many more variables available.