From 45af2131d0dce416c9960f6dbfa309d8421026cd Mon Sep 17 00:00:00 2001 From: Armaan Bhojwani Date: Mon, 10 May 2021 20:26:39 -0400 Subject: [PATCH] Add tests, restructure repo, and add static target --- .gitignore | 4 ++++ Makefile | 27 +++++++++++++++++++-------- src/{ => libacheam}/acheam.h | 0 src/{ => libacheam}/tolowerw.c | 0 src/{ => libacheam}/toupperw.c | 0 src/tests.c | 18 ++++++++++++++++++ 6 files changed, 41 insertions(+), 8 deletions(-) rename src/{ => libacheam}/acheam.h (100%) rename src/{ => libacheam}/tolowerw.c (100%) rename src/{ => libacheam}/toupperw.c (100%) create mode 100644 src/tests.c diff --git a/.gitignore b/.gitignore index 6d5e378..ee15c0d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,8 @@ *.o +*.a *.so + man/* !man/*.scd + +test diff --git a/Makefile b/Makefile index fc46d4b..a301e4a 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,14 @@ DESTDIR ?= /usr/local CFLAGS := -Wall -Wextra -pedantic -std=c99 -fPIC ${CFLAGS} -all: lib man +all: shared static man -lib: - ${CC} -shared ${LDFLAGS} ${OBJS} -o libacheam.so src/*.c ${CFLAGS} +shared: + ${CC} -shared ${LDFLAGS} -o libacheam.so src/libacheam/*.c ${CFLAGS} + +static: + ${CC} ${LDFLAGS} src/libacheam/*.c ${CFLAGS} -c + ar rcs libacheam.a *.o man: for i in man/*.scd; do \ @@ -18,10 +22,10 @@ install: all ${DESTDIR}/lib/pkgconfig \ ${DESTDIR}/man/man3 - cp libacheam.so ${DESTDIR}/lib - cp acheam.pc ${DESTDIR}/lib/pkgconfig - cp src/acheam.h ${DESTDIR}/include - cp man/*.3 ${DESTDIR}/man/man3/ + cp libacheam.so ${DESTDIR}/lib + cp acheam.pc ${DESTDIR}/lib/pkgconfig + cp man/*.3 ${DESTDIR}/man/man3/ + cp src/libacheam/acheam.h ${DESTDIR}/include uninstall: rm ${DESTDIR}/include/acheam.h \ @@ -32,5 +36,12 @@ uninstall: rm ${DESTDIR}/man/man3/$$(basename "$$i" ".scd"); \ done +test: static + ${CC} -o test src/tests.c -I./src/libacheam libacheam.a ${CFLAGS} + ./test + +clean: + rm -f test libacheam.so libacheam.a *.o man/*.3 + .POSIX: -.PHONY: all man +.PHONY: all man test diff --git a/src/acheam.h b/src/libacheam/acheam.h similarity index 100% rename from src/acheam.h rename to src/libacheam/acheam.h diff --git a/src/tolowerw.c b/src/libacheam/tolowerw.c similarity index 100% rename from src/tolowerw.c rename to src/libacheam/tolowerw.c diff --git a/src/toupperw.c b/src/libacheam/toupperw.c similarity index 100% rename from src/toupperw.c rename to src/libacheam/toupperw.c diff --git a/src/tests.c b/src/tests.c new file mode 100644 index 0000000..c7dd2a2 --- /dev/null +++ b/src/tests.c @@ -0,0 +1,18 @@ +#include +#include + +#include +#include + +int +main(void) +{ + // tolowerw() + assert(strcmp(tolowerw("eXaMpLe StRiNg"), "example string") == 0); + + // toupperw() + assert(strcmp(toupperw("eXaMpLe StRiNg"), "EXAMPLE STRING") == 0); + + printf("All tests passed succesfully!\n"); + return 0; +} -- 2.39.2