OSDN Git Service

Added language bindings for Java.
[slunkcrypt/SlunkCrypt.git] / Makefile
1 # ---------------------------------------------------------------------------
2 # Options
3 # ---------------------------------------------------------------------------
4
5 DEBUG  ?= 0
6 NALYZE ?= 0
7 ASAN   ?= 0
8 STATIC ?= 0
9 SHARED ?= 0
10 FLTO   ?= 0
11 FPGO   ?= 0
12 STRIP  ?= 0
13 CPU    ?= 0
14 THREAD ?= 1
15
16 $(info Options: DEBUG=$(DEBUG), NALYZE=$(NALYZE), ASAN=$(ASAN), STATIC=$(STATIC), SHARED=$(SHARED), FLTO=$(FLTO), FPGO=$(FPGO), STRIP=$(STRIP), CPU=$(CPU), THREAD=$(THREAD))
17
18 ifneq ($(SHARED),0)
19   ifneq ($(STATIC),0)
20     $(error Options SHARED=1 and STATIC=1 are mutually exclusive!)
21   endif
22 endif
23
24 # ---------------------------------------------------------------------------
25 # Directories
26 # ---------------------------------------------------------------------------
27
28 SUBDIR_APP := frontend
29 SUBDIR_LIB := libslunkcrypt
30
31 # ---------------------------------------------------------------------------
32 # Flags
33 # ---------------------------------------------------------------------------
34
35 CFLAGS = -I$(SUBDIR_LIB)/include -std=gnu99 -Wall -pedantic
36
37 ifneq (,$(firstword $(filter 32 64,$(CPU))))
38   CFLAGS += -m$(firstword $(CPU))
39 endif
40 ifneq (,$(firstword $(TARGET)))
41   CFLAGS += --target=$(firstword $(TARGET))
42   LDFLGS += --target=$(firstword $(TARGET))
43 endif
44
45 ifneq (,$(firstword $(MARCH)))
46   CFLAGS += -march=$(firstword $(MARCH))
47 endif
48 ifneq (,$(firstword $(MTUNE)))
49   CFLAGS += -mtune=$(firstword $(MTUNE))
50 endif
51
52 ifneq ($(ASAN),0)
53   CONFIG := _a
54   CFLAGS += -O1 -g -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
55 else
56   ifneq ($(DEBUG),0)
57     CONFIG := _g
58     CFLAGS += -Og -g
59   else
60     CFLAGS += -O3 -DNDEBUG
61     ifneq ($(FLTO),0)
62       CFLAGS += -flto
63     endif
64     ifneq ($(FPGO),0)
65       CFLAGS += -fprofile-$(firstword $(FPGO))
66     endif
67   endif
68 endif
69 ifneq ($(NALYZE),0)
70   CFLAGS += -fanalyzer
71 endif
72
73 MACHINE := $(strip $(shell $(CC) -dumpmachine))
74 ifeq (,$(MACHINE))
75   $(error Failed to determine target machine, please check CC is working!)
76 else
77   $(info Target machine type: $(MACHINE))
78 endif
79
80 ifneq (,$(firstword $(filter %mingw32 %-windows-gnu %-cygwin %-cygnus,$(MACHINE))))
81   EXE_SUFFIX := .exe
82   LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),dll,lib)
83 else
84   LIB_SUFFIX := .$(if $(subst 0,,$(SHARED)),$(if $(findstring -apple-darwin,$(MACHINE)),dylib,so),a)
85 endif
86
87 ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
88   LDFLGS += -mconsole -municode
89 endif
90
91 ifeq ($(STATIC),1)
92   LDFLGS += -static
93 endif
94
95 ifneq ($(STRIP),0)
96   LDFLGS += -s
97 endif
98
99 ifeq ($(THREAD),1)
100   LDFLGS += -lpthread
101 else
102   CFLAGS += -DSLUNKBUILD_NOTHREADS
103 endif
104
105 ifneq (,$(firstword $(filter %-pc-haiku %-unknown-haiku,$(MACHINE))))
106   LDFLGS += -lbsd
107 endif
108
109 APP_CFLAGS = $(CFLAGS)
110 APP_LDFLGS = $(LDFLGS) -L$(SUBDIR_LIB)/lib -l$(VERSION_LIB)
111 LIB_CFLAGS = $(CFLAGS)
112 LIB_LDFLGS = $(LDFLGS)
113
114 ifneq ($(SHARED),0)
115   LIB_CFLAGS += -fPIC
116   ifneq (,$(firstword $(filter %-w64-mingw32 %w64-windows-gnu,$(MACHINE))))
117     LIB_LDFLGS = -Wl,--out-implib,"$@.a" $(LDFLGS)
118   endif
119 endif
120
121 # ---------------------------------------------------------------------------
122 # File names
123 # ---------------------------------------------------------------------------
124
125 VERSION_LIB := slunkcrypt$(CONFIG)-1
126
127 OUTNAME_APP := slunkcrypt$(CONFIG)$(EXE_SUFFIX)
128 OUTNAME_LIB := lib$(VERSION_LIB)$(LIB_SUFFIX)
129
130 OUTPATH_APP := $(SUBDIR_APP)/bin/$(OUTNAME_APP)
131 OUTPATH_LIB := $(SUBDIR_LIB)/lib/$(OUTNAME_LIB)
132
133 SOURCES_APP := $(wildcard $(SUBDIR_APP)/src/*.c)
134 OBJECTS_APP := $(patsubst $(SUBDIR_APP)/src/%.c,$(SUBDIR_APP)/obj/%$(CONFIG).o,$(SOURCES_APP))
135
136 SOURCES_LIB := $(wildcard $(SUBDIR_LIB)/src/*.c)
137 OBJECTS_LIB := $(patsubst $(SUBDIR_LIB)/src/%.c,$(SUBDIR_LIB)/obj/%$(CONFIG).o,$(SOURCES_LIB))
138
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))
142 endif
143
144 # ---------------------------------------------------------------------------
145 # Targets
146 # ---------------------------------------------------------------------------
147
148 .PHONY: all build clean
149
150 all: clean build
151
152 build: $(OUTPATH_APP)
153
154 $(OUTPATH_APP): $(OBJECTS_APP) $(OUTPATH_LIB)
155         @mkdir -p $(@D)
156         $(CC) $(APP_CFLAGS) $(OBJECTS_APP) -o $@ $(APP_LDFLGS)
157
158 $(OUTPATH_LIB): $(OBJECTS_LIB)
159         @mkdir -p $(@D)
160 ifneq ($(SHARED),0)
161         $(CC) $(LIB_CFLAGS) $^ -shared -o $@ $(LIB_LDFLGS)
162 else
163         $(AR) rcs $@ $^
164 endif
165
166 $(SUBDIR_APP)/obj/%$(CONFIG).o: $(SUBDIR_APP)/src/%.c
167         @mkdir -p $(@D)
168         $(CC) $(APP_CFLAGS) -c $< -o $@
169
170 $(SUBDIR_APP)/obj/%.rsrc.o: $(SUBDIR_APP)/res/%.rc
171         @mkdir -p $(@D)
172         windres -o $@ $<
173
174 $(SUBDIR_LIB)/obj/%$(CONFIG).o: $(SUBDIR_LIB)/src/%.c
175         @mkdir -p $(@D)
176         $(CC) $(LIB_CFLAGS) -c $< -o $@
177
178 clean:
179         $(RM) $(SUBDIR_APP)/obj/* $(SUBDIR_APP)/lib/* $(SUBDIR_APP)/bin/*
180         $(RM) $(SUBDIR_LIB)/obj/* $(SUBDIR_LIB)/lib/* $(SUBDIR_LIB)/bin/*