c-multihash/Makefile

75 lines
1.4 KiB
Makefile
Raw Normal View History

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 =
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/hashes.c src/errors.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
all: $(TARGET_LIB) $(TARGET_BIN)
2016-07-25 10:51:54 +00:00
$(TARGET_LIB): $(OBJS)
ar rcs $@ $^
2016-07-26 11:00:54 +00:00
$(TARGET_BIN): $(MAIN_O) $(TARGET_LIB)
$(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
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; \
[ "$${ERROR-0}" -eq "1" ] && exit 1
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)