-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.windows-gmake
287 lines (232 loc) · 7.98 KB
/
Makefile.windows-gmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
CFLAGS ?= -O2 -Wall -Wextra -std=c99 -pedantic
CPPFLAGS = -Iinclude -Isrc/win32 -D_DEFAULT_SOURCE -D_XOPEN_SOURCE=700 -D_SVID_SOURCE -fPIC
PKG_CONFIG ?= pkg-config
DESTDIR ?= /usr/local
INSTALL ?= install
PERL ?= perl
SED ?= sed
RM = del /Q
CC ?= gcc
ifndef RFC6531_FOLLOW_RFC5322
export RFC6531_FOLLOW_RFC5322 = OFF
endif
ifndef RFC6531_FOLLOW_RFC20
export RFC6531_FOLLOW_RFC20 = OFF
endif
ifndef LABELS_ALLOW_UNDERSCORE
export LABELS_ALLOW_UNDERSCORE = OFF
endif
BINDIR ?= $(DESTDIR)/bin
LIBDIR ?= $(DESTDIR)/lib
INCLUDEDIR ?= $(DESTDIR)/include
DATAROOTDIR ?= $(DESTDIR)/share
MANDIR ?= $(DATAROOTDIR)/man
MAJOR_VERSION = 1
MINOR_VERSION = 2
PATCH_VERSION = 0
VERSION = $(MAJOR_VERSION).$(MINOR_VERSION).$(PATCH_VERSION)
DLL_EXT ?= dll
LIB_EXT ?= a
DLL_TARGET = libeav.$(DLL_EXT)
LIB_TARGET = libeav.$(LIB_EXT)
BIN_TARGET = eav.exe
BIN_TARGET_STATIC = eav-static.exe
FixPath = $(subst /,\,$1)
TARGETS = $(BIN_TARGET) $(DLL_TARGET) $(LIB_TARGET)
bin_SOURCES = $(wildcard bin/*.c)
bin_OBJECTS = $(patsubst bin/%.c, bin/%.o, $(bin_SOURCES))
SOURCES = $(wildcard src/*.c)
OBJECTS = $(patsubst src/%.c, src/%.o, $(SOURCES))
win32_SOURCES = $(wildcard src/win32/*.c)
win32_OBJECTS = $(patsubst src/win32/%.c, src/win32/%.o, $(win32_SOURCES))
OBJECTS += $(win32_OBJECTS)
#----------------------------------------------------------#
ifdef FORCE_IDN
ifeq ($(FORCE_IDN),idnkit)
$(info > Force using idnkit)
WITH_IDN = idnkit
IDNKIT_DIR ?= /usr/local
DEFS ?= -DHAVE_IDNKIT -I$(IDNKIT_DIR)/include
LIBS ?= -L$(IDNKIT_DIR)/lib -lidnkit
LIBS_STATIC ?= -L$(IDNKIT_DIR)/lib -lidnkit
PARTIAL = $(wildcard partial/idnkit/*.c)
OBJECTS += $(patsubst partial/idnkit/%.c, partial/idnkit/%.o, $(PARTIAL))
else ifeq ($(FORCE_IDN),idn2)
$(info > Force using libidn2)
WITH_IDN = idn2
DEFS ?= -DHAVE_LIBIDN2 $(shell $(PKG_CONFIG) --cflags libidn2)
LIBS ?= $(shell $(PKG_CONFIG) --libs libidn2)
LIBS_STATIC ?= $(shell $(PKG_CONFIG) --static --libs libidn2)
PARTIAL = $(wildcard partial/idn2/*.c)
OBJECTS += $(patsubst partial/idn2/%.c, partial/idn2/%.o, $(PARTIAL))
else ifeq ($(FORCE_IDN),idn)
$(info > Force using libidn)
WITH_IDN = idn
DEFS ?= -DHAVE_LIBIDN $(shell $(PKG_CONFIG) --cflags libidn)
LIBS ?= $(shell $(PKG_CONFIG) --libs libidn)
LIBS_STATIC ?= $(shell $(PKG_CONFIG) --static --libs libidn)
PARTIAL = $(wildcard partial/idn/*.c)
OBJECTS += $(patsubst partial/idn/%.c, partial/idn/%.o, $(PARTIAL))
else
$(error !!! Unknown IDN library type)
endif
else
$(info > Looking for idn library ...)
ifeq ($(shell $(PKG_CONFIG) --exists "libidn2 >= 2.0.3" || echo NO),)
$(info > Found libidn2)
WITH_IDN = idn2
DEFS = -DHAVE_LIBIDN2 $(shell $(PKG_CONFIG) --cflags libidn2)
LIBS = $(shell $(PKG_CONFIG) --libs libidn2)
LIBS_STATIC = $(shell $(PKG_CONFIG) --static --libs libidn2)
PARTIAL = $(wildcard partial/idn2/*.c)
OBJECTS += $(patsubst partial/idn2/%.c, partial/idn2/%.o, $(PARTIAL))
else ifeq ($(shell $(PKG_CONFIG) --exists 'libidn' || echo NO),)
$(info > Found libidn)
WITH_IDN = idn
DEFS = -DHAVE_LIBIDN $(shell $(PKG_CONFIG) --cflags libidn)
LIBS = $(shell $(PKG_CONFIG) --libs libidn)
LIBS_STATIC = $(shell $(PKG_CONFIG) --static --libs libidn)
PARTIAL = $(wildcard partial/idn/*.c)
OBJECTS += $(patsubst partial/idn/%.c, partial/idn/%.o, $(PARTIAL))
else
$(info > Using idnkit by default)
WITH_IDN = idnkit
IDNKIT_DIR ?= /usr/local
DEFS = -DHAVE_IDNKIT -I$(IDNKIT_DIR)/include
LIBS = -L$(IDNKIT_DIR)/lib -lidnkit
LIBS_STATIC = -L$(IDNKIT_DIR)/lib -lidnkit
PARTIAL = $(wildcard partial/idnkit/*.c)
OBJECTS += $(patsubst partial/idnkit/%.c, partial/idnkit/%.o, $(PARTIAL))
endif
endif
ifeq ($(RFC6531_FOLLOW_RFC5322),ON)
CPPFLAGS += -DRFC6531_FOLLOW_RFC5322
export RFC6531_FOLLOW_RFC5322
endif
ifeq ($(RFC6531_FOLLOW_RFC20),ON)
CPPFLAGS += -DRFC6531_FOLLOW_RFC20
export RFC6531_FOLLOW_RFC20
endif
ifeq ($(LABELS_ALLOW_UNDERSCORE),ON)
CPPFLAGS += -DLABELS_ALLOW_UNDERSCORE
export LABELS_ALLOW_UNDERSCORE
endif
#----------------------------------------------------------#
CPPFLAGS += $(DEFS) $(INCLUDES)
LIB_PATH = $(realpath .)
export _defs = $(DEFS)
export _libs = $(LIBS)
export _libs_static = $(LIBS_STATIC)
export _pkg_config = $(PKG_CONFIG)
export _install = $(INSTALL)
export _idnkit_dir = $(IDNKIT_DIR)
export _destdir = $(DESTDIR)
export _objects = $(OBJECTS)
export _libpath = $(LIB_PATH)
export _withidn = $(WITH_IDN)
#----------------------------------------------------------#
.PHONY: all debug check clean docs man install libs libeav.pc csv uninstall
all: libs app
debug: CFLAGS += -g -D_DEBUG
debug: all
libs: shared static
shared: $(DLL_TARGET)
static: $(LIB_TARGET)
app: $(BIN_TARGET)
app-static: $(BIN_TARGET_STATIC)
$(BIN_TARGET): $(DLL_TARGET)
$(MAKE) -f Makefile.windows-gmake -C bin
$(BIN_TARGET_STATIC): $(LIB_TARGET)
$(MAKE) -f Makefile.windows-gmake -C bin static
$(DLL_TARGET): $(OBJECTS)
$(info library -> shared linkage)
$(CC) -shared $(LDFLAGS) -Iinclude -Wl,-soname,$(DLL_TARGET) \
-o $(DLL_TARGET) $(OBJECTS) $(LIBS)
$(LIB_TARGET): $(OBJECTS)
$(info library -> static linkage)
$(AR) rcs $@ $(OBJECTS)
%.o: %.c
$(CC) $(CPPFLAGS) $(CFLAGS) -I. -o $@ -c $<
check: $(DLL_TARGET)
$(MAKE) -f Makefile.windows-gmake -C tests check
docs: man
man:
$(MAKE) -f Makefile.windows-gmake -C docs VERSION=$(VERSION)
csv: auto tld-domains
auto:
$(PERL) util/gentld.pl include/eav/auto_tld.h src/auto_tld.c \
data/punycode.csv
tld-domains:
$(PERL) util/gen_utf8_pass_test.pl data/tld-domains.txt data/raw.csv
#----------------------------------------------------------#
ifeq ($(WITH_IDN),idnkit)
pc_cflags = -I$${includedir} -DIDN_KIT
pc_requires_private =
pc_libs_private = -L$(IDNKIT_DIR)/lib -lidnkit
else
pc_cflags = -I$${includedir}
pc_requires_private = lib$(WITH_IDN)
pc_libs_private =
endif
libeav.pc: libeav.pc.in
$(SED) \
-e 's,@version\@,$(VERSION),' \
-e 's,@prefix\@,$(DESTDIR),g' \
-e 's,@exec_prefix\@,$(DESTDIR),g' \
-e 's,@includedir\@,$(INCLUDEDIR),g' \
-e 's,@libdir\@,$(LIBDIR),g' \
-e 's,@cflags\@,$(pc_cflags),g' \
-e 's,@requires_private\@,$(pc_requires_private),g' \
-e 's,@libs_private\@,$(pc_libs_private),g' \
$< > $@
#----------------------------------------------------------#
clean: clean-tests clean-bin
$(info === cleanup)
$(RM) $(DLL_TARGET) $(LIB_TARGET) $(call FixPath,$(OBJECTS)) libeav.pc
clean-tests:
$(MAKE) -f Makefile.windows-gmake -C tests clean
clean-bin:
$(MAKE) -f Makefile.windows-gmake -C bin clean
strip: app
$(MAKE) -f Makefile.windows-gmake -C bin strip
strip-static: app-static
$(MAKE) -f Makefile.windows-gmake -C bin strip-static
#----------------------------------------------------------#
install: install-bin install-libs install-man
install-bin: $(BIN_TARGET)
$(MAKE) -f Makefile.windows-gmake -C bin install DESTDIR=$(DESTDIR)
install-bin-static: $(BIN_TARGET)
$(MAKE) -f Makefile.windows-gmake -C bin install-static DESTDIR=$(DESTDIR)
install-libs: install-shared install-static libeav.pc
$(INSTALL) -d $(DATAROOTDIR)/pkgconfig
$(INSTALL) -m 0644 libeav.pc $(DATAROOTDIR)/pkgconfig
install-shared: $(DLL_TARGET)
$(info installing shared library)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -d $(INCLUDEDIR)
$(INSTALL) -m 0644 include/eav.h $(INCLUDEDIR)
$(INSTALL) -m 0755 $(DLL_TARGET) $(LIBDIR)/$(DLL_TARGET).$(VERSION)
cd $(LIBDIR) && \
ln -snf $(DLL_TARGET).$(VERSION) $(DLL_TARGET).$(MAJOR_VERSION) && \
ln -snf $(DLL_TARGET).$(VERSION) $(DLL_TARGET)
install-static: $(LIB_TARGET)
$(info installing static library)
$(INSTALL) -d $(LIBDIR)
$(INSTALL) -d $(INCLUDEDIR)
$(INSTALL) -m 0644 include/eav.h $(INCLUDEDIR)
$(INSTALL) -m 0644 $(LIB_TARGET) $(LIBDIR)
install-man:
$(INSTALL) -d $(MANDIR)/man3
$(INSTALL) -m 0644 docs/libeav.3.gz $(MANDIR)/man3
#----------------------------------------------------------#
uninstall: uninstall-bin
$(info === uninstalling ...)
$(RM) $(DATAROOTDIR)/pkgconfig/libeav.pc
$(RM) $(INCLUDEDIR)/eav.h
$(RM) $(LIBDIR)/$(LIB_TARGET) \
$(LIBDIR)/$(DLL_TARGET).$(VERSION) \
$(LIBDIR)/$(DLL_TARGET).$(MAJOR_VERSION) \
$(LIBDIR)/$(DLL_TARGET)
$(RM) $(MANDIR)/man3/libeav.3.gz
uninstall-bin:
$(MAKE) -f Makefile.windows-gmake -C bin uninstall DESTDIR=$(DESTDIR)