Skip to content

Instantly share code, notes, and snippets.

@zed
Last active December 31, 2015 11:49
Show Gist options
  • Select an option

  • Save zed/7982358 to your computer and use it in GitHub Desktop.

Select an option

Save zed/7982358 to your computer and use it in GitHub Desktop.
Makefile template for a simple C project
NAME := $(patsubst %.c,%,$(wildcard *.c))
CC := gcc -std=c89
CFLAGS = -pedantic -Wall \
-Wno-missing-braces -Wextra -Wno-missing-field-initializers -Wformat=2 \
-Wswitch-default -Wswitch-enum -Wcast-align -Wpointer-arith \
-Wbad-function-cast -Wstrict-overflow=5 -Wstrict-prototypes -Winline \
-Wundef -Wnested-externs -Wcast-qual -Wshadow -Wunreachable-code \
-Wlogical-op -Wfloat-equal -Wstrict-aliasing=2 -Wredundant-decls \
-Wold-style-definition -Werror \
-ggdb3 \
-O0 \
-fno-omit-frame-pointer -ffloat-store -fno-common -fstrict-aliasing \
-lm
.PHONY: clean check-syntax
# Recommended gcc warning options for C, from:
# http://stackoverflow.com/a/1667114
%-debug: %.c
$(CC) $(CFLAGS) -o $@ $^
%: %.c
$(CC) -pedantic -O3 -DNDEBUG -flto -o $@ $^
check-syntax:
$(CC) -c $(CFLAGS) $(CHK_SOURCES)
clean:
rm ./$(NAME) ./$(NAME)-debug -f
# $@ - current target
# $* '%'-part (works if there *is* '%' in specification)
# $< first dependence
# $^ all dependencies (without duplicates)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment