From 6a23dbd54d601c5bf803d0be592e8244bd086526 Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Tue, 26 Jul 2016 12:00:54 +0100 Subject: [PATCH] separate headers and src --- .gitignore | 4 +--- Makefile | 13 ++++++++++--- include/mh/.gitignore | 2 ++ errors.h => include/mh/errors.h | 0 hashes.c => include/mh/hashes.h | 4 ++-- src/.gitignore | 1 + errors.c => src/errors.c | 2 +- hashes.h => src/hashes.c | 2 +- main.c => src/main.c | 2 +- tests/c/test_error_string.c | 2 +- 10 files changed, 20 insertions(+), 12 deletions(-) create mode 100644 include/mh/.gitignore rename errors.h => include/mh/errors.h (100%) rename hashes.c => include/mh/hashes.h (95%) create mode 100644 src/.gitignore rename errors.c => src/errors.c (96%) rename hashes.h => src/hashes.c (62%) rename main.c => src/main.c (87%) diff --git a/.gitignore b/.gitignore index bed6bdf..c4d2da9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,5 @@ * !.gitignore -!*.c -!*.h !Makefile -!tests +!**/ diff --git a/Makefile b/Makefile index 73d0c37..b61c513 100644 --- a/Makefile +++ b/Makefile @@ -16,15 +16,21 @@ LDLIBS = TARGET_LIB = mulithash.a TARGET_BIN = multihash -SRCS = errors.c hashes.c +MAIN = src/main.c +MAIN_O = $(MAIN:.c=.o) + +SRCS = src/errors.c src/hashes.c OBJS = $(SRCS:.c=.o) +src/%.o: src/%.c + $(CC) $(CFLAGS) -c -I include $^ -o $@ + all: $(TARGET_LIB) $(TARGET_BIN) $(TARGET_LIB): $(OBJS) ar rcs $@ $^ -$(TARGET_BIN): main.o $(TARGET_LIB) +$(TARGET_BIN): $(MAIN_O) $(TARGET_LIB) $(CC) $(LDFLAGS) $^ -o $@ # Tests @@ -42,7 +48,7 @@ tests: $(TEST_BINS) done tests/c/test_%.o: tests/c/test_%.c - $(CC) -c -I. $^ -o $@ + $(CC) $(CFLAGS) -c -I include $^ -o $@ tests/c/test_%: tests/c/test_%.o $(TARGET_LIB) $(CC) $(LDFLAGS) $^ -o $@ @@ -56,6 +62,7 @@ clean: $(RM) $(TEST_BINS) $(RM) $(TARGET_LIB) $(RM) $(TARGET_BIN) + $(RM) $(MAIN_O) dist-clean: clean diff --git a/include/mh/.gitignore b/include/mh/.gitignore new file mode 100644 index 0000000..9e6bde3 --- /dev/null +++ b/include/mh/.gitignore @@ -0,0 +1,2 @@ +!*.h + diff --git a/errors.h b/include/mh/errors.h similarity index 100% rename from errors.h rename to include/mh/errors.h diff --git a/hashes.c b/include/mh/hashes.h similarity index 95% rename from hashes.c rename to include/mh/hashes.h index 3469a88..1d00ecd 100644 --- a/hashes.c +++ b/include/mh/hashes.h @@ -1,5 +1,5 @@ /* vim: set ts=8 sw=8 noexpandtab: */ - +#include "errors.h" // list of avaliable hash functions. typedef enum { @@ -28,7 +28,7 @@ typedef struct { mh_hash hash; int code; int length; -} mh_hashinfo +} mh_hashinfo; // decodes code info hash info, leaves length field zeroed mh_error mh_hashinfo_from_code(int code, mh_hashinfo *hinfo); diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..970d78f --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +!*.c diff --git a/errors.c b/src/errors.c similarity index 96% rename from errors.c rename to src/errors.c index 3f14e79..6d74946 100644 --- a/errors.c +++ b/src/errors.c @@ -1,5 +1,5 @@ /* vim: set ts=8 sw=8 noexpandtab: */ -#include "errors.h" +#include "mh/errors.h" static const struct mh_error_desc { int code; diff --git a/hashes.h b/src/hashes.c similarity index 62% rename from hashes.h rename to src/hashes.c index 09ddeb8..7be258f 100644 --- a/hashes.h +++ b/src/hashes.c @@ -1,2 +1,2 @@ /* vim: set ts=8 sw=8 noexpandtab: */ - +#include "mh/hashes.h" diff --git a/main.c b/src/main.c similarity index 87% rename from main.c rename to src/main.c index 6de7f52..425f19e 100644 --- a/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ #include -#include "errors.h" +#include "mh/errors.h" int main(void) { printf("%s\n", mh_error_string(MH_E_TOO_LONG)); diff --git a/tests/c/test_error_string.c b/tests/c/test_error_string.c index 2baa875..1334c3c 100644 --- a/tests/c/test_error_string.c +++ b/tests/c/test_error_string.c @@ -1,7 +1,7 @@ #include #include "minunit.h" -#include "errors.h" +#include "mh/errors.h" char error_buf[256];