From d8c63c261da85e2092d26ebb8325da322e20485b Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sat, 16 Apr 2016 14:48:19 -0400 Subject: [PATCH] ex28 extra credit --- lcthw-remnants-2/.gitignore | 1 + lcthw-remnants-2/c-skeleton/.gitignore | 1 + lcthw-remnants-2/c-skeleton/Makefile | 12 +++++++----- lcthw-remnants-2/c-skeleton/src/your_library.c | 6 ++++++ lcthw-remnants-2/c-skeleton/src/your_library.h | 8 ++++++++ .../c-skeleton/tests/your_library_tests.c | 8 ++++++++ 6 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 lcthw-remnants-2/c-skeleton/.gitignore create mode 100644 lcthw-remnants-2/c-skeleton/src/your_library.c create mode 100644 lcthw-remnants-2/c-skeleton/src/your_library.h create mode 100644 lcthw-remnants-2/c-skeleton/tests/your_library_tests.c diff --git a/lcthw-remnants-2/.gitignore b/lcthw-remnants-2/.gitignore index 81aa9e6..4e8f831 100644 --- a/lcthw-remnants-2/.gitignore +++ b/lcthw-remnants-2/.gitignore @@ -2,3 +2,4 @@ ex* !ex*.c devpkgzed +*.log diff --git a/lcthw-remnants-2/c-skeleton/.gitignore b/lcthw-remnants-2/c-skeleton/.gitignore new file mode 100644 index 0000000..9b6cf51 --- /dev/null +++ b/lcthw-remnants-2/c-skeleton/.gitignore @@ -0,0 +1 @@ +tests/your_library_tests diff --git a/lcthw-remnants-2/c-skeleton/Makefile b/lcthw-remnants-2/c-skeleton/Makefile index 5bca129..70e2e98 100644 --- a/lcthw-remnants-2/c-skeleton/Makefile +++ b/lcthw-remnants-2/c-skeleton/Makefile @@ -1,5 +1,6 @@ -CFLAGS = -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS) -LIBS = -ldl $(OPTLIBS) +CFLAGS = -g -O2 -Wall -Wextra -Isrc -Lbuild -rdynamic -DNDEBUG $(OPTFLAGS) +LDLIBS = -ldl $(OPTLIBS) + PREFIX ?= /usr/local SOURCES = $(wildcard src/**/*.c src/*.c) @@ -8,7 +9,8 @@ OBJECTS = $(patsubst %.c,%.o,$(SOURCES)) TEST_SRC = $(wildcard tests/*_tests.c) TESTS = $(patsubst %.c,%,$(TEST_SRC)) -TARGET = build/libYOUR_LIBRARY.a +LIBNAME = YOUR_LIBRARY +TARGET = build/lib$(LIBNAME).a SO_TARGET = $(patsubst %.a,%.so,$(TARGET)) # The Target Build @@ -19,7 +21,7 @@ dev: all $(TARGET): CFLAGS += -fPIC $(TARGET): build $(OBJECTS) - ar rcs $@ $(OBJECTS) + $(AR) rcs $@ $(OBJECTS) ranlib $@ $(SO_TARGET): $(TARGET) $(OBJECTS) @@ -31,7 +33,7 @@ build: # The Unit Tests .PHONY: tests -tests: CFLAGS += $(TARGET) +tests: LDLIBS += -static -l$(LIBNAME) tests: $(TESTS) sh ./tests/runtests.sh diff --git a/lcthw-remnants-2/c-skeleton/src/your_library.c b/lcthw-remnants-2/c-skeleton/src/your_library.c new file mode 100644 index 0000000..24b58f6 --- /dev/null +++ b/lcthw-remnants-2/c-skeleton/src/your_library.c @@ -0,0 +1,6 @@ +#include "your_library.h" + +int howmanyweasels() +{ + return WEASELS; +} diff --git a/lcthw-remnants-2/c-skeleton/src/your_library.h b/lcthw-remnants-2/c-skeleton/src/your_library.h new file mode 100644 index 0000000..53e21f0 --- /dev/null +++ b/lcthw-remnants-2/c-skeleton/src/your_library.h @@ -0,0 +1,8 @@ +#ifndef _your_library_h +#define _your_library_h + +#define WEASELS 23 + +int howmanyweasels(); + +#endif diff --git a/lcthw-remnants-2/c-skeleton/tests/your_library_tests.c b/lcthw-remnants-2/c-skeleton/tests/your_library_tests.c new file mode 100644 index 0000000..dcd1ed6 --- /dev/null +++ b/lcthw-remnants-2/c-skeleton/tests/your_library_tests.c @@ -0,0 +1,8 @@ +#include +#include "your_library.h" + +int main() +{ + printf("WEASELS: %d\n", howmanyweasels()); + return 0; +}