Created
March 25, 2019 15:24
-
-
Save Silur/9d89cc1438d940d918cbdab731159554 to your computer and use it in GitHub Desktop.
my template makefile
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
.POSIX: | |
.SUFFIXES: | |
CC = gcc | |
LIB_CFLAGS = -pedantic -Wall -Wextra -fPIC | |
LIB_CFLAGS += -DFORTIFY_SOURCE=2 -fstack-protector-strong | |
LIB_LDFLAGS = -shared -fPIC -Wl,-z,relro,-z,now | |
BIN_CFLAGS = -pedantic -Wall -Wextra -fPIE | |
BIN_CFLAGS += -DFORTIFY_SOURCE=2 -fstack-protector-strong | |
BIN_LDFLAGS = -L. -fPIE -Wl,-z,relro,-z,now | |
all: lib bin | |
lib: foo.o | |
$(CC) -o foo.so $(LIB_CFLAGS) $^ $(LIB_LDFLAGS) | |
bin: main.o | |
$(CC) -o foo $(BIN_CFLAGS) $^ $(BIN_LDFLAGS) | |
main.o: main.c | |
$(CC) -c $(BIN_CFLAGS) $< | |
debug: LIB_CFLAGS += -DDEBUG -g3 -fsanitize=address -fno-omit-frame-pointer | |
debug: LIB_LDFLAGS += -static-libasan | |
debug: BIN_CFLAGS += -DDEBUG -g3 -fsanitize=address -fno-omit-frame-pointer | |
debug: BIN_LDFLAGS += -lasan | |
#debug: LIB_CFLAGS += -DDEBUG -g3 -fsanitize=thread -fno-omit-frame-pointer | |
#debug: LIB_LDFLAGS += -DDEBUG -ltsan | |
debug: all | |
test: debug | |
CC=$(CC) ./test.sh | |
clean: | |
rm -f *.o *.so *.gcov *.gcda *.gcno foo; \ | |
find ./test ! -name '*.c' -type f -exec rm -f {} + | |
.SUFFIXES: .c .o | |
.c.o: | |
$(CC) -c $(LIB_CFLAGS) $< | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment