ex28
This commit is contained in:
parent
3ea457e797
commit
1aafac69cb
0
lcthw-remnants-2/c-skeleton/LICENSE
Normal file
0
lcthw-remnants-2/c-skeleton/LICENSE
Normal file
57
lcthw-remnants-2/c-skeleton/Makefile
Normal file
57
lcthw-remnants-2/c-skeleton/Makefile
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
CFLAGS = -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS)
|
||||||
|
LIBS = -ldl $(OPTLIBS)
|
||||||
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
|
SOURCES = $(wildcard src/**/*.c src/*.c)
|
||||||
|
OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
|
||||||
|
|
||||||
|
TEST_SRC = $(wildcard tests/*_tests.c)
|
||||||
|
TESTS = $(patsubst %.c,%,$(TEST_SRC))
|
||||||
|
|
||||||
|
TARGET = build/libYOUR_LIBRARY.a
|
||||||
|
SO_TARGET = $(patsubst %.a,%.so,$(TARGET))
|
||||||
|
|
||||||
|
# The Target Build
|
||||||
|
all: $(TARGET) $(SO_TARGET) tests
|
||||||
|
|
||||||
|
dev: CFLAGS = -g -Wall -Isrc -Wall -Wextra $(OPTFLAGS)
|
||||||
|
dev: all
|
||||||
|
|
||||||
|
$(TARGET): CFLAGS += -fPIC
|
||||||
|
$(TARGET): build $(OBJECTS)
|
||||||
|
ar rcs $@ $(OBJECTS)
|
||||||
|
ranlib $@
|
||||||
|
|
||||||
|
$(SO_TARGET): $(TARGET) $(OBJECTS)
|
||||||
|
$(CC) -shared -o $@ $(OBJECTS)
|
||||||
|
|
||||||
|
build:
|
||||||
|
@mkdir -p build
|
||||||
|
@mkdir -p bin
|
||||||
|
|
||||||
|
# The Unit Tests
|
||||||
|
.PHONY: tests
|
||||||
|
tests: CFLAGS += $(TARGET)
|
||||||
|
tests: $(TESTS)
|
||||||
|
sh ./tests/runtests.sh
|
||||||
|
|
||||||
|
valgrind:
|
||||||
|
VALGRIND="valgrind --log-file=/tmp/valgrind-%p.log" $(MAKE)
|
||||||
|
|
||||||
|
# The Cleaner
|
||||||
|
clean:
|
||||||
|
rm -rf build $(OBJECTS) $(TESTS)
|
||||||
|
rm -f tests/tests.log
|
||||||
|
find . -name "*.gc*" -exec rm {} \;
|
||||||
|
rm -rf `find . -name "*.dSYM" -print`
|
||||||
|
|
||||||
|
# The Install
|
||||||
|
install: all
|
||||||
|
install -d $(DESTDIR)/$(PREFIX)/lib/
|
||||||
|
install $(TARGET) $(DESTDIR)/$(PREFIX)/lib/
|
||||||
|
|
||||||
|
# The Checker
|
||||||
|
BADFUNCS='[^_.>a-zA-Z0-9](str(n?cpy|n?cat|xfrm|n?dup|str|pbrk|tok|_)|stpn?cpy|a?sn?printf|byte_)'
|
||||||
|
check:
|
||||||
|
@echo Files with potentially dangerous functions
|
||||||
|
@egrep $(BADFUNCS) $(SOURCES) || true
|
0
lcthw-remnants-2/c-skeleton/README.md
Normal file
0
lcthw-remnants-2/c-skeleton/README.md
Normal file
30
lcthw-remnants-2/c-skeleton/src/dbg.h
Normal file
30
lcthw-remnants-2/c-skeleton/src/dbg.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#ifndef __dbg_h__
|
||||||
|
#define __dbg_h__
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifdef NDEBUG
|
||||||
|
#define debug(M, ...)
|
||||||
|
#else
|
||||||
|
#define debug(M, ...) fprintf(stderr, "DEBUG %s:%d:%s: " M "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define clean_errno() (errno == 0 ? "None" : strerror(errno))
|
||||||
|
|
||||||
|
#define log_err(M, ...) fprintf(stderr, "[ERROR] (%s:%d:%s: errno: %s) " M "\n", __FILE__, __LINE__, __func__, clean_errno(), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define log_warn(M, ...) fprintf(stderr, "[WARN] (%s:%d:%s: errno: %s) " M "\n", __FILE__, __LINE__, __func__, clean_errno(), ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define log_info(M, ...) fprintf(stderr, "[INFO] (%s:%d:%s) " M "\n", __FILE__, __LINE__, __func__, ##__VA_ARGS__)
|
||||||
|
|
||||||
|
#define check(A, M, ...) if(!(A)) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
||||||
|
|
||||||
|
#define sentinel(M, ...) { log_err(M, ##__VA_ARGS__); errno=0; goto error; }
|
||||||
|
|
||||||
|
#define check_mem(A) check((A), "Out of memory.")
|
||||||
|
|
||||||
|
#define check_debug(A, M, ...) if(!(A)) { debug(M, ##__VA_ARGS__); errno=0; goto error; }
|
||||||
|
|
||||||
|
#endif
|
19
lcthw-remnants-2/c-skeleton/tests/runtests.sh
Normal file
19
lcthw-remnants-2/c-skeleton/tests/runtests.sh
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
echo "Running unit tests:"
|
||||||
|
|
||||||
|
for i in tests/*_tests
|
||||||
|
do
|
||||||
|
if test -f $i
|
||||||
|
then
|
||||||
|
if $VALGRIND ./$i 2>> tests/tests.log
|
||||||
|
then
|
||||||
|
echo $i PASS
|
||||||
|
else
|
||||||
|
echo "ERROR in test $i: here's tests/tests.log"
|
||||||
|
echo "------"
|
||||||
|
tail tests/tests.log
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo ""
|
Loading…
Reference in New Issue
Block a user