Last active
December 31, 2015 11:49
-
-
Save zed/7982358 to your computer and use it in GitHub Desktop.
Makefile template for a simple C project
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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