-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
313 lines (244 loc) · 6.98 KB
/
makefile
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
## makefile for LangIdent
FRAMEPAC=./framepac
DESTDIR=/usr/bin
DBDIR=/usr/share/langident
SHAREDLIB=
OBJS = build/langid.o \
build/mtrie.o \
build/prepfile.o \
build/ptrie.o \
build/scan_langid.o \
build/smooth.o \
build/trie.o \
build/trigram.o
EXES = bin/mklangid \
bin/romanize \
bin/subsample \
bin/whatlang
DISTFILES = COPYING README makefile manual.txt *.C *.h \
mklangid romanize whatlang
LIBRARY=langident.a
#########################################################################
## define the compiler
CC=g++ --std=c++11
CCLINK=$(CC)
CPUTYPE = -D__386__ -D__586__ -D__886__
#########################################################################
## define compilation options
ifndef BUILD_DBG
### compile fully optimized for distribution
BUILD_DBG=0
### compile with debugging info
#BUILD_DBG=1
### compile with debugging info and all optimizations off
#BUILD_DBG=2
endif
# build statically-linked executable (1=yes, 0=no)
#STATIC?=1
STATIC?=0
# enable multi-threading? (1=yes, 0=no)
THREADS?=1
#THREADS?=0
ifndef NODEBUG
#NODEBUG=-DNDEBUG
endif
ifndef GDB
#GDB = -ggdb3
endif
ifeq ($(DO_PROFILE),1)
PROFILE=-pg
#PROFILE=-DPURIFY
else
ifndef PROFILE
PROFILE=
endif
endif
ifeq ($(SANE),1)
SANITIZE=-fsanitize=thread -fPIE -DHELGRIND
LINKSAN=-pie
else ifeq ($(SANE),2)
SANITIZE=-fsanitize=address -fno-omit-frame-pointer -DPURIFY
else ifeq ($(SANE),3)
SANITIZE=-fsanitize=leak -DPURIFY
else ifeq ($(SANE),4)
SANITIZE=-fsanitize=memory -fno-omit-frame-pointer
else ifeq ($(SANE),5)
SANITIZE=-fsanitize=undefined
endif
ifndef CPU
## Uncomment the appropriate CPU type
### 486
#CPU=4
### Pentium
#CPU=5
### PentiumPro or higher
#CPU=6
### AMD Athlon; not supported by GCC 2.x
#CPU=7
### AMD64/x86_64 CPUs in 64-bit mode; not supported by GCC 2.x
### (AMD K8 [Opteron/Athlon64], newest PentiumIV with EM64t)
#CPU=8
### AMD64 "PhenomII" (K10) or newer
#CPU=10
### Let GCC auto-determine CPU type, but assume at least CPU=8 capabilities
CPU=99
endif
ifndef BITS
#BITS=32
BITS=64
endif
ifeq ($(NOTHREADS),1)
PTHREAD=-DFrSINGLE_THREADED
else
PTHREAD=-pthread
#-fopenmp
endif
ifeq ($(STATIC),1)
LINKTYPE=-static -z muldefs
else
LINKTYPE=
endif
ifdef MAKE_SHAREDLIB
SHAREDLIB=-fPIC -DSHARED
endif
ifeq ($(NOICONV),1)
ICONV=-DNO_ICONV
else
ICONV=
endif
ifndef RELEASE
RELPATH=LangIdent
ZIPNAME=langident.zip
else
RELPATH=LangIdent-$(RELEASE)
ZIPNAME=langident-$(RELEASE).zip
endif
WARN=-Wall -Wextra -Wno-deprecated -Wshadow -Wcast-align -Wmissing-noreturn -Wmissing-format-attribute
WARN += -Wunused-result -Wno-multichar -Wpacked -Wdisabled-optimization
#WARN += -Wpadded
LINKBITS=-m$(BITS)
CPUDEF=-march=native -D__BITS__=$(BITS)
CC = g++ -std=c++11
CCLINK = $(CC)
CFLAGS = $(WARN)
CFLAGS +=$(CPUDEF)
CFLAGS +=$(PTHREAD)
CFLAGS +=$(PROFILE)
CFLAGS +=$(ICONV)
CFLAGS +=$(NODEBUG)
CFLAGS +=$(LINKBITS) -pipe
CFLAGS +=$(EXTRAINC)
CFLAGS +=$(SANITIZE)
CFLAGS +=$(INCLUDEDIRS)
CFLAGS +=$(SHAREDLIB)
CFLAGS +=$(COMPILE_OPTS)
CFLAGS +=-I$(FRAMEPAC) -I..
CFLAGEXE = -L$(LIBINSTDIR) $(PROFILE) -o $@
LINKFLAGS =$(LINKBITS)
LINKFLAGS +=$(LINKTYPE)
LINKFLAGS +=$(PTHREAD)
LINKFLAGS +=$(SANITIZE)
LINKFLAGS +=$(LINKSAN)
LINKFLAGS +=-L$(FRAMEPAC)
ifeq ($(BUILD_DBG),2)
CFLAGS += -ggdb3 -O0 -fno-inline -g3 '-DDBDIR="$(DBDIR)"'
CFLAGSLOOP=
LINKFLAGS += -ggdb3
else ifeq ($(BUILD_DBG),1)
CFLAGS +=-Og -fno-inline -ggdb3 '-DDBDIR="$(DBDIR)"'
CFLAGSLOOP=
LINKFLAGS += -ggdb3
else ifeq ($(BUILD_DBG),-1)
CFLAGS +=-O3 -fexpensive-optimizations -ggdb3 '-DDBDIR="$(DBDIR)"'
CFLAGSLOOP=-fno-align-labels -fno-align-loops
LINKFLAGS += -ggdb3
else
CFLAGS +=-O3 -fexpensive-optimizations -fmerge-constants '-DDBDIR="$(DBDIR)"'
CFLAGSLOOP=-fno-align-labels -fno-align-loops
# CFLAGS += -fweb -ftracer -fgcse-sm -fgcse-las -fno-math-errno
endif
CFLAGSLOOP += $(CFLAGS)
CFLAGEXE=-o $@ -m$(BITS) $(PROFILE)
RM=rm -f
CP=cp -p
NULL=/dev/null
#########################################################################
## define the programs needed to create the target library
LIBRARIAN=ar
LIBFLAGS=rucl
LIBINDEXER = ranlib
LIBIDXFLAGS = $(LIBRARY)
#########################################################################
## standard targets
all: framepac $(EXES)
clean:
-$(RM) $(LIBRARY) build/*.o $(EXES)
allclean: clean
-rmdir bin build >$(NULL) ; true
tags:
etags --c++ *.h *.C
install:
$(CP) bin/mklangid bin/romanize bin/whatlang bin/subsample $(DESTDIR)
zip: $(EXES)
# -strip $(EXES)
-$(RM) $(ZIPNAME)
mkdir $(RELPATH)
-$(CP) -i --parents $(DISTFILES) $(RELPATH)
-( cd $(RELPATH) ; md5sum ${DISTFILES} >MD5SUM )
-( cd $(RELPATH) ; sha1sum ${DISTFILES} >SHA1SUM )
zip -mro9 $(ZIPNAME) $(RELPATH)/
lib: $(LIBRARY)
#########################################################################
## executables
bin/mklangid: build/mklangid.o $(LIBRARY) $(FRAMEPAC)/framepacng.a
@mkdir -p bin
$(CCLINK) $(LINKFLAGS) $(CFLAGEXE) -o $@ $^
bin/romanize: build/romanize.o $(LIBRARY) $(FRAMEPAC)/framepacng.a
@mkdir -p bin
$(CCLINK) $(LINKFLAGS) $(CFLAGEXE) -o $@ $^
bin/whatlang: build/whatlang.o $(LIBRARY) $(FRAMEPAC)/framepacng.a
@mkdir -p bin
$(CCLINK) $(LINKFLAGS) $(CFLAGEXE) -o $@ $^
bin/subsample: build/subsample.o $(FRAMEPAC)/framepacng.a
@mkdir -p bin
$(CCLINK) $(LINKFLAGS) $(CFLAGEXE) -o $@ $^
#########################################################################
## object modules
build/langid.o: langid.C langid.h
$(CC) $(CFLAGSLOOP) -c -o $@ $<
build/mklangid.o: mklangid.C langid.h prepfile.h trie.h mtrie.h ptrie.h
build/whatlang.o: whatlang.C langid.h
build/scan_langid.o: scan_langid.C langid.h
build/mtrie.o: mtrie.C mtrie.h
build/prepfile.o: prepfile.C prepfile.h
build/ptrie.o: ptrie.C ptrie.h mtrie.h
build/romanize.o: romanize.C framepac/framepac/romanize.h
build/smooth.o: smooth.C langid.h
build/subsample.o: subsample.C
build/trie.o: trie.C trie.h
build/trigram.o: trigram.C langid.h trie.h
#########################################################################
## header files -- touching to ensure proper recompilation
langid.h: mtrie.h ptrie.h
touch langid.h
#########################################################################
## submodule initialization
framepac:
@[ -e ../framepac-ng/framepac ] && echo "Linking to local install of FramepaC-ng" && ln -s ../framepac-ng framepac ; true
@[ -e ../framepac/framepac ] && echo "Linking to local install of FramepaC-ng" && ln -s ../framepac framepac ; true
@[ ! -e framepac ] && [ -e .git ] && echo "Fetching FramepaC-ng" && git submodule add -f ../framepac-ng.git framepac && git submodule update --init
@[ -e framepac ] || (echo "Please install FramepaC-ng in subdir 'framepac'" ;exit 1)
#########################################################################
## library
$(LIBRARY): $(OBJS)
-$(RM) $(LIBRARY)
$(LIBRARIAN) $(LIBFLAGS) $(LIBRARY) $(OBJS)
$(LIBINDEXER) $(LIBIDXFLAGS)
$(FRAMEPAC)/framepacng.a:
( cd $(FRAMEPAC) ; make lib )
#########################################################################
## default compilation rule
.C.o: ; $(CC) $(CFLAGS) $(CPUTYPE) -c $<
build/%.o : %.C
@mkdir -p build
$(CC) $(CFLAGS) $(CPUTYPE) -c -o $@ $<