rework build structure for static link

make .gitignore exclude default
move tests into tests/c/
whys-review
Jakub Sztandera 2016-07-26 10:57:05 +01:00
parent 60fa67b590
commit f91684f3c8
7 changed files with 61 additions and 70 deletions

41
.gitignore vendored
View File

@ -1,36 +1,7 @@
# Object files *
*.o
*.ko
*.obj
*.elf
# Precompiled Headers !.gitignore
*.gch !*.c
*.pch !*.h
!Makefile
# Libraries !tests
*.lib
*.a
*.la
*.lo
# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib
# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex
# Debug files
*.dSYM/
*.su
# Build system
.depend

View File

@ -13,34 +13,39 @@ CFLAGS = -fPIC -g -O2 -std=c99 \
LDFLAGS = -g LDFLAGS = -g
LDLIBS = LDLIBS =
TARGET_LIB = mulithash.so TARGET_LIB = mulithash.a
TARGET_BIN = multihash
SRCS = errors.c SRCS = errors.c
OBJS = $(SRCS:.c=.o) OBJS = $(SRCS:.c=.o)
all: ${TARGET_LIB} all: $(TARGET_LIB) $(TARGET_BIN)
$(TARGET_LIB): $(OBJS) $(TARGET_LIB): $(OBJS)
$(CC) -g -shared -o $@ $^ ar rcs $@ $^
$(TARGET_BIN): main.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $^ -o $@
# Tests # Tests
TEST_SRCS = $(wildcard test/test_*.c) TEST_SRCS = $(wildcard tests/c/test_*.c)
TEST_OBJS = $(TEST_SRCS:.c=.o) TEST_OBJS = $(TEST_SRCS:.c=.o)
TEST_BINS = $(TEST_OBJS:.o=.out) TEST_BINS = $(TEST_OBJS:.o=)
PHONY += tests PHONY += tests
tests: $(TEST_BINS) tests: $(TEST_BINS)
@for t in $^; do \ @for t in $^; do \
echo; \ echo; \
echo '***' "$$t" '***'; \ echo '***' "$$t.c" '***'; \
LD_LIBRARY_PATH=. "./$$t"; \ "./$$t"; \
echo; \
done done
tests/c/test_%.o: tests/c/test_%.c
$(CC) -c -I. $^ -o $@
test/test_%.out: test/test_%.o $(TARGET_LIB) tests/c/test_%: tests/c/test_%.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $(TARGET_LIB) $^ -o $@ $(CC) $(LDFLAGS) $^ -o $@
# Utils # Utils
@ -48,9 +53,9 @@ PHONY += clean dist-clean
clean: clean:
$(RM) $(OBJS) $(RM) $(OBJS)
$(RM) $(TEST_OBJS)
$(RM) $(TEST_BINS) $(RM) $(TEST_BINS)
$(RM) $(TARGET_LIB) $(RM) $(TARGET_LIB)
$(RM) $(TARGET_BIN)
dist-clean: clean dist-clean: clean

11
main.c Normal file
View File

@ -0,0 +1,11 @@
/* vim: set ts=8 sw=8 noexpandtab: */
#include <stdio.h>
#include "errors.h"
int main(void) {
printf("%s\n", mh_error_string(MH_E_TOO_LONG));
printf("Hello World\n");
return 0;
}

View File

@ -1,5 +0,0 @@
/* vim: set ts=8 sw=8 noexpandtab: */
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *message = test(); tests_run++; \
if (message) return message; } while (0)
extern int tests_run;

4
tests/c/.gitignore vendored Normal file
View File

@ -0,0 +1,4 @@
*
!.gitignore
!minunit.h
!*.c

22
tests/c/minunit.h Normal file
View File

@ -0,0 +1,22 @@
/* vim: set ts=8 sw=8 noexpandtab: */
#include <stdio.h>
#define mu_assert(message, test) do { if (!(test)) return message; } while (0)
#define mu_run_test(test) do { char *message = test(); tests_run++; \
if (message) return message; } while (0)
int tests_run = 0;
static char *mu_all_tests(void);
int main(void) {
char *result = mu_all_tests();
if (result != 0) {
printf("%s\n", result);
}
else {
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}

View File

@ -1,13 +1,10 @@
#include <stdio.h>
#include <string.h> #include <string.h>
#include "minunit.h" #include "minunit.h"
#include "../errors.h" #include "errors.h"
int tests_run = 0;
char error_buf[256]; char error_buf[256];
static char *test_error_messages_exist(void) { static char *test_error_messages_exist(void) {
int i = -1; int i = -1;
for (; i > MH_E_LAST; i--) { for (; i > MH_E_LAST; i--) {
@ -18,21 +15,7 @@ static char *test_error_messages_exist(void) {
return 0; return 0;
} }
static char *all_tests(void) { static char *mu_all_tests(void) {
mu_run_test(test_error_messages_exist); mu_run_test(test_error_messages_exist);
return 0; return 0;
} }
int main(void) {
char *result = all_tests();
if (result != 0) {
printf("%s\n", result);
}
else {
printf("ALL TESTS PASSED\n");
}
printf("Tests run: %d\n", tests_run);
return result != 0;
}