1 # ---------------------------------------------------------------------------
3 # ---------------------------------------------------------------------------
16 $(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), SHARED=$(SHARED), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD))
20 $(error Options SHARED=1 and STATIC=1 are mutually exclusive!)
24 # ---------------------------------------------------------------------------
26 # ---------------------------------------------------------------------------
28 SUBDIR_APP := frontend
29 SUBDIR_LIB := libslunkcrypt
31 # ---------------------------------------------------------------------------
33 # ---------------------------------------------------------------------------
35 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall -pedantic
37 ifneq (,$(firstword $(filter 32 64,$(CPU))))
38 CFLAGS += -m$(firstword $(CPU))
40 ifneq (,$(firstword $(TARGET)))
41 CFLAGS += --target=$(firstword $(TARGET))
42 LDFLGS += --target=$(firstword $(TARGET))
45 ifneq (,$(firstword $(MARCH)))
46 CFLAGS += -march=$(firstword $(MARCH))
48 ifneq (,$(firstword $(MTUNE)))
49 CFLAGS += -mtune=$(firstword $(MTUNE))
54 CFLAGS += -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
60 CFLAGS += -O3 -DNDEBUG
65 CFLAGS += -fprofile-$(firstword $(FPGO))
73 MACHINE := $(strip $(shell $(CC) -dumpmachine))
75 $(error Failed to determine target machine, please check CC is working!)
77 $(info Target machine type: $(MACHINE))
80 ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE))))
82 LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),dll,lib)
84 LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),$(if $(findstring -apple-darwin,$(MACHINE)),dylib,so),a)
87 ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
88 LDFLGS += -mconsole -municode
102 CFLAGS += -DSLUNKBUILD_NOTHREADS
105 ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE))))
109 APP_CFLAGS = $(CFLAGS)
110 APP_LDFLGS = $(LDFLGS) -L$(SUBDIR_LIB)/lib -l$(VERSION_LIB)
111 LIB_CFLAGS = $(CFLAGS)
112 LIB_LDFLGS = $(LDFLGS)
116 ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
117 LIB_LDFLGS = -Wl,--out-implib,"$@.a" $(LDFLGS)
121 # ---------------------------------------------------------------------------
123 # ---------------------------------------------------------------------------
125 VERSION_LIB := slunkcrypt$(CONFIG)-1
127 OUTNAME_APP := slunkcrypt$(CONFIG)$(EXE_SUFFIX)
128 OUTNAME_LIB := lib$(VERSION_LIB)$(LIB_SUFFIX)
130 OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
131 OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
133 SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
134 OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
136 SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
137 OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
139 ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
140 RCFILES_APP := $(wildcard $(SUBDIR_APP)/res/*.rc)
141 OBJECTS_APP += $(patsubst $(SUBDIR_APP)/res/%.rc,$(SUBDIR_APP)/obj/%.rsrc.o,$(RCFILES_APP))
144 # ---------------------------------------------------------------------------
146 # ---------------------------------------------------------------------------
148 .PHONY: all build clean
152 build: $(OUTPATH_APP)
154 $(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
156 $(CC) $(APP_CFLAGS) $(OBJECTS_APP) -o $@ $(APP_LDFLGS)
158 $(OUTPATH_LIB): $(OBJECTS_LIB)
161 $(CC) $(LIB_CFLAGS) $^ -shared -o $@ $(LIB_LDFLGS)
166 $(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
168 $(CC) $(APP_CFLAGS) -c $< -o $@
170 $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc
174 $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
176 $(CC) $(LIB_CFLAGS) -c $< -o $@
179 $(RM) $(SUBDIR_APP)/obj/* $(SUBDIR_APP)/lib/* $(SUBDIR_APP)/bin/*
180 $(RM) $(SUBDIR_LIB)/obj/* $(SUBDIR_LIB)/lib/* $(SUBDIR_LIB)/bin/*