Makefile for multiple CGI scripts

This commit is contained in:
thematdev 2023-07-05 00:46:12 +03:00
parent 140738e4e8
commit 92e7d1ed15
Signed by: thematdev
GPG Key ID: D12878639B090D90
3 changed files with 8 additions and 5 deletions

View File

@ -1,14 +1,16 @@
CGI_EXEC ?= main.cgi
BD ?= build
SD ?= src
LIBS_DIR ?= libs
LIBS ?= $(wildcard $(LIBS_DIR)/*)
CGI_EXECS ?= view_comments.cgi
EXEC_TARGETS := $(patsubst %.cgi,$(BD)/%.cgi,$(CGI_EXECS))
LDFLAGS ?= -L$(BD)/ -lcgic -lqments -lhiredis -ltomcrypt -luuid
SRC_FILES := $(shell find $(SD) -name *.c)
OBJ_FILES := $(patsubst $(SD)/%.c,$(BD)/%.o,$(SRC_FILES))
EXEC_OBJS := $(patsubst %.cgi,$(BD)/%.o,$(CGI_EXECS))
OBJ_FILES := $(filter-out $(EXEC_OBJS),$(patsubst $(SD)/%.c,$(BD)/%.o,$(SRC_FILES)))
INCLUDE_DIRS = -Ilibs/qments/include -Ilibs/cgic
LIB_TARGETS = $(patsubst $(LIBS_DIR)/%,$(BD)/lib%.a,$(LIBS))
@ -24,14 +26,14 @@ $(BD)/libqments.a:
$(MAKE) -C $(LIBS_DIR)/qments static
cp $(LIBS_DIR)/qments/$(BD)/libqments.a $(BD)
$(BD)/$(CGI_EXEC): $(OBJ_FILES)
$(BD)/%.cgi: $(BD)/%.o $(OBJ_FILES)
$(CC) $(INCLUDE_DIRS) $(CFLAGS) $^ -o $@ $(LDFLAGS)
$(BD)/%.o: $(SD)/%.c $(LIB_TARGETS)
mkdir -p $(@D)
$(CC) $(INCLUDE_DIRS) $(CFLAGS) -c $< -o $@ $(LDFLAGS)
all: $(BD)/$(CGI_EXEC)
all: $(BD)/$(CGI_EXECS)
clean:
rm -rfI $(BD)/

View File

@ -7,6 +7,7 @@
int user_by_session_id(const char *session_id, char *username);
/* return 0 on failure, 1 on success, negative number on error */
/* authenticate must assign a session id */
int authenticate(const char *username, const char *password, char *sid);
#endif /* AUTH_H */