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
|
2016-07-26 09:57:05 +00:00
|
|
|
TARGET_BIN = multihash
|
2016-07-25 10:51:54 +00:00
|
|
|
|
2016-08-01 15:33:32 +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
|
2016-07-27 09:45:53 +00:00
|
|
|
$(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)
|
2016-07-26 09:57:05 +00:00
|
|
|
ar rcs $@ $^
|
|
|
|
|
2016-07-25 15:18:34 +00:00
|
|
|
# Tests
|
2016-07-25 10:51:54 +00:00
|
|
|
|
2016-07-26 09:57:05 +00:00
|
|
|
TEST_SRCS = $(wildcard tests/c/test_*.c)
|
2016-07-25 15:18:34 +00:00
|
|
|
TEST_OBJS = $(TEST_SRCS:.c=.o)
|
2016-07-26 09:57:05 +00:00
|
|
|
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)
|
2016-07-26 15:53:52 +00:00
|
|
|
@for t in $^; do \
|
|
|
|
echo; \
|
|
|
|
echo '***' "$$t.c" '***'; \
|
2016-07-27 09:45:53 +00:00
|
|
|
"./$$t" || ERROR=1; \
|
|
|
|
done; \
|
|
|
|
echo; \
|
2016-07-31 14:42:29 +00:00
|
|
|
exit $$ERROR
|
2016-07-25 15:18:34 +00:00
|
|
|
|
2016-07-27 09:45:53 +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
|
|
|
|
2016-07-26 09:57:05 +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)
|
2016-07-26 09:57:05 +00:00
|
|
|
$(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
|
|
|
|
|
2016-07-26 15:53:52 +00:00
|
|
|
PHONY += build
|
|
|
|
build: all
|
|
|
|
|
2016-07-25 15:18:34 +00:00
|
|
|
.PHONY: $(PHONY)
|