c-multihash/Makefile

75 lines
1.4 KiB
Makefile
Raw Normal View History

2016-11-14 13:11:21 +00:00
DEBUG=true
2016-07-25 10:51:54 +00:00
CC = gcc
RM = rm -f
2016-11-14 13:11:21 +00:00
CFLAGS = -fPIC -O0 -std=c99 \
2016-07-25 10:51:54 +00:00
-Wall -Wextra -pedantic -Werror \
-Wdeclaration-after-statement \
-Wno-format-zero-length \
-Wold-style-definition \
-Woverflow \
-Wpointer-arith \
-Wunused \
-Wvla
2016-11-14 13:11:21 +00:00
ifdef DEBUG
CFLAGS += -g3
endif
2016-07-25 15:18:34 +00:00
LDFLAGS = -g
2016-07-25 10:51:54 +00:00
LDLIBS =
2016-11-14 13:11:21 +00:00
TARGET_LIB = libmultihash.a
TARGET_BIN = multihash
2016-07-25 10:51:54 +00:00
SRCS = src/hashes.c src/errors.c src/multihash.c
2016-07-25 15:18:34 +00:00
OBJS = $(SRCS:.c=.o)
2016-07-25 10:51:54 +00:00
2016-07-26 11:00:54 +00:00
src/%.o: src/%.c
$(CC) $(CFLAGS) -c -I include $< -o $@
2016-07-26 11:00:54 +00:00
2016-11-10 14:29:42 +00:00
all: $(TARGET_LIB)
2016-07-25 10:51:54 +00:00
$(TARGET_LIB): $(OBJS)
ar rcs $@ $^
2016-07-25 15:18:34 +00:00
# Tests
2016-07-25 10:51:54 +00:00
TEST_SRCS = $(wildcard tests/c/test_*.c)
2016-07-25 15:18:34 +00:00
TEST_OBJS = $(TEST_SRCS:.c=.o)
TEST_BINS = $(TEST_OBJS:.o=)
2016-07-25 15:18:34 +00:00
2016-07-26 13:23:03 +00:00
PHONY += test
test: $(TEST_BINS)
@for t in $^; do \
echo; \
echo '***' "$$t.c" '***'; \
"./$$t" || ERROR=1; \
done; \
echo; \
exit $$ERROR
2016-07-25 15:18:34 +00:00
tests/c/test_%.o: tests/c/test_%.c tests/c/minunit.h
$(CC) $(CFLAGS) -c -I include $< -o $@
2016-07-25 15:18:34 +00:00
tests/c/test_%: tests/c/test_%.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $^ -o $@
2016-07-25 15:18:34 +00:00
# Utils
PHONY += clean dist-clean
2016-07-25 10:51:54 +00:00
clean:
$(RM) $(OBJS)
2016-07-25 15:18:34 +00:00
$(RM) $(TEST_BINS)
2016-07-25 10:51:54 +00:00
$(RM) $(TARGET_LIB)
$(RM) $(TARGET_BIN)
2016-07-26 11:00:54 +00:00
$(RM) $(MAIN_O)
2016-07-25 10:51:54 +00:00
dist-clean: clean
PHONY += build
build: all
2016-07-25 15:18:34 +00:00
.PHONY: $(PHONY)