rework build structure for static link

make .gitignore exclude default
move tests into tests/c/
This commit is contained in:
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
*.gch
*.pch
# Libraries
*.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
!.gitignore
!*.c
!*.h
!Makefile
!tests

View file

@ -13,34 +13,39 @@ CFLAGS = -fPIC -g -O2 -std=c99 \
LDFLAGS = -g
LDLIBS =
TARGET_LIB = mulithash.so
TARGET_LIB = mulithash.a
TARGET_BIN = multihash
SRCS = errors.c
OBJS = $(SRCS:.c=.o)
all: ${TARGET_LIB}
all: $(TARGET_LIB) $(TARGET_BIN)
$(TARGET_LIB): $(OBJS)
$(CC) -g -shared -o $@ $^
ar rcs $@ $^
$(TARGET_BIN): main.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $^ -o $@
# Tests
TEST_SRCS = $(wildcard test/test_*.c)
TEST_SRCS = $(wildcard tests/c/test_*.c)
TEST_OBJS = $(TEST_SRCS:.c=.o)
TEST_BINS = $(TEST_OBJS:.o=.out)
TEST_BINS = $(TEST_OBJS:.o=)
PHONY += tests
tests: $(TEST_BINS)
@for t in $^; do \
echo; \
echo '***' "$$t" '***'; \
LD_LIBRARY_PATH=. "./$$t"; \
echo; \
echo '***' "$$t.c" '***'; \
"./$$t"; \
done
tests/c/test_%.o: tests/c/test_%.c
$(CC) -c -I. $^ -o $@
test/test_%.out: test/test_%.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $(TARGET_LIB) $^ -o $@
tests/c/test_%: tests/c/test_%.o $(TARGET_LIB)
$(CC) $(LDFLAGS) $^ -o $@
# Utils
@ -48,9 +53,9 @@ PHONY += clean dist-clean
clean:
$(RM) $(OBJS)
$(RM) $(TEST_OBJS)
$(RM) $(TEST_BINS)
$(RM) $(TARGET_LIB)
$(RM) $(TARGET_BIN)
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 "minunit.h"
#include "../errors.h"
#include "errors.h"
int tests_run = 0;
char error_buf[256];
static char *test_error_messages_exist(void) {
int i = -1;
for (; i > MH_E_LAST; i--) {
@ -18,21 +15,7 @@ static char *test_error_messages_exist(void) {
return 0;
}
static char *all_tests(void) {
static char *mu_all_tests(void) {
mu_run_test(test_error_messages_exist);
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;
}