ex28 extra credit

This commit is contained in:
Dan Buch 2016-04-16 14:48:19 -04:00
parent 1aafac69cb
commit d8c63c261d
No known key found for this signature in database
GPG Key ID: FAEF12936DD3E3EC
6 changed files with 31 additions and 5 deletions

View File

@ -2,3 +2,4 @@
ex* ex*
!ex*.c !ex*.c
devpkgzed devpkgzed
*.log

View File

@ -0,0 +1 @@
tests/your_library_tests

View File

@ -1,5 +1,6 @@
CFLAGS = -g -O2 -Wall -Wextra -Isrc -rdynamic -DNDEBUG $(OPTFLAGS) CFLAGS = -g -O2 -Wall -Wextra -Isrc -Lbuild -rdynamic -DNDEBUG $(OPTFLAGS)
LIBS = -ldl $(OPTLIBS) LDLIBS = -ldl $(OPTLIBS)
PREFIX ?= /usr/local PREFIX ?= /usr/local
SOURCES = $(wildcard src/**/*.c src/*.c) SOURCES = $(wildcard src/**/*.c src/*.c)
@ -8,7 +9,8 @@ OBJECTS = $(patsubst %.c,%.o,$(SOURCES))
TEST_SRC = $(wildcard tests/*_tests.c) TEST_SRC = $(wildcard tests/*_tests.c)
TESTS = $(patsubst %.c,%,$(TEST_SRC)) TESTS = $(patsubst %.c,%,$(TEST_SRC))
TARGET = build/libYOUR_LIBRARY.a LIBNAME = YOUR_LIBRARY
TARGET = build/lib$(LIBNAME).a
SO_TARGET = $(patsubst %.a,%.so,$(TARGET)) SO_TARGET = $(patsubst %.a,%.so,$(TARGET))
# The Target Build # The Target Build
@ -19,7 +21,7 @@ dev: all
$(TARGET): CFLAGS += -fPIC $(TARGET): CFLAGS += -fPIC
$(TARGET): build $(OBJECTS) $(TARGET): build $(OBJECTS)
ar rcs $@ $(OBJECTS) $(AR) rcs $@ $(OBJECTS)
ranlib $@ ranlib $@
$(SO_TARGET): $(TARGET) $(OBJECTS) $(SO_TARGET): $(TARGET) $(OBJECTS)
@ -31,7 +33,7 @@ build:
# The Unit Tests # The Unit Tests
.PHONY: tests .PHONY: tests
tests: CFLAGS += $(TARGET) tests: LDLIBS += -static -l$(LIBNAME)
tests: $(TESTS) tests: $(TESTS)
sh ./tests/runtests.sh sh ./tests/runtests.sh

View File

@ -0,0 +1,6 @@
#include "your_library.h"
int howmanyweasels()
{
return WEASELS;
}

View File

@ -0,0 +1,8 @@
#ifndef _your_library_h
#define _your_library_h
#define WEASELS 23
int howmanyweasels();
#endif

View File

@ -0,0 +1,8 @@
#include <stdio.h>
#include "your_library.h"
int main()
{
printf("WEASELS: %d\n", howmanyweasels());
return 0;
}