*.o
+*.a
*.so
+
man/*
!man/*.scd
+
+test
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 \
${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 \
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
+++ /dev/null
-char * tolowerw(char *input);
-char * toupperw(char *input);
--- /dev/null
+char * tolowerw(char *input);
+char * toupperw(char *input);
--- /dev/null
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+tolowerw(char *inp)
+{
+ char *tmp = calloc(strlen(inp), sizeof(char));
+ strcpy(tmp, inp);
+ for (int i = 0; tmp[i]; i++){
+ tmp[i] = tolower(tmp[i]);
+ }
+ return tmp;
+}
+
--- /dev/null
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+
+char *
+toupperw(char *inp)
+{
+ char *tmp = calloc(strlen(inp), sizeof(char));
+ strcpy(tmp, inp);
+ for (int i = 0; tmp[i]; i++){
+ tmp[i] = toupper(tmp[i]);
+ }
+ return tmp;
+}
+
--- /dev/null
+#include <acheam.h>
+#include <assert.h>
+
+#include <string.h>
+#include <stdio.h>
+
+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;
+}
+++ /dev/null
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-tolowerw(char *inp)
-{
- char *tmp = calloc(strlen(inp), sizeof(char));
- strcpy(tmp, inp);
- for (int i = 0; tmp[i]; i++){
- tmp[i] = tolower(tmp[i]);
- }
- return tmp;
-}
-
+++ /dev/null
-#include <ctype.h>
-#include <stdlib.h>
-#include <string.h>
-
-char *
-toupperw(char *inp)
-{
- char *tmp = calloc(strlen(inp), sizeof(char));
- strcpy(tmp, inp);
- for (int i = 0; tmp[i]; i++){
- tmp[i] = toupper(tmp[i]);
- }
- return tmp;
-}
-