deployd/Makefile
2025-08-02 02:03:28 +03:00

105 lines
5.8 KiB
Makefile

LIBS := -lssl -lcrypto -lsqlite3
ifeq ($(NOQA),)
CFLAGS += -std=c99 -Wall -Wextra -Wpedantic -pedantic -Wshadow -Werror -Wconversion -Wformat -Wuninitialized -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wredundant-decls -Wfloat-equal -Wcast-qual -Wnested-externs -Wvla -Winline -Wmissing-format-attribute -Wmissing-noreturn -pedantic-errors -Wformat-security -Wsign-conversion
endif
ifneq ($(READLINE),)
CFLAGS += -DDP_WITH_READLINE
LIBS += -lreadline
endif
SERVER_DIR := server
CLIENT_DIR := client
DEPLOYER_DIR := script
PREFIX ?= /usr/local
BINDIR := $(PREFIX)/bin
DATADIR := $(PREFIX)/share/deployd
OBJ_DIR := obj
SERVER_OBJ_DIR := $(OBJ_DIR)/server
CLIENT_OBJ_DIR := $(OBJ_DIR)/client
DEPLOYER_OBJ_DIR := $(OBJ_DIR)/deployer
DEPLOYER_SRC_FILES := $(wildcard $(DEPLOYER_DIR)/*.c)
DEPLOYER_OBJ_FILES := $(patsubst $(DEPLOYER_DIR)/%.c,$(DEPLOYER_OBJ_DIR)/%.o,$(DEPLOYER_SRC_FILES))
DEPLOYER_SRC_FILES_DEBUG := $(wildcard $(DEPLOYER_DIR)/*.c)
DEPLOYER_OBJ_FILES_DEBUG := $(patsubst $(DEPLOYER_DIR)/%.c,$(DEPLOYER_OBJ_DIR)/debug_%.o,$(DEPLOYER_SRC_FILES_DEBUG))
SERVER_SRC_FILES := $(wildcard $(SERVER_DIR)/*.c)
SERVER_OBJ_FILES := $(patsubst $(SERVER_DIR)/%.c,$(SERVER_OBJ_DIR)/%.o,$(SERVER_SRC_FILES))
CLIENT_SRC_FILES := $(wildcard $(CLIENT_DIR)/*.c)
CLIENT_OBJ_FILES := $(patsubst $(CLIENT_DIR)/%.c,$(CLIENT_OBJ_DIR)/%.o,$(CLIENT_SRC_FILES))
.PHONY: all clean strip
all: deployer deployd libserver.a deployd-client
.PHONY: deployer
# I must require gcc for compiler flags. I do *not* want to fall into security issues due to this.
deployer: $(DEPLOYER_OBJ_FILES) libserver.a
gcc -o $@ -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Wpedantic -pedantic -Wshadow -Werror -Wconversion -Wformat -Wuninitialized -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wredundant-decls -Wfloat-equal -Wcast-qual -Wnested-externs -Wvla -Winline -Wmissing-format-attribute -Wmissing-noreturn -pedantic-errors -Wformat-security -Wsign-conversion -s -O2 -fstack-protector-strong -fstack-clash-protection -D_FORTIFY_SOURCE=2 -flto -fPIE -pie -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,--as-needed -Wl,--no-copy-dt-needed-entries $^
strip --remove-section=.note.gnu.gold-version --remove-section=.note --remove-section=.gnu.version --remove-section=.eh_frame --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag --strip-symbol=__gmon_start__ --remove-section=.comment --remove-section=.eh_frame_ptr --strip-unneeded --strip-all --strip-debug --merge-notes --strip-dwo --discard-all --discard-locals --verbose $@
chown root:root $@
chmod 4500 $@
deployer-debug: $(DEPLOYER_OBJ_FILES_DEBUG) libserver.a
gcc -o deployer -std=c11 -D_DEFAULT_SOURCE -ggdb -O0 -fsanitize=undefined -fsanitize=address -Wall -Wextra -Wpedantic -pedantic -Wshadow -Werror -Wconversion -Wformat -Wuninitialized -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wredundant-decls -Wfloat-equal -Wcast-qual -Wnested-externs -Wvla -Winline -Wmissing-format-attribute -Wmissing-noreturn -pedantic-errors -Wformat-security -Wsign-conversion -Wl,-z,relro,-z,now $^
chown root:root deployer
chmod 4550 deployer
deployd: $(SERVER_OBJ_FILES)
$(CC) -o $@ $(CFLAGS) $(F_CFLAGS) $^ $(LIBS) $(LDFLAGS) $(F_LDFLAGS)
libserver.a: $(SERVER_OBJ_FILES)
ar rcs $@ $^
deployd-client: $(CLIENT_OBJ_FILES) libserver.a
$(CC) -o $@ $(CFLAGS) $(F_CFLAGS) -I$(SERVER_DIR) $^ libserver.a $(LIBS) $(LDFLAGS) $(F_LDFLAGS)
$(SERVER_OBJ_DIR):
mkdir -p $@
$(CLIENT_OBJ_DIR):
mkdir -p $@
$(DEPLOYER_OBJ_DIR):
mkdir -p $@
$(SERVER_OBJ_DIR)/%.o: $(SERVER_DIR)/%.c | $(SERVER_OBJ_DIR)
$(CC) -c -o $@ $(CFLAGS) $< $(LDFLAGS)
$(CLIENT_OBJ_DIR)/%.o: $(CLIENT_DIR)/%.c | $(CLIENT_OBJ_DIR)
$(CC) -c -o $@ $(CFLAGS) -I. $< $(LDFLAGS)
$(DEPLOYER_OBJ_DIR)/%.o: $(DEPLOYER_DIR)/%.c | $(DEPLOYER_OBJ_DIR)
gcc -c -o $@ -I. -std=c11 -D_DEFAULT_SOURCE -Wall -Wextra -Wpedantic -pedantic -Wshadow -Werror -Wconversion -Wformat -Wuninitialized -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wredundant-decls -Wfloat-equal -Wcast-qual -Wnested-externs -Wvla -Winline -Wmissing-format-attribute -Wmissing-noreturn -pedantic-errors -Wformat-security -Wsign-conversion -s -O2 -fstack-protector-strong -fstack-clash-protection -D_FORTIFY_SOURCE=2 -flto -fPIC -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -Wl,--as-needed -Wl,--no-copy-dt-needed-entries $<
$(DEPLOYER_OBJ_DIR)/debug_%.o: $(DEPLOYER_DIR)/%.c | $(DEPLOYER_OBJ_DIR)
gcc -c -o $@ -std=c11 -D_DEFAULT_SOURCE -ggdb -O0 -fsanitize=undefined -fsanitize=address -Wall -Wextra -Wpedantic -pedantic -Wshadow -Werror -Wconversion -Wformat -Wuninitialized -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wredundant-decls -Wfloat-equal -Wcast-qual -Wnested-externs -Wvla -Winline -Wmissing-format-attribute -Wmissing-noreturn -pedantic-errors -Wformat-security -Wsign-conversion -Wl,-z,relro,-z,now $^
.PHONY: install uninstall
install: all deployer interpreter/deployer/extensions
@echo "Installing binaries to $(BINDIR)..."
install -d $(BINDIR)
install -m 755 deployd $(BINDIR)/
install -m 755 deployd-client $(BINDIR)/
install -m 4500 deployer $(BINDIR)/
@echo "Installing extensions to $(DATADIR)..."
install -d $(DATADIR)/extensions
cp -r interpreter/deployer/extensions/* $(DATADIR)/extensions/
uninstall:
rm -f $(BINDIR)/deployd $(BINDIR)/deployd-client $(BINDIR)/deployd $(BINDIR)/deployer
rm -rf $(DATADIR)/extensions/
clean:
rm -rf deployd deployd-client libserver.a $(OBJ_DIR)
strip:
strip --remove-section=.note.gnu.gold-version --remove-section=.note --remove-section=.gnu.version --remove-section=.eh_frame --remove-section=.note.gnu.build-id --remove-section=.note.ABI-tag --strip-symbol=__gmon_start__ --remove-section=.comment --remove-section=.eh_frame_ptr --strip-unneeded --strip-all --strip-debug --merge-notes --strip-dwo --discard-all --discard-locals --verbose deployd deployd-client