Update makefile with some libraries compiled separately

This commit is contained in:
2026-06-17 17:34:07 +02:00
parent f0267d7a5c
commit 8aab365e14
7 changed files with 65 additions and 22 deletions

View File

@@ -1,22 +1,50 @@
CFLAGS=-Wall -Wextra -ggdb CFLAGS=-Wall -Wextra -ggdb
LIBWS=./vendor/libmicrohttpd/ LIBWS=./vendor/libmicrohttpd/
LIBWS_LIB=$(LIBWS)lib/libmicrohttpd.a
LIBSHA=./vendor/sha256/ LIBSHA=./vendor/sha256/
LIBSHA_SRC=$(LIBSHA)sha256.c
LDFLAGS=-lm -luuid SHARED_LIB_FILES=output/libpath.a output/libnoh.a output/libsha.a
INCL_FLAGS=-I$(LIBWS)include -I$(LIBSHA) 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 SERVER_LDFLAGS=-lm -luuid -L $(LIBWS)lib -lmicrohttpd $(SHARED_LIBS)
INCL_FLAGS2=-I$(LIBSHA) SERVER_INCL_FLAGS=-I$(LIBWS)include -I$(LIBSHA)
userctl: src/userctl.c $(LIBSHA_SRC) output SERVER_SRC=src/server.c src/users.c \
gcc $(CFLAGS) $(INCL_FLAGS2) -o output/userctl src/userctl.c $(LIBSHA_SRC) $(LDFLAGS2) 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: output:
mkdir -p output mkdir -p output

View File

@@ -5,8 +5,8 @@ clear
if [ $1 = "build" ]; then if [ $1 = "build" ]; then
echo "Building" echo "Building"
make server -B make server
make userctl -B make userctl
elif [ $1 = "run" ]; then elif [ $1 = "run" ]; then
echo "Running" echo "Running"

View File

@@ -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); 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. // 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 the first index of the second string view in the first string view.
// Returns -1 if it is not found. // Returns -1 if it is not found.
int noh_sv_index_of(Noh_String_View a, Noh_String_View b); 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. // 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 the first index of the second string view in the first string view, ignoring the case.
// Returns -1 if it is not found. // 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); 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; 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; 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; return noh_sv_index_of_ci(a, b) >= 0;
} }

View File

@@ -1,3 +1,5 @@
#include "path.h"
static inline bool byte_is_url_safe(char c) { static inline bool byte_is_url_safe(char c) {
return (c >= 'A' && c <= 'Z') return (c >= 'A' && c <= 'Z')
|| (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) #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; va_list args;
Noh_String_View *elem_ = first; Noh_String_View *elem_ = first;
va_start(args, first); va_start(args, first);

13
src/path.h Normal file
View File

@@ -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_

View File

@@ -2,12 +2,12 @@
#include <sha256.h> #include <sha256.h>
#include <uuid/uuid.h> #include <uuid/uuid.h>
#include <dirent.h> #include <dirent.h>
#define NOH_IMPLEMENTATION
#include "path.h"
#include "noh.h" #include "noh.h"
Noh_Arena temp; Noh_Arena temp;
#include "path.c"
#include "users.c" #include "users.c"
#define SV Noh_String_View #define SV Noh_String_View

View File

@@ -1,11 +1,11 @@
#include <stdio.h> #include <stdio.h>
#include <dirent.h> #include <dirent.h>
#define NOH_IMPLEMENTATION
#include "path.h"
#include "noh.h" #include "noh.h"
Noh_Arena temp; Noh_Arena temp;
#include "path.c"
#include "users.c" #include "users.c"
#define SV Noh_String_View #define SV Noh_String_View