3 PKGCONFIG ?= pkg-config
7 PKGLIBS := libuv zlib-ng
9 PKGCPPFLAGS := $(shell $(PKGCONFIG) --cflags $(PKGLIBS))
10 PKGLDFLAGS := $(shell $(PKGCONFIG) --libs $(PKGLIBS))
11 PKGLIBPATH := $(shell $(PKGCONFIG) --variable=libdir zlib-ng)
12 WARNINGFLAGS := -Wall -Wextra -Wpedantic -Werror=odr -Werror=strict-aliasing# -Wconversion
14 CFLAGS := -pipe -march=x86-64-v3 -mtune=generic -funroll-loops -flto -fPIE
15 # https://en.wikipedia.org/wiki/X86-64#Microarchitecture_levels
16 LDFLAGS := $(PKGLDFLAGS) -Wl,-pie -lc -lm -pthread
18 CFLAGS += -fstack-protector-strong -fcf-protection
20 ifeq ($(OS),Windows_NT)
21 detected_OS := Windows
23 detected_OS := $(shell sh -c 'uname 2>/dev/null || echo Unknown')
26 ifeq ($(detected_OS),Windows)
29 ifeq ($(detected_OS),Darwin)
30 CC = /usr/local/opt/llvm/bin/clang
31 CXX = /usr/local/opt/llvm/bin/clang++
33 LDFLAGS += -L/usr/local/opt/llvm/lib/c++ -L/usr/local/opt/llvm/lib -lunwind
34 #PKGLDFLAGS := -Wl,-search_paths_first $(PKGLDFLAGS)
36 ifeq ($(detected_OS),Linux)
38 CFLAGS += -fstack-clash-protection
39 #PKGLDFLAGS := -Wl,-Bstatic $(PKGLDFLAGS) -Wl,-Bdynamic -Wl,--as-needed
40 LDFLAGS += -Wl,-z,defs -Wl,-z,now -Wl,-z,relro
41 WARNINGFLAGS += -Werror=lto-type-mismatch
44 ifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"),1)
46 LDFLAGS += -Wl,-rpath,$(PKGLIBPATH) -fuse-ld=lld
54 BUILT_PROGRAMS = salustsFstCoord3
56 SOURCES := $(foreach d,$(SRCDIR),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
57 OBJFILES := $(SOURCES:$(SRCDIR)/%.c=$(BUILDIR)/%.o)
59 VPATH := $(SRCDIR) klib
62 CPPFLAGS := $(addprefix -I,$(VPATH)) $(PKGCPPFLAGS) -D_FORTIFY_SOURCE=2 -DE4C_THREADSAFE -DE4C_NOKEYWORDS
63 CSTANDARD := -std=gnu2x# -std=c23
65 all: $(BUILT_PROGRAMS)
68 debug: override CPPFLAGS += -DDEBUG -g -fsanitize=address
69 debug: override OPT := -Og
72 release: override CPPFLAGS += -DNDEBUG -DRELEASE
73 release: override OPT := -Ofast -finline-functions -funswitch-loops
77 @: # Clean objects and executables.
79 rm -f $(BUILT_PROGRAMS)
84 $(BUILDIR)/%.o: $(SRCDIR)/%.c $(BUILDIR)
85 $(CC) -c $(CPPFLAGS) $(WARNINGFLAGS) $(CFLAGS) $(OPT) $< -o $@
87 %: $(BUILDIR)/%.o # sth. like `make uv_callback.test`
88 $(CC) $(CFLAGS) $(WARNINGFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS) -o $@
90 $(BUILT_PROGRAMS): $(OBJFILES)
91 $(CC) $(CFLAGS) $(WARNINGFLAGS) $(CPPFLAGS) $^ $(LDFLAGS) $(TARGET_ARCH) $(LOADLIBES) $(LDLIBS) -o $@
93 .SECONDARY: $(OBJFILES)
98 @echo $(THISDIR) $(MAKEFILE_LIST)
105 UV_THREADPOOL_SIZE=1 MallocNanoZone=0 ./$(BUILT_PROGRAMS) n.fq xx
106 UV_THREADPOOL_SIZE=2 valgrind -q --leak-check=yes ./$(BUILT_PROGRAMS) n.fq xx
108 .PHONY: all clean debug release test echo