-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
70 lines (54 loc) · 1.85 KB
/
Copy pathMakefile
File metadata and controls
70 lines (54 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
NAME := libgetarg.a
SRCS := src/parse.c src/find_opt.c \
src/handle_opt.c src/handle_help.c \
src/error.c src/tokenizer.c
OBJSDIR := build
OBJS := $(patsubst src/%.c,$(OBJSDIR)/%.o,$(SRCS))
HEADER := include/getarg/getarg.h \
include/getarg/getarg_structures.h \
include/getarg/getarg_internal.h \
include/getarg/getarg_error.h \
include/getarg/getarg_token.h
CC := cc
CFLAGS := -Wall -Wextra -Werror
INCLUDE := -I include
AR := ar rcs
RM := rm -rf
PREFIX ?= /usr/local
DESTDIR ?=
INCDIR := $(DESTDIR)$(PREFIX)/include/getarg
LIBDIR := $(DESTDIR)$(PREFIX)/lib
TEST_SRCS := test/test_tokenizer.c test/test_getarg_parse.c
TEST_BIN := $(OBJSDIR)/unit_tests.c
CRITERION_FLAGS := $(shell pkg-config --cflags --libs criterion)
all: $(NAME)
$(NAME): $(OBJS)
$(AR) $(NAME) $(OBJS)
$(OBJSDIR)/%.o: src/%.c $(HEADER) | $(OBJSDIR)
$(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@
$(OBJSDIR):
mkdir -p $(OBJSDIR)
clean:
$(RM) $(OBJSDIR)
fclean: clean
$(RM) $(NAME)
re: fclean all
test_and_report: $(NAME) | $(OBJSDIR)
@$(CC) -fsanitize=address $(CRITERION_FLAGS) $(CFLAGS) $(INCLUDE) -I./test $(TEST_SRCS) $(SRCS) -o $(TEST_BIN)
@ASAN_OPTIONS=abort_on_error=1 ./$(TEST_BIN) > $(OBJSDIR)/test.log 2>&1; status=$$?; \
cat $(OBJSDIR)/test.log; \
if [ $$status -ne 0 ]; then ./scripts/report_crash.sh $$status $(OBJSDIR)/test.log; fi; \
exit $$status
test: $(NMAE) | $(OBJSDIR)
@$(CC) -fsanitize=address $(CRITERION_FLAGS) $(CFLAGS) $(INCLUDE) -I./test $(TEST_SRCS) $(SRCS) -o $(TEST_BIN)
@ASAN_OPTIONS=abort_on_error=1 ./$(TEST_BIN)
install: $(NAME)
install -d $(INCDIR)
install -d $(LIBDIR)
install -m 644 $(HEADER) $(INCDIR)
install -m 644 $(NAME) $(LIBDIR)
uninstall:
rm -f $(LIBDIR)/$(NAME)
rm -f $(INCDIR)/*.h
rmdir -p --ignore-fail-on-non-empty $(INCDIR)
.PHONY: all clean fclean re test test_and_report install uninstall