OSDN Git Service

Added runtime CPU detection for SSE2 capability to the GUI front-end.
[slunkcrypt/SlunkCrypt.git] / Makefile
1 # ---------------------------------------------------------------------------
2 # Options
3 # ---------------------------------------------------------------------------
4
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 MARCH  ?= 0
14 MTUNE  ?= 0
15
16 # ---------------------------------------------------------------------------
17 # Directories
18 # ---------------------------------------------------------------------------
19
20 SUBDIR_APP := frontend
21 SUBDIR_LIB := libslunkcrypt
22
23 # ---------------------------------------------------------------------------
24 # Flags
25 # ---------------------------------------------------------------------------
26
27 CONFIG =
28 LDFLGS =
29 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall
30
31 ifneq ($(CPU),0)
32   CFLAGS += -m$(firstword $(CPU))
33 endif
34 ifneq ($(MARCH),0)
35   CFLAGS += -march=$(firstword $(MARCH))
36 endif
37 ifneq ($(MTUNE),0)
38   CFLAGS += -mtune=$(firstword $(MTUNE))
39 endif
40
41 ifneq ($(ASAN),0)
42   CONFIG := _a
43   CFLAGS += -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
44 else ifneq ($(DEBUG),0)
45   CONFIG := _g
46   CFLAGS += -Og -g
47 else
48   CFLAGS += -O3 -DNDEBUG
49 ifneq ($(FLTO),0)
50   CFLAGS += -flto
51 endif
52 ifneq ($(FPGO),0)
53   CFLAGS += -fprofile-$(firstword $(FPGO))
54 endif
55 endif
56 ifneq ($(NALYZE),0)
57   CFLAGS += -fanalyzer
58 endif
59
60 MACHINE := $(shell $(CC) -dumpmachine)
61
62 ifeq ($(MACHINE),$(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)))
63   SUFFIX := .exe
64 else
65   SUFFIX :=
66 endif
67
68 ifneq ($(MACHINE),$(filter %mingw32 %-windows-gnu,$(MACHINE)))
69   LDFLGS += -lpthread
70 endif
71
72 ifneq ($(STRIP),0)
73   LDFLGS += -s
74 endif
75
76 ifeq ($(STATIC),1)
77   LDFLGS += -static
78 endif
79
80 ifeq ($(MACHINE),$(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE)))
81   LDFLGS += -mconsole -municode
82 endif
83
84 # ---------------------------------------------------------------------------
85 # File names
86 # ---------------------------------------------------------------------------
87
88 OUTNAME_APP := slunkcrypt$(CONFIG)$(SUFFIX)
89 OUTNAME_LIB := libslunkcrypt$(CONFIG)-1.a
90
91 OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
92 OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
93
94 SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
95 OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
96
97 SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
98 OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
99
100 ifneq ($(filter %-mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE)),)
101   RCFILES_APP := $(wildcard $(SUBDIR_APP)/res/*.rc)
102   OBJECTS_APP += $(patsubst $(SUBDIR_APP)/res/%.rc,$(SUBDIR_APP)/obj/%.rsrc.o,$(RCFILES_APP))
103 endif
104
105 # ---------------------------------------------------------------------------
106 # Targets
107 # ---------------------------------------------------------------------------
108
109 .PHONY: all clean
110
111 all: $(OUTPATH_APP)
112
113 $(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
114         @mkdir -p $(@D)
115         $(CC) $(CFLAGS) $^ -o $@ $(LDFLGS)
116
117 $(OUTPATH_LIB): $(OBJECTS_LIB)
118         @mkdir -p $(@D)
119         $(AR) rcs $@ $^
120
121 $(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
122         @mkdir -p $(@D)
123         $(CC) $(CFLAGS) -c $< -o $@
124
125 $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc
126         @mkdir -p $(@D)
127         windres -o $@ $<
128
129 $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
130         @mkdir -p $(@D)
131         $(CC) $(CFLAGS) -c $< -o $@
132
133 clean:
134         $(RM) $(SUBDIR_APP)/obj/*.o $(SUBDIR_APP)/obj/*.gcda $(SUBDIR_APP)/lib/*.a $(SUBDIR_APP)/bin/*$(SUFFIX)
135         $(RM) $(SUBDIR_LIB)/obj/*.o $(SUBDIR_LIB)/obj/*.gcda $(SUBDIR_LIB)/lib/*.a $(SUBDIR_LIB)/bin/*$(SUFFIX)
136