2016-07-25 10:51:54 +00:00
|
|
|
CC = gcc
|
|
|
|
RM = rm -f
|
|
|
|
CFLAGS = -fPIC -g -O2 -std=c99 \
|
|
|
|
-Wall -Wextra -pedantic -Werror \
|
|
|
|
-Wdeclaration-after-statement \
|
|
|
|
-Wno-format-zero-length \
|
|
|
|
-Wold-style-definition \
|
|
|
|
-Woverflow \
|
|
|
|
-Wpointer-arith \
|
|
|
|
-Wunused \
|
|
|
|
-Wvla
|
|
|
|
|
2016-07-25 15:18:34 +00:00
|
|
|
LDFLAGS = -g
|
2016-07-25 10:51:54 +00:00
|
|
|
LDLIBS =
|
|
|
|
|
2016-07-26 09:57:05 +00:00
|
|
|
TARGET_LIB = mulithash.a
|
|
|
|
TARGET_BIN = multihash
|
2016-07-25 10:51:54 +00:00
|
|
|
|
2016-07-26 11:00:54 +00:00
|
|
|
MAIN = src/main.c
|
|
|
|
MAIN_O = $(MAIN:.c=.o)
|
|
|
|
|
|
|
|
SRCS = src/errors.c src/hashes.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 09:57:05 +00:00
|
|
|
all: $(TARGET_LIB) $(TARGET_BIN)
|
2016-07-25 10:51:54 +00:00
|
|
|
|
|
|
|
$(TARGET_LIB): $(OBJS)
|
2016-07-26 09:57:05 +00:00
|
|
|
ar rcs $@ $^
|
|
|
|
|
2016-07-26 11:00:54 +00:00
|
|
|
$(TARGET_BIN): $(MAIN_O) $(TARGET_LIB)
|
2016-07-26 09:57:05 +00:00
|
|
|
$(CC) $(LDFLAGS) $^ -o $@
|
2016-07-25 10:51:54 +00:00
|
|
|
|
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" '***'; \
|
|
|
|
"./$$t" || printf "\n!!! TEST FAILURE !!!\n"; \
|
2016-07-25 15:18:34 +00:00
|
|
|
done
|
|
|
|
|
2016-07-26 09:57:05 +00:00
|
|
|
tests/c/test_%.o: tests/c/test_%.c
|
2016-07-26 11:00:54 +00:00
|
|
|
$(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)
|