2020-10-14 19:59:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Options
|
|
|
|
# ---------------------------------------------------------------------------
|
2020-10-13 23:36:58 +02:00
|
|
|
|
2020-10-21 21:58:46 +02:00
|
|
|
DEBUG ?= 0
|
2021-04-07 01:40:05 +02:00
|
|
|
NALYZE ?= 0
|
2020-10-29 18:12:21 +01:00
|
|
|
ASAN ?= 0
|
2020-10-21 21:58:46 +02:00
|
|
|
STATIC ?= 0
|
2024-06-22 16:49:02 +02:00
|
|
|
SHARED ?= 0
|
2020-11-01 22:46:25 +01:00
|
|
|
FLTO ?= 0
|
2020-10-29 18:12:21 +01:00
|
|
|
FPGO ?= 0
|
2020-10-31 16:33:53 +01:00
|
|
|
STRIP ?= 0
|
2021-04-19 22:21:07 +02:00
|
|
|
CPU ?= 0
|
2022-04-09 16:40:16 +02:00
|
|
|
THREAD ?= 1
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2024-06-22 16:49:02 +02:00
|
|
|
$(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), SHARED=$(SHARED), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD))
|
|
|
|
|
|
|
|
ifneq ($(SHARED),0)
|
|
|
|
ifneq ($(STATIC),0)
|
|
|
|
$(error Options SHARED=1 and STATIC=1 are mutually exclusive!)
|
|
|
|
endif
|
|
|
|
endif
|
2022-09-20 21:53:57 +02:00
|
|
|
|
2020-10-14 19:59:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
2020-10-19 21:56:12 +02:00
|
|
|
# Directories
|
2020-10-14 19:59:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
SUBDIR_APP := frontend
|
|
|
|
SUBDIR_LIB := libslunkcrypt
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Flags
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
2022-09-20 21:53:57 +02:00
|
|
|
CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall -pedantic
|
2021-04-19 22:21:07 +02:00
|
|
|
|
2022-05-06 00:33:45 +02:00
|
|
|
ifneq (,$(firstword $(filter 32 64,$(CPU))))
|
2021-04-19 22:21:07 +02:00
|
|
|
CFLAGS += -m$(firstword $(CPU))
|
|
|
|
endif
|
2022-05-06 00:33:45 +02:00
|
|
|
ifneq (,$(firstword $(TARGET)))
|
2022-04-09 16:40:16 +02:00
|
|
|
CFLAGS += --target=$(firstword $(TARGET))
|
|
|
|
LDFLGS += --target=$(firstword $(TARGET))
|
|
|
|
endif
|
|
|
|
|
2022-05-06 00:33:45 +02:00
|
|
|
ifneq (,$(firstword $(MARCH)))
|
2021-04-19 22:21:07 +02:00
|
|
|
CFLAGS += -march=$(firstword $(MARCH))
|
|
|
|
endif
|
2022-05-06 00:33:45 +02:00
|
|
|
ifneq (,$(firstword $(MTUNE)))
|
2021-04-19 22:21:07 +02:00
|
|
|
CFLAGS += -mtune=$(firstword $(MTUNE))
|
|
|
|
endif
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2021-04-07 01:40:05 +02:00
|
|
|
ifneq ($(ASAN),0)
|
|
|
|
CONFIG := _a
|
|
|
|
CFLAGS += -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
|
2020-10-14 19:59:12 +02:00
|
|
|
else
|
2022-09-22 00:08:05 +02:00
|
|
|
ifneq ($(DEBUG),0)
|
|
|
|
CONFIG := _g
|
|
|
|
CFLAGS += -Og -g
|
|
|
|
else
|
|
|
|
CFLAGS += -O3 -DNDEBUG
|
|
|
|
ifneq ($(FLTO),0)
|
|
|
|
CFLAGS += -flto
|
|
|
|
endif
|
|
|
|
ifneq ($(FPGO),0)
|
|
|
|
CFLAGS += -fprofile-$(firstword $(FPGO))
|
|
|
|
endif
|
|
|
|
endif
|
2020-11-01 22:46:25 +01:00
|
|
|
endif
|
2021-04-07 01:40:05 +02:00
|
|
|
ifneq ($(NALYZE),0)
|
|
|
|
CFLAGS += -fanalyzer
|
|
|
|
endif
|
2020-10-29 18:12:21 +01:00
|
|
|
|
2022-09-20 21:53:57 +02:00
|
|
|
MACHINE := $(strip $(shell $(CC) -dumpmachine))
|
|
|
|
ifeq (,$(MACHINE))
|
|
|
|
$(error Failed to determine target machine, please check CC is working!)
|
|
|
|
else
|
|
|
|
$(info Target machine type: $(MACHINE))
|
|
|
|
endif
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2022-05-06 00:33:45 +02:00
|
|
|
ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE))))
|
2022-09-22 00:08:05 +02:00
|
|
|
EXE_SUFFIX := .exe
|
2024-11-14 23:14:06 +01:00
|
|
|
LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),dll,a)
|
2024-06-22 16:49:02 +02:00
|
|
|
else
|
|
|
|
LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),$(if $(findstring -apple-darwin,$(MACHINE)),dylib,so),a)
|
2020-10-13 23:36:58 +02:00
|
|
|
endif
|
|
|
|
|
2022-09-20 23:58:45 +02:00
|
|
|
ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
|
|
|
|
LDFLGS += -mconsole -municode
|
2020-10-31 16:33:53 +01:00
|
|
|
endif
|
|
|
|
|
2020-10-21 21:58:46 +02:00
|
|
|
ifeq ($(STATIC),1)
|
|
|
|
LDFLGS += -static
|
|
|
|
endif
|
|
|
|
|
2022-09-20 23:58:45 +02:00
|
|
|
ifneq ($(STRIP),0)
|
|
|
|
LDFLGS += -s
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(THREAD),1)
|
|
|
|
LDFLGS += -lpthread
|
|
|
|
else
|
|
|
|
CFLAGS += -DSLUNKBUILD_NOTHREADS
|
2020-10-14 19:59:12 +02:00
|
|
|
endif
|
|
|
|
|
2022-09-29 21:05:16 +02:00
|
|
|
ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE))))
|
2022-05-08 16:11:52 +02:00
|
|
|
LDFLGS += -lbsd
|
|
|
|
endif
|
|
|
|
|
2024-06-22 16:49:02 +02:00
|
|
|
APP_CFLAGS = $(CFLAGS)
|
|
|
|
APP_LDFLGS = $(LDFLGS) -L$(SUBDIR_LIB)/lib -l$(VERSION_LIB)
|
|
|
|
LIB_CFLAGS = $(CFLAGS)
|
|
|
|
LIB_LDFLGS = $(LDFLGS)
|
|
|
|
|
|
|
|
ifneq ($(SHARED),0)
|
|
|
|
LIB_CFLAGS += -fPIC
|
|
|
|
ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
|
|
|
|
LIB_LDFLGS = -Wl,--out-implib,"$@.a" $(LDFLGS)
|
|
|
|
endif
|
|
|
|
endif
|
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# File names
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
2024-06-22 16:49:02 +02:00
|
|
|
VERSION_LIB := slunkcrypt$(CONFIG)-1
|
|
|
|
|
2022-09-22 00:08:05 +02:00
|
|
|
OUTNAME_APP := slunkcrypt$(CONFIG)$(EXE_SUFFIX)
|
2024-06-22 16:49:02 +02:00
|
|
|
OUTNAME_LIB := lib$(VERSION_LIB)$(LIB_SUFFIX)
|
2020-10-19 21:56:12 +02:00
|
|
|
|
|
|
|
OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
|
|
|
|
OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
|
|
|
|
OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
|
|
|
|
OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2020-10-21 17:07:03 +02:00
|
|
|
ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
|
2020-10-20 17:46:18 +02:00
|
|
|
RCFILES_APP := $(wildcard $(SUBDIR_APP)/res/*.rc)
|
|
|
|
OBJECTS_APP += $(patsubst $(SUBDIR_APP)/res/%.rc,$(SUBDIR_APP)/obj/%.rsrc.o,$(RCFILES_APP))
|
|
|
|
endif
|
|
|
|
|
2020-10-14 19:59:12 +02:00
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
# Targets
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
2024-06-22 16:49:02 +02:00
|
|
|
.PHONY: all build clean
|
2020-10-13 23:36:58 +02:00
|
|
|
|
2024-06-22 16:49:02 +02:00
|
|
|
all: clean build
|
|
|
|
|
|
|
|
build: $(OUTPATH_APP)
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
$(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
|
2020-10-14 19:59:12 +02:00
|
|
|
@mkdir -p $(@D)
|
2024-06-22 16:49:02 +02:00
|
|
|
$(CC) $(APP_CFLAGS) $(OBJECTS_APP) -o $@ $(APP_LDFLGS)
|
2020-10-14 19:59:12 +02:00
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
$(OUTPATH_LIB): $(OBJECTS_LIB)
|
2020-10-14 19:59:12 +02:00
|
|
|
@mkdir -p $(@D)
|
2024-06-22 16:49:02 +02:00
|
|
|
ifneq ($(SHARED),0)
|
|
|
|
$(CC) $(LIB_CFLAGS) $^ -shared -o $@ $(LIB_LDFLGS)
|
|
|
|
else
|
2020-10-14 19:59:12 +02:00
|
|
|
$(AR) rcs $@ $^
|
2024-06-22 16:49:02 +02:00
|
|
|
endif
|
2020-10-13 23:36:58 +02:00
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
$(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
|
2020-10-14 19:59:12 +02:00
|
|
|
@mkdir -p $(@D)
|
2024-06-22 16:49:02 +02:00
|
|
|
$(CC) $(APP_CFLAGS) -c $< -o $@
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2020-10-20 17:46:18 +02:00
|
|
|
$(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc
|
|
|
|
@mkdir -p $(@D)
|
|
|
|
windres -o $@ $<
|
|
|
|
|
2020-10-19 21:56:12 +02:00
|
|
|
$(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
|
|
|
|
@mkdir -p $(@D)
|
2024-06-22 16:49:02 +02:00
|
|
|
$(CC) $(LIB_CFLAGS) -c $< -o $@
|
2020-10-19 21:56:12 +02:00
|
|
|
|
2020-10-13 23:36:58 +02:00
|
|
|
clean:
|
2024-06-22 16:49:02 +02:00
|
|
|
$(RM) $(SUBDIR_APP)/obj/* $(SUBDIR_APP)/lib/* $(SUBDIR_APP)/bin/*
|
|
|
|
$(RM) $(SUBDIR_LIB)/obj/* $(SUBDIR_LIB)/lib/* $(SUBDIR_LIB)/bin/*
|