Skip to content

Instantly share code, notes, and snippets.

@fmela
Created February 17, 2014 23:04
Show Gist options
  • Save fmela/9061043 to your computer and use it in GitHub Desktop.
Save fmela/9061043 to your computer and use it in GitHub Desktop.
C program makefile boilerplate
SOURCES = $(wildcard *.c)
HEADERS = $(wildcard *.h)
OBJECTS = $(SOURCES:%.c=%.o)
PROGRAM = $(shell basename `pwd`)
CC := $(shell which clang || which gcc)
CFLAGS = -Wall -W -O
LIBS =
LDFLAGS = $(LIBS:%=-l%)
$(PROGRAM) : $(OBJECTS)
$(CC) $(LDFLAGS) -o $@ $<
%.o : %.c $(HEADERS)
$(CC) $(CFLAGS) -c -o $@ $<
.PHONY : clean
clean :
rm -f $(PROGRAM) $(OBJECTS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment