Fixed detection of 32-Bit (x86) version of Haiku OS.
[slunkcrypt.git] / Makefile
blobe90eea64deb681b94d0f3998d152f2b9f9fb4ad6
1 # ---------------------------------------------------------------------------
2 # Options
3 # ---------------------------------------------------------------------------
5 DEBUG ?= 0
6 NALYZE ?= 0
7 ASAN ?= 0
8 STATIC ?= 0
9 FLTO ?= 0
10 FPGO ?= 0
11 STRIP ?= 0
12 CPU ?= 0
13 THREAD ?= 1
15 $(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD))
17 # ---------------------------------------------------------------------------
18 # Directories
19 # ---------------------------------------------------------------------------
21 SUBDIR_APP := frontend
22 SUBDIR_LIB := libslunkcrypt
24 # ---------------------------------------------------------------------------
25 # Flags
26 # ---------------------------------------------------------------------------
28 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall -pedantic
30 ifneq (,$(firstword $(filter 32 64,$(CPU))))
31 CFLAGS += -m$(firstword $(CPU))
32 endif
33 ifneq (,$(firstword $(TARGET)))
34 CFLAGS += --target=$(firstword $(TARGET))
35 LDFLGS += --target=$(firstword $(TARGET))
36 endif
38 ifneq (,$(firstword $(MARCH)))
39 CFLAGS += -march=$(firstword $(MARCH))
40 endif
41 ifneq (,$(firstword $(MTUNE)))
42 CFLAGS += -mtune=$(firstword $(MTUNE))
43 endif
45 ifneq ($(ASAN),0)
46 CONFIG := _a
47 CFLAGS += -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
48 else
49 ifneq ($(DEBUG),0)
50 CONFIG := _g
51 CFLAGS += -Og -g
52 else
53 CFLAGS += -O3 -DNDEBUG
54 ifneq ($(FLTO),0)
55 CFLAGS += -flto
56 endif
57 ifneq ($(FPGO),0)
58 CFLAGS += -fprofile-$(firstword $(FPGO))
59 endif
60 endif
61 endif
62 ifneq ($(NALYZE),0)
63 CFLAGS += -fanalyzer
64 endif
66 MACHINE := $(strip $(shell $(CC) -dumpmachine))
67 ifeq (,$(MACHINE))
68 $(error Failed to determine target machine, please check CC is working!)
69 else
70 $(info Target machine type: $(MACHINE))
71 endif
73 ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE))))
74 EXE_SUFFIX := .exe
75 endif
77 ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
78 LDFLGS += -mconsole -municode
79 endif
81 ifeq ($(STATIC),1)
82 LDFLGS += -static
83 endif
85 ifneq ($(STRIP),0)
86 LDFLGS += -s
87 endif
89 ifeq ($(THREAD),1)
90 LDFLGS += -lpthread
91 else
92 CFLAGS += -DSLUNKBUILD_NOTHREADS
93 endif
95 ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE))))
96 LDFLGS += -lbsd
97 endif
99 # ---------------------------------------------------------------------------
100 # File names
101 # ---------------------------------------------------------------------------
103 OUTNAME_APP := slunkcrypt$(CONFIG)$(EXE_SUFFIX)
104 OUTNAME_LIB := libslunkcrypt$(CONFIG)-1.a
106 OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
107 OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
109 SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
110 OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
112 SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
113 OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
115 ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
116 RCFILES_APP := $(wildcard $(SUBDIR_APP)/res/*.rc)
117 OBJECTS_APP += $(patsubst $(SUBDIR_APP)/res/%.rc,$(SUBDIR_APP)/obj/%.rsrc.o,$(RCFILES_APP))
118 endif
120 # ---------------------------------------------------------------------------
121 # Targets
122 # ---------------------------------------------------------------------------
124 .PHONY: all clean
126 all: $(OUTPATH_APP)
128 $(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
129 @mkdir -p $(@D)
130 $(CC) $(CFLAGS) $^ -o $@ $(LDFLGS)
132 $(OUTPATH_LIB): $(OBJECTS_LIB)
133 @mkdir -p $(@D)
134 $(AR) rcs $@ $^
136 $(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
137 @mkdir -p $(@D)
138 $(CC) $(CFLAGS) -c $< -o $@
140 $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc
141 @mkdir -p $(@D)
142 windres -o $@ $<
144 $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
145 @mkdir -p $(@D)
146 $(CC) $(CFLAGS) -c $< -o $@
148 clean:
149 $(RM) $(SUBDIR_APP)/obj/*.o $(SUBDIR_APP)/obj/*.gcda $(SUBDIR_APP)/lib/*.a $(SUBDIR_APP)/bin/*$(EXE_SUFFIX)
150 $(RM) $(SUBDIR_LIB)/obj/*.o $(SUBDIR_LIB)/obj/*.gcda $(SUBDIR_LIB)/lib/*.a $(SUBDIR_LIB)/bin/*$(EXE_SUFFIX)