forked from PuzzleTechHub/nutrimatic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·81 lines (63 loc) · 2.73 KB
/
build.py
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
#!/usr/bin/env python3
#
# Build Nutrimatic binaries.
#
# Uses "memoize", not make: http://www.eecs.berkeley.edu/~billm/memoize.html
# We do invoke configure and make to build the bundled openfst library.
#
# Re-run this script to do an incremental rebuild; edit the compile() directives
# at the end if you add new programs or source files.
import os
import pipes
import sys
from glob import glob
from memoize import memoize
CFLAGS = "-std=c++11 -g -O6 -Wall -Werror -Wno-unused-local-typedefs -Wno-uninitialized"
LIBS = ""
def run(cmd):
""" Run a shell command with memoization, exit if it fails """
status = memoize(('sh', '-c', cmd))
if status: sys.exit(1)
def getoutput(cmd):
""" Capture and return the output from a command """
tmp = "tmp/%s" % cmd.replace("/", "_")
run("%s >%s" % (cmd, pipes.quote(tmp)))
return open(tmp).read().strip()
def compile(main, others=[], cflags=CFLAGS, libs=LIBS):
""" Build a C++ binary from source """
objs = []
for source in [main] + others:
objs.append(pipes.quote("tmp/%s.o" % source))
run("g++ -o %s %s -c %s" % (objs[-1], cflags, pipes.quote(source)))
bin = "bin/%s" % main.replace(".cpp", "")
run("g++ -o %s %s %s" % (pipes.quote(bin), " ".join(objs), libs))
#####
# Build the bundled openfst library in tmp/openfst, install it in bin/openfst
# So openfst binaries are bin/openfst/bin, libraries are bin/openfst/lib, etc.
# Note that memoize will remember *all* the inputs and outputs of the build,
# and re-invoke configure/make only if any of them change.
run("mkdir -p bin/openfst tmp/openfst")
run("cd tmp/openfst && ../../openfst-1.7.0/configure --enable-static --enable-shared=no --prefix=%s/bin/openfst" % os.getcwd())
run("make -C tmp/openfst install")
run("cp tmp/openfst/config.h bin/openfst/include/config.h")
fst_cflags = "-Ibin/openfst/include -Wno-sign-compare"
fst_libs = "bin/openfst/lib/libfst.a -lpthread -ldl"
#####
# Build the Nutrimatic binaries.
compile("remove-markup.cpp", [],
cflags=CFLAGS + " " + getoutput("xml2-config --cflags"),
libs=LIBS + " " + getoutput("xml2-config --libs") + " -ltre")
compile("make-index.cpp", glob("index-*.cpp"))
compile("merge-indexes.cpp", glob("index-*.cpp"))
compile("dump-index.cpp", glob("index-*.cpp"))
compile("explore-index.cpp", glob("index-*.cpp"))
compile("find-anagrams.cpp", glob("search-*.cpp") + glob("index-*.cpp"))
compile("find-phone-words.cpp", glob("search-*.cpp") + glob("index-*.cpp"))
compile("find-expr.cpp",
glob("expr-*.cpp") + glob("search-*.cpp") + glob("index-*.cpp"),
cflags=CFLAGS + " " + fst_cflags,
libs=LIBS + " " + fst_libs)
compile("test-expr.cpp",
glob("expr-*.cpp") + glob("search-*.cpp") + glob("index-*.cpp"),
cflags=CFLAGS + " " + fst_cflags,
libs=LIBS + " " + fst_libs)