Skip to content

Commit

Permalink
Support CFLAGS and LDFLAGS in Makefile, and reformat the Makefile to …
Browse files Browse the repository at this point in the history
…fit in 80 cols
  • Loading branch information
camgunz committed Mar 29, 2022
1 parent 74327c2 commit a8b526e
Showing 1 changed file with 39 additions and 19 deletions.
58 changes: 39 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
CC ?= gcc
CLANG ?= clang

CFLAGS ?= -Werror -Wall -Wextra -funsigned-char -fwrapv -Wconversion -Wno-sign-conversion -Wmissing-format-attribute -Wpointer-arith -Wformat-nonliteral -Winit-self -Wwrite-strings -Wshadow -Wenum-compare -Wempty-body -Wparentheses -Wcast-align -Wstrict-aliasing --pedantic-errors
EXTRA_CFLAGS ?= -Werror -Wall -Wextra -funsigned-char -fwrapv -Wconversion \
-Wno-sign-conversion -Wmissing-format-attribute \
-Wpointer-arith -Wformat-nonliteral -Winit-self \
-Wwrite-strings -Wshadow -Wenum-compare -Wempty-body \
-Wparentheses -Wcast-align -Wstrict-aliasing --pedantic-errors
CMPCFLAGS ?= -std=c89 -Wno-c99-extensions
TESTCFLAGS ?= -std=c99 -Wno-error=deprecated-declarations -Wno-deprecated-declarations -O0
TESTCFLAGS ?= -std=c99 -Wno-error=deprecated-declarations \
-Wno-deprecated-declarations -O0
NOFPUTESTCFLAGS ?= $(TESTCFLAGS) -DCMP_NO_FLOAT

ADDRCFLAGS ?= -fsanitize=address
MEMCFLAGS ?= -fsanitize=memory -fno-omit-frame-pointer -fno-optimize-sibling-calls
MEMCFLAGS ?= -fsanitize=memory -fno-omit-frame-pointer \
-fno-optimize-sibling-calls
UBCFLAGS ?= -fsanitize=undefined

.PHONY: all clean test coverage
Expand Down Expand Up @@ -38,43 +44,57 @@ unittest: cmptest
@./cmptest

cmp.o:
$(CC) $(CFLAGS) $(CMPCFLAGS) -fprofile-arcs -ftest-coverage -g -I. -c cmp.c
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CMPCFLAGS) \
-fprofile-arcs -ftest-coverage -g -I. -c cmp.c

cmpprof: cmp.o
$(CC) $(CFLAGS) $(TESTCFLAGS) -fprofile-arcs -I. \
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(TESTCFLAGS) $(LDFLAGS) \
-fprofile-arcs -I. \
-o cmpprof cmp.o test/profile.c test/tests.c test/buf.c test/utils.c \
-lcmocka -lprofiler

cmptest: cmp.o
$(CC) $(CFLAGS) $(TESTCFLAGS) -fprofile-arcs -ftest-coverage -g -I. \
-o cmptest cmp.o test/test.c test/tests.c test/buf.c test/utils.c -lcmocka
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(TESTCFLAGS) $(LDFLAGS) \
-fprofile-arcs -ftest-coverage -g -I. \
-o cmptest cmp.o test/test.c test/tests.c test/buf.c test/utils.c \
-lcmocka

cmpnofloattest: cmp.o
$(CC) $(CFLAGS) $(NOFPUTESTCFLAGS) -fprofile-arcs -ftest-coverage -g -I. \
-o cmpnofloattest cmp.o test/test.c test/tests.c test/buf.c test/utils.c \
$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(NOFPUTESTCFLAGS) $(LDFLAGS) \
-fprofile-arcs -ftest-coverage -g -I. \
-o cmpnofloattest cmp.o test/test.c test/tests.c test/buf.c \
test/utils.c \
-lcmocka

clangcmp.o:
$(CLANG) $(CFLAGS) $(CMPCFLAGS) -fprofile-arcs -ftest-coverage -g -I. \
-c cmp.c -o clangcmp.o
$(CLANG) $(CFLAGS) $(EXTRA_CFLAGS) $(CMPCFLAGS) \
-fprofile-arcs -ftest-coverage -g -I. -c cmp.c -o clangcmp.o

cmpaddrtest: clangcmp.o clean
$(CLANG) $(CFLAGS) $(TESTCFLAGS) $(ADDRCFLAGS) -I. -o cmpaddrtest cmp.c \
test/test.c test/tests.c test/buf.c test/utils.c -lcmocka
$(CLANG) $(CFLAGS) $(EXTRA_CFLAGS) $(TESTCFLAGS) $(ADDRCFLAGS) $(LDFLAGS) \
-I. -o cmpaddrtest \
cmp.c test/test.c test/tests.c test/buf.c test/utils.c \
-lcmocka

cmpmemtest: clangcmp.o clean
$(CLANG) $(CFLAGS) $(TESTCFLAGS) $(MEMCFLAGS) -I. -o cmpmemtest cmp.c \
test/test.c test/tests.c test/buf.c test/utils.c -lcmocka
$(CLANG) $(CFLAGS) $(EXTRA_CFLAGS) $(TESTCFLAGS) $(MEMCFLAGS) $(LDFLAGS) \
-I. -o cmpmemtest \
cmp.c test/test.c test/tests.c test/buf.c test/utils.c \
-lcmocka

cmpubtest: clangcmp.o clean
$(CLANG) $(CFLAGS) $(TESTCFLAGS) $(UBCFLAGS) -I. -o cmpubtest cmp.c \
test/test.c test/tests.c test/buf.c test/utils.c -lcmocka
$(CLANG) $(CFLAGS) $(EXTRA_CFLAGS) $(TESTCFLAGS) $(UBCFLAGS) $(LDFLAGS) \
-I. -o cmpubtest \
cmp.c test/test.c test/tests.c test/buf.c test/utils.c \
-lcmocka

example1:
$(CC) $(CFLAGS) --std=c89 -O3 -I. -o example1 cmp.c examples/example1.c
$(CC) $(EXTRA_CFLAGS) --std=c89 -O3 -I. -o example1 \
cmp.c examples/example1.c

example2:
$(CC) $(CFLAGS) --std=c89 -O3 -I. -o example2 cmp.c examples/example2.c
$(CC) $(EXTRA_CFLAGS) --std=c89 -O3 -I. -o example2 \
cmp.c examples/example2.c

coverage:
@rm -f base_coverage.info test_coverage.info total_coverage.info
Expand Down

0 comments on commit a8b526e

Please sign in to comment.