-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmakefile
More file actions
530 lines (456 loc) · 18.6 KB
/
makefile
File metadata and controls
530 lines (456 loc) · 18.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
# Makefile for toy project
# C99, POSIX-compliant, fio-stl only
#############################################################################
# Settings
#############################################################################
DESCRIPTION="The facil.io C STL Library"
AUTHOR="Boaz Segev"
# Project configuration
NAME=fio-stl
CC ?= gcc
SRC_DIR = src
BUILD_DIR ?= tmp
TEST_DIR := tests
EXAMPLES_DIR := examples
INSTALL_PREFIX ?= /usr/local
# Compiler / Linker Warnings... i.e. -Wpedantic -Weverything -Wno-format-pedantic -Wshorten-64-to-32
WARNINGS=-Wshadow -Wall -Wextra -Wpedantic -Wno-missing-field-initializers -Wformat-security -Wno-psabi
# Compiler and linker flags
# Consider: -O3 -Rpass=loop-vectorize -Rpass-missed=loop-vectorize -Rpass-analysis=loop-vectorize
OPTIMIZATION=-O3 -DNDEBUG -DNODEBUG
# CFLAGS in debug mode. i.e.: -fsanitize=thread -fsanitize=undefined -fsanitize=address -coverage -DFIO_MEMORY_DISABLE
DEBUG_CFLAGS:=$(CFLAGS) -O0 -DDEBUG=1 -fno-builtin $(WARNINGS) -I$(SRC_DIR) -I.
# CFLAGS in production mode.
CFLAGS+=$(OPTIMIZATION) $(WARNINGS) -I$(SRC_DIR) -I.
LDFLAGS+= -lm
# Main executable
PROJECT = $(BUILD_DIR)/$(NAME)
# combining headers, C files and docs to a single file? i.e., fio-stl
LIB_CONCAT_FOLDER=fio-stl
LIB_CONCAT_TARGET=fio-stl
# Source files
SOURCES = $(shell find $(SRC_DIR) -name "*.c" -type f 2>/dev/null | sed 's/ /\\ /g')
OBJECTS = $(SOURCES:$(SRC_DIR)/%.c=$(BUILD_DIR)/%.o)
# Install paths
INSTALL_BIN = $(INSTALL_PREFIX)/bin
INSTALL_INCLUDE = $(INSTALL_PREFIX)/include/$(NAME)
#############################################################################
# Basics
#############################################################################
# Targets
.PHONY: all clean test format lint install install-headers everything___ help set_debug_flags $(TEST_DIR) $(TEST_DIR)/% $(EXAMPLES_DIR) $(EXAMPLES_DIR)/% extras extras/%
# Default target
all: everything___
@echo "Library headers installed to $(BUILD_DIR)/include/"
# Build main executable (only if source files exist)
ifneq ($(strip $($(strip $(SOURCES)))),)
$(PROJECT): $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
endif
# Build object files
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "* Compiling $*.c"
@$(CC) $(CFLAGS) -c -o $@ $<
# Create build directory
$(BUILD_DIR):
@mkdir -p $(BUILD_DIR)
# Format code with clang-format (style set in .clang-format)
format:
@echo "Formatting code..."
@clang-format -i $(SRC_DIR)/**/*.c $(SRC_DIR)/**/*.h $(SRC_DIR)/*.c $(SRC_DIR)/*.h 2>/dev/null || true
@echo "Formatting complete!"
# Lint code with clang-tidy
lint:
@echo "Linting code..."
@clang-tidy $(SRC_DIR)/main.c --extra-arg=-std=c99 -- $(CFLAGS)
@echo "Linting complete!"
#############################################################################
# Debug Flags (db/target or target/db)
#############################################################################
set_debug_flags:
$(eval CFLAGS=$(DEBUG_CFLAGS))
@echo "(!) Debug mode detected."
db/%: | clean set_debug_flags % ;
%/db: | clean set_debug_flags % ;
#############################################################################
# Install
#############################################################################
# Install binary and headers to system
install: $(PROJECT) install-headers install-docs
@echo "Installing $(NAME) to $(INSTALL_PREFIX)..."
@mkdir -p $(INSTALL_BIN)
@mkdir -p $(INSTALL_INCLUDE)
@install -m 755 $(PROJECT) $(INSTALL_BIN)/
@cp -r $(BUILD_DIR)/include/* $(INSTALL_INCLUDE)/
@echo "Installation complete!"
@echo " Binary: $(INSTALL_BIN)/$(NAME)"
@echo " Headers: $(INSTALL_INCLUDE)/"
# Copy headers to build/include preserving directory structure
install-headers: | $(BUILD_DIR)
@echo "Copying headers to $(BUILD_DIR)/include..."
@find $(SRC_DIR) -name "*.h" -type f | while read -r header; do \
rel_path=$${header#$(SRC_DIR)/}; \
target_dir=$(BUILD_DIR)/include/$$(dirname "$$rel_path"); \
mkdir -p "$$target_dir"; \
cp "$$header" "$$target_dir/"; \
done
@echo "Headers copied successfully!"
# Copy documentation to build/docs preserving directory structure
install-docs: | $(BUILD_DIR)
@echo "Copying documentation to $(BUILD_DIR)/docs..."
@find $(SRC_DIR) -name "*.md" -type f | while read -r file_name; do \
rel_path=$${file_name#$(SRC_DIR)/}; \
target_dir=$(BUILD_DIR)/docs/$$(dirname "$$rel_path"); \
mkdir -p "$$target_dir"; \
cp "$$file_name" "$$target_dir/"; \
done
@echo "Headers copied successfully!"
everything___: install-docs install-headers
#############################################################################
# Tests
#############################################################################
# Test files
TEST_SOURCES = $(shell find $(TEST_DIR) -name "*.c" -type f 2>/dev/null | sed 's/ /\\ /g')
TEST_TARGETS = $(TEST_SOURCES:$(TEST_DIR)/%=$(BUILD_DIR)/$(TEST_DIR)/%)
TEST_BINS = $(TEST_TARGETS:%.c=%)
AFTER_TEST_MESSAGE="\\n$(DESCRIPTION) is brought to you by \\x1B[1m$(AUTHOR)\x1B[0m.\\n\\x1B[1mValue deserves to be valued.\\x1B[0m\\n(please consider code contributions / donations)\\n"
# Build test binaries (each test file becomes a separate executable)
$(BUILD_DIR)/$(TEST_DIR)/%: $(TEST_DIR)/%.c $(OBJECTS) | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "* Compiling Test: $*.c"
@$(CC) $(CFLAGS) -o $@ $< $(filter-out $(BUILD_DIR)/main.o,$(OBJECTS)) $(LDFLAGS)
# Build and run tests
test: clean | all $(TEST_BINS)
@echo ""
@if [ -n "$(TEST_BINS)" ]; then \
echo "Running test suite..."; \
test_count=0; \
pass_count=0; \
fail_count=0; \
failed_tests=""; \
for test_bin in $(TEST_BINS); do \
test_count=$$((test_count + 1)); \
test_name=$$(basename $$test_bin); \
echo " [$$test_count] Running $$test_name..."; \
if $$test_bin; then \
echo " ✓ TEST PASSED: $$test_bin"; \
pass_count=$$((pass_count + 1)); \
else \
echo " ✗ TEST FAILED: $$test_bin"; \
fail_count=$$((fail_count + 1)); \
failed_tests="$$failed_tests$$test_name "; \
fi; \
echo ""; \
done; \
echo ""; \
echo "Test Results: $$pass_count passed, $$fail_count failed, $$test_count total"; \
if [ $$fail_count -gt 0 ]; then \
echo ""; \
echo "Failed tests:"; \
for failed_test in $$failed_tests; do \
echo " ✗ $$failed_test"; \
done; \
exit 1; \
fi; \
else \
echo "No test files found in $(TEST_DIR)/"; \
fi
@echo "All tests complete!"
@echo $(AFTER_TEST_MESSAGE)
$(TEST_DIR)/%: | clean $(BUILD_DIR)/$(TEST_DIR)/%
@echo "Running test $(BUILD_DIR)/$@"
@echo "=================================="
@if $(BUILD_DIR)/$@; then \
echo " ✓ TEST PASS"; \
else \
echo " ✗ TEST FAILED"; \
exit 1; \
fi;
@echo $(AFTER_TEST_MESSAGE)
$(TEST_DIR): test;
#############################################################################
# Examples
#############################################################################
EXAMPLES_SOURCES:=$(shell find $(EXAMPLES_DIR) -name "*.c" -type f 2>/dev/null | sed 's/ /\\ /g')
EXAMPLES_BINS:=$(EXAMPLES_SOURCES:%.c=$(BUILD_DIR)/%)
.PHONY: $(EXAMPLES_DIR) $(EXAMPLES_DIR)/%
# Build example binary (each C file becomes a separate executable)
$(BUILD_DIR)/$(EXAMPLES_DIR)/%: $(EXAMPLES_DIR)/%.c $(OBJECTS) | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "* Compiling Example: $*.c"
@$(CC) $(CFLAGS) -o $@ $< $(filter-out $(BUILD_DIR)/main.o,$(OBJECTS)) $(LDFLAGS)
$(EXAMPLES_DIR)/%: $(BUILD_DIR)/$(EXAMPLES_DIR)/%
@echo "Running $(BUILD_DIR)/$@"
@echo "=================================="
@$(BUILD_DIR)/$@
$(EXAMPLES_DIR): $(EXAMPLES_BINS);
#############################################################################
# Experiments & Extras - use for testing new ideas or temporary tests
#############################################################################
EXTRAS_SOURCES:=$(shell find extras -name "*.c" -type f 2>/dev/null | sed 's/ /\\ /g')
EXTRAS_BINS:=$(EXTRAS_SOURCES:%.c=$(BUILD_DIR)/%)
.PHONY: $(BUILD_DIR)/extras/% extras/%
# Build extra binary (each C file becomes a separate executable)
$(BUILD_DIR)/extras/%: extras/%.c $(OBJECTS) | $(BUILD_DIR)
@mkdir -p $(dir $@)
@echo "* Compiling Example: $*.c"
@$(CC) $(CFLAGS) -o $@ $< $(filter-out $(BUILD_DIR)/main.o,$(OBJECTS)) $(LDFLAGS)
extras/%: $(BUILD_DIR)/extras/%
@echo "Running $(BUILD_DIR)/$@"
@echo "=================================="
@$(BUILD_DIR)/$@
extras: $(EXTRA_BINS) ;
#############################################################################
# Combining single-file library
#############################################################################
ifdef LIB_CONCAT_FOLDER
ifdef LIB_CONCAT_TARGET
ifneq ($(OS),Windows_NT)
# POSIX implementation
ifneq ($(wildcard $(LIB_CONCAT_FOLDER)/*.h), $(EMPTY))
$(info * Merging to single-file header: $(LIB_CONCAT_TARGET).h)
$(shell rm $(LIB_CONCAT_TARGET).h 2> /dev/null)
$(shell cat $(LIB_CONCAT_FOLDER)/*.h >> $(LIB_CONCAT_TARGET).h)
endif
ifneq ($(wildcard $(LIB_CONCAT_FOLDER)/*.c), $(EMPTY))
$(info * Merging to single-file C source: $(LIB_CONCAT_TARGET).c)
$(shell rm $(LIB_CONCAT_TARGET).c 2> /dev/null)
$(shell cat $(LIB_CONCAT_FOLDER)/*.c >> $(LIB_CONCAT_TARGET).c)
endif
ifneq ($(wildcard $(LIB_CONCAT_FOLDER)/*.md), $(EMPTY))
$(info * Merging documentation: $(LIB_CONCAT_TARGET).md)
$(shell rm $(LIB_CONCAT_TARGET).md 2> /dev/null)
$(shell cat $(LIB_CONCAT_FOLDER)/*.md >> $(LIB_CONCAT_TARGET).md)
endif
else
# Windows implementation
$(warning *** Single-file library concatination skipped: requires a POSIX system.)
LDFLAGS += -lcrypt32
endif #Windows_NT
endif # LIB_CONCAT_TARGET
endif # LIB_CONCAT_FOLDER
#############################################################################
# Compile Time Tests / Flags
#############################################################################
#############################################################################
# Makefile Runtime Tests (sets flags, such as HAVE_OPENSSL)
#############################################################################
# Tests are performed unless the value is empty / missing
TEST4SOCKET:= # --- tests for socket library linker flags
TEST4POLL:= # HAVE_KQUEUE / HAVE_EPOLL / HAVE_POLL
TEST4CRYPTO:=1 # HAVE_OPENSSL / HAVE_SODIUM
TEST4ZLIB:=1 # HAVE_ZLIB
TEST4PG:= # HAVE_POSTGRESQL
TEST4SQLITE3:= # HAVE_SQLITE3
#############################################################################
# TRY_RUN, TRY_COMPILE and TRY_COMPILE_AND_RUN functions
#
# Call using $(call TRY_COMPILE, code, compiler_flags)
#
# Returns shell code as string: "0" (success) or non-0 (failure)
#
# TRY_COMPILE_AND_RUN returns the program's shell code as string.
#############################################################################
TRY_RUN=$(shell $(1) >> /dev/null 2> /dev/null; echo $$?;)
TRY_COMPILE=$(shell printf $(1) | $(CC) $(CFLAGS) -xc -o /dev/null - $(LDFLAGS) $(2) >> /dev/null 2> /dev/null ; echo $$? 2> /dev/null)
TRY_COMPILE_AND_RUN=$(shell printf $(1) | $(CC) $(CFLAGS) -xc -o ./___$(NAME)_tmp_test_ - $(LDFLAGS) $(2) 2> /dev/null ; ./___fio_tmp_test_ >> /dev/null 2> /dev/null; echo $$?; rm ./___$(NAME)_tmp_test_ 2> /dev/null)
TRY_HEADER_AND_FUNC= $(shell printf "\#include <$(strip $(1))>\\nint main(void) {(void)($(strip $(2)));}" | $(CC) $(CFLAGS) -xc -o /dev/null - $(LDFLAGS) $(3) >> /dev/null 2> /dev/null; echo $$? 2> /dev/null)
EMPTY_STRING:=
# pkg-config
PKG_CONFIG?=pkg-config
#############################################################################
# Detecting SystemV socket libraries
# (no need to edit)
#############################################################################
ifneq ($(strip $(TEST4SOCKET)),)
FIO_TEST_SOCKET_AND_NETWORK_SERVICE:="\\n\
\#include <sys/types.h>\\n\
\#include <sys/socket.h>\\n\
\#include <netinet/in.h>\\n\
\#include <arpa/inet.h>\\n\
int main(void) {\\n\
struct sockaddr_in addr = { .sin_port = 0 };\\n\
int fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);\\n\
if(fd == -1) return 1;\\n\
if(inet_pton(AF_INET, \"127.0.0.1\", &addr.sin_addr) < 1) return 1;\\n\
return connect(fd, (struct sockaddr *)&addr, sizeof addr) < 0 ? 1 : 0;\\n\
}\\n\
"
ifeq ($(call TRY_COMPILE, $(FIO_TEST_SOCKET_AND_NETWORK_SERVICE), $(EMPTY)), 0)
$(info * Detected native socket API, without additional libraries)
else ifeq ($(call TRY_COMPILE, $(FIO_TEST_SOCKET_AND_NETWORK_SERVICE), "-lsocket" "-lnsl"), 0)
$(info * Detected socket API from libsocket and libnsl)
LINKER_LIBS_EXT:=$(LINKER_LIBS_EXT) socket nsl
else
$(warning No socket API detected - won't be able to compile facil.io)
endif
endif # TEST4SOCKET
ifneq ($(strip $(TEST4POLL)),)
FIO_POLL_TEST_KQUEUE:="\\n\
\#define _GNU_SOURCE\\n\
\#include <stdlib.h>\\n\
\#include <sys/event.h>\\n\
int main(void) {\\n\
int fd = kqueue();\\n\
}\\n\
"
FIO_POLL_TEST_EPOLL:="\\n\
\#define _GNU_SOURCE\\n\
\#include <stdlib.h>\\n\
\#include <stdio.h>\\n\
\#include <sys/types.h>\\n\
\#include <sys/stat.h>\\n\
\#include <fcntl.h>\\n\
\#include <sys/epoll.h>\\n\
int main(void) {\\n\
int fd = epoll_create1(EPOLL_CLOEXEC);\\n\
}\\n\
"
FIO_POLL_TEST_POLL:="\\n\
\#define _GNU_SOURCE\\n\
\#include <stdlib.h>\\n\
\#include <poll.h>\\n\
int main(void) {\\n\
struct pollfd plist[18];\\n\
memset(plist, 0, sizeof(plist[0]) * 18);\\n\
poll(plist, 1, 1);\\n\
}\\n\
"
# Test for manual selection and then TRY_COMPILE with each polling engine
ifdef FIO_POLL
$(info * Skipping polling tests, enforcing manual selection of: poll)
FLAGS+=HAVE_POLL
else ifdef FIO_FORCE_POLL
$(info * Skipping polling tests, enforcing manual selection of: poll)
FLAGS+=HAVE_POLL
else ifdef FIO_FORCE_EPOLL
$(info * Skipping polling tests, enforcing manual selection of: epoll)
FLAGS+=HAVE_EPOLL
else ifdef FIO_FORCE_KQUEUE
$(info * Skipping polling tests, enforcing manual selection of: kqueue)
FLAGS+=HAVE_KQUEUE
else ifeq ($(call TRY_COMPILE, $(FIO_POLL_TEST_EPOLL), $(EMPTY)), 0)
$(info * Detected `epoll`)
FLAGS+=HAVE_EPOLL
else ifeq ($(call TRY_COMPILE, $(FIO_POLL_TEST_KQUEUE), $(EMPTY)), 0)
$(info * Detected `kqueue`)
FLAGS+=HAVE_KQUEUE
else ifeq ($(call TRY_COMPILE, $(FIO_POLL_TEST_POLL), $(EMPTY)), 0)
$(info * Detected `poll` - this is suboptimal fallback!)
FLAGS+=HAVE_POLL
else
$(warning No supported polling engine! won't be able to compile facil.io)
endif
endif # TEST4POLL
#############################################################################
# SSL/ TLS Library Detection
# (no need to edit)
#############################################################################
ifneq ($(strip $(TEST4CRYPTO)),)
# OpenSSL requirement C application code
FIO_TLS_TEST_OPENSSL:="\\n\
\#define _GNU_SOURCE\\n\
\#include <stdlib.h>\\n\
\#include <stdio.h>\\n\
\#include <openssl/bio.h> \\n\
\#include <openssl/err.h> \\n\
\#include <openssl/ssl.h> \\n\
\#if OPENSSL_VERSION_MAJOR < 3L \\n\
\#error \"OpenSSL version too small\" \\n\
\#endif \\n\
int main(void) { \\n\
SSL_library_init(); \\n\
SSL_CTX *ctx = SSL_CTX_new(TLS_method()); \\n\
SSL *ssl = SSL_new(ctx); \\n\
BIO *bio = BIO_new_socket(3, 0); \\n\
BIO_up_ref(bio); \\n\
SSL_set0_rbio(ssl, bio); \\n\
SSL_set0_wbio(ssl, bio); \\n\
}\\n\
"
OPENSSL_CFLAGS:=
OPENSSL_LDFLAGS:="-lssl" "-lcrypto"
LIBSODIUM_CFLAGS:=
LIBSODIUM_LDFLAGS:=-lsodium
# detect OpenSSL flags using pkg-config, if available
ifeq ($(shell $(PKG_CONFIG) -- openssl >/dev/null 2>&1; echo $$?), 0)
OPENSSL_CFLAGS:=$(shell $(PKG_CONFIG) --cflags openssl)
OPENSSL_LDFLAGS:=$(shell $(PKG_CONFIG) --libs openssl)
endif
ifeq ($(shell $(PKG_CONFIG) -- libsodium >/dev/null 2>&1; echo $$?), 0)
LIBSODIUM_CFLAGS:=$(shell $(PKG_CONFIG) --cflags libsodium)
LIBSODIUM_LDFLAGS:=$(shell $(PKG_CONFIG) --libs libsodium)
endif
# add TLS library flags (TODO? non-exclusive?)
ifdef FIO_NO_TLS
$(info * Skipping crypto library detection.)
else ifeq ($(call TRY_COMPILE, $(FIO_TLS_TEST_OPENSSL), $(OPENSSL_CFLAGS) $(OPENSSL_LDFLAGS)), 0)
$(info * Detected the OpenSSL library, setting HAVE_OPENSSL)
CFLAGS+=-DHAVE_OPENSSL $(OPENSSL_CFLAGS)
LDFLAGS+=$(OPENSSL_LDFLAGS)
else ifeq ($(call TRY_COMPILE, "\#include <sodium.h.h>\\n int main(void) {}", $(LIBSODIUM_CFLAGS) $(LIBSODIUM_LDFLAGS)) , 0)
# Sodium Crypto Library: https://doc.libsodium.org/usage
$(info * Detected the Sodium library, setting HAVE_SODIUM)
CFLAGS+=-DHAVE_SODIUM $(LIBSODIUM_CFLAGS)
LDFLAGS+=$(LIBSODIUM_LDFLAGS)
else
$(info * No compatible SSL/TLS library detected.)
endif # FIO_NO_TLS
endif # TEST4CRYPTO
#############################################################################
# ZLib Library Detection
# (no need to edit)
#############################################################################
ifneq ($(strip $(TEST4ZLIB)),)
ifeq ($(call TRY_HEADER_AND_FUNC, zlib.h, 0, -lz) , 0)
$(info * Detected the zlib library, setting HAVE_ZLIB)
CFLAGS+= -DHAVE_ZLIB
LDFLAGS+= -lz
endif
endif #TEST4ZLIB
#############################################################################
# PostgreSQL Library Detection
# (no need to edit)
#############################################################################
ifneq ($(strip $(TEST4PG)),)
ifeq ($(call TRY_HEADER_AND_FUNC, libpq-fe.h, 0, -lpg) , 0)
$(info * Detected the PostgreSQL library, setting HAVE_POSTGRESQL)
CFLAGS+=-DHAVE_POSTGRESQL
LDFLAGS+=-lpg
else ifeq ($(call TRY_HEADER_AND_FUNC, "/usr/include/postgresql/libpq-fe.h", 0, "-lpg") , 0)
$(info * Detected the PostgreSQL library, setting HAVE_POSTGRESQL)
CFLAGS+=-DHAVE_POSTGRESQL -I/usr/include/postgresql
LDFLAGS+=-lpg
endif
endif # TEST4PG
# #############################################################################
# SQLite3 Library Detection
# (no need to edit)
#############################################################################
ifneq ($(strip $(TEST4SQLITE3)),)
ifeq ($(call TRY_HEADER_AND_FUNC, sqlite3.h, sqlite3_open, -lsqlite3) , 0)
$(info * Detected the SQLite3 library, setting HAVE_SQLITE3)
CFLAGS+= -DHAVE_SQLITE3
LDFLAGS+=-lsqlite3
endif
endif #TEST4SQLITE3
#############################################################################
# Help
#############################################################################
help:
@echo "Available targets:"
@echo " all - Build the project and copy headers (default)"
@echo " test - Build and run tests"
@echo " format - Format code with clang-format"
@echo " lint - Lint code with clang-tidy"
@echo " install - Install binary and headers to $(INSTALL_PREFIX)"
@echo " clean - Remove build artifacts"
@echo " help - Show this help message"
#############################################################################
# Cleanup
#############################################################################
clean:
@echo "Cleaning build artifacts..."
@rm -rf $(BUILD_DIR) $(PROJECT)
@echo "Clean complete!"