diff --git a/Makefile b/Makefile index 7832df3..28ad7c9 100644 --- a/Makefile +++ b/Makefile @@ -1,22 +1,50 @@ CFLAGS=-Wall -Wextra -ggdb LIBWS=./vendor/libmicrohttpd/ -LIBWS_LIB=$(LIBWS)lib/libmicrohttpd.a - LIBSHA=./vendor/sha256/ -LIBSHA_SRC=$(LIBSHA)sha256.c -LDFLAGS=-lm -luuid -INCL_FLAGS=-I$(LIBWS)include -I$(LIBSHA) +SHARED_LIB_FILES=output/libpath.a output/libnoh.a output/libsha.a +SHARED_LIBS=-L./output -lsha -lpath -lnoh -server: src/server.c $(LIBSHA_SRC) output - gcc $(CFLAGS) $(INCL_FLAGS) -o output/server src/server.c $(LIBSHA_SRC) $(LIBWS_LIB) $(LDFLAGS) +################################################################################ -LDFLAGS2=-lm -INCL_FLAGS2=-I$(LIBSHA) +SERVER_LDFLAGS=-lm -luuid -L $(LIBWS)lib -lmicrohttpd $(SHARED_LIBS) +SERVER_INCL_FLAGS=-I$(LIBWS)include -I$(LIBSHA) -userctl: src/userctl.c $(LIBSHA_SRC) output - gcc $(CFLAGS) $(INCL_FLAGS2) -o output/userctl src/userctl.c $(LIBSHA_SRC) $(LDFLAGS2) +SERVER_SRC=src/server.c src/users.c \ + src/id_store.c src/library.c \ + src/opds_handler.c src/get_handler.c + +server: output/server +output/server: $(SERVER_SRC) $(SHARED_LIB_FILES) | output + gcc $(CFLAGS) $(SERVER_INCL_FLAGS) -o output/server src/server.c $(SERVER_LDFLAGS) + +################################################################################ + +USERCTL_LDFLAGS=-lm $(SHARED_LIBS) +USERCTL_INCL_FLAGS=-I$(LIBSHA) + +USERCTL_SRC=src/userctl.c src/users.c + +userctl: output/userctl +output/userctl: $(USERCTL_SRC) $(SHARED_LIB_FILES) | output + gcc $(CFLAGS) $(USERCTL_INCL_FLAGS) -o output/userctl src/userctl.c $(USERCTL_LDFLAGS) + +################################################################################ + +output/libsha.a: $(LIBSHA)sha256.c $(LIBSHA)sha256.h | output + gcc $(CFLAGS) -c -o output/sha.o $(LIBSHA)sha256.c + ar rcsD output/libsha.a output/sha.o + +output/libpath.a: src/path.c src/path.h | output + gcc $(CFLAGS) -x c -c -o output/path.o src/path.c -L ./output -lnoh + ar rcsD output/libpath.a output/path.o + +output/libnoh.a: src/noh.h | output + gcc $(CFLAGS) -x c -c -o output/noh.o src/noh.h -DNOH_IMPLEMENTATION + ar rcsD output/libnoh.a output/noh.o + +################################################################################ output: mkdir -p output diff --git a/build.sh b/build.sh index bbb6373..14e49a9 100755 --- a/build.sh +++ b/build.sh @@ -5,8 +5,8 @@ clear if [ $1 = "build" ]; then echo "Building" - make server -B - make userctl -B + make server + make userctl elif [ $1 = "run" ]; then echo "Running" diff --git a/src/noh.h b/src/noh.h index 0a25791..bec3710 100644 --- a/src/noh.h +++ b/src/noh.h @@ -440,14 +440,14 @@ bool noh_sv_ends_with(Noh_String_View a, Noh_String_View b); bool noh_sv_ends_with_ci(Noh_String_View a, Noh_String_View b); // Checks whether the first string view contains the elements from the second string view. -inline bool noh_sv_contains(Noh_String_View a, Noh_String_View b); +bool noh_sv_contains(Noh_String_View a, Noh_String_View b); // Returns the first index of the second string view in the first string view. // Returns -1 if it is not found. int noh_sv_index_of(Noh_String_View a, Noh_String_View b); // Checks whether the first string view contains the elements from the second string view, ignoring the case. -inline bool noh_sv_contains_ci(Noh_String_View a, Noh_String_View b); +bool noh_sv_contains_ci(Noh_String_View a, Noh_String_View b); // Returns the first index of the second string view in the first string view, ignoring the case. // Returns -1 if it is not found. @@ -1113,7 +1113,7 @@ bool noh_sv_ends_with_ci(Noh_String_View a, Noh_String_View b) { return noh_sv_eq_ci(a, b); } -inline bool noh_sv_contains(Noh_String_View a, Noh_String_View b) { +bool noh_sv_contains(Noh_String_View a, Noh_String_View b) { return noh_sv_index_of(a, b) >= 0; } @@ -1128,7 +1128,7 @@ int noh_sv_index_of(Noh_String_View a, Noh_String_View b) { return -1; } -inline bool noh_sv_contains_ci(Noh_String_View a, Noh_String_View b) { +bool noh_sv_contains_ci(Noh_String_View a, Noh_String_View b) { return noh_sv_index_of_ci(a, b) >= 0; } diff --git a/src/path.c b/src/path.c index 0d5f857..5c7095e 100644 --- a/src/path.c +++ b/src/path.c @@ -1,3 +1,5 @@ +#include "path.h" + static inline bool byte_is_url_safe(char c) { return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') @@ -99,7 +101,7 @@ void url_decode(Noh_String *string) { } #define build_path(url, first, ...) build_path_((url), (first), __VA_ARGS__, NULL) -static Noh_String build_path_(bool url, bool go_up, Noh_String_View *first, ...) { +Noh_String build_path_(bool url, bool go_up, Noh_String_View *first, ...) { va_list args; Noh_String_View *elem_ = first; va_start(args, first); diff --git a/src/path.h b/src/path.h new file mode 100644 index 0000000..9e37e14 --- /dev/null +++ b/src/path.h @@ -0,0 +1,13 @@ +#ifndef PATH_H_ +#define PATH_H_ + +#include "noh.h" + +#define build_path(url, first, ...) build_path_((url), (first), __VA_ARGS__, NULL) +Noh_String build_path_(bool url, bool go_up, Noh_String_View *first, ...); + +void url_encode(Noh_String *string); + +void url_decode(Noh_String *string); + +#endif // PATH_H_ diff --git a/src/server.c b/src/server.c index 970e91e..ace1aa5 100644 --- a/src/server.c +++ b/src/server.c @@ -2,12 +2,12 @@ #include #include #include -#define NOH_IMPLEMENTATION + +#include "path.h" #include "noh.h" Noh_Arena temp; -#include "path.c" #include "users.c" #define SV Noh_String_View diff --git a/src/userctl.c b/src/userctl.c index 2ba32c9..e3bd125 100644 --- a/src/userctl.c +++ b/src/userctl.c @@ -1,11 +1,11 @@ #include #include -#define NOH_IMPLEMENTATION + +#include "path.h" #include "noh.h" Noh_Arena temp; -#include "path.c" #include "users.c" #define SV Noh_String_View