-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·156 lines (147 loc) · 5.78 KB
/
configure
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
#!/usr/bin/env python2
import os, sys
directory = os.path.dirname(os.path.abspath(__file__))
makefile_lines = []
makefile_cflags = ""
makefile_pkgs = ""
makefile_cflags_index = -1
makefile_pkgs_index = -1
try:
makefile = open("%s/make.conf" % directory)
for n, line in enumerate(makefile):
line = line.rstrip("\r\n")
makefile_lines.append(line)
if line.startswith("CXXFLAGS") or line.startswith("override CXXFLAGS "):
makefile_cflags = line.rstrip() + " "
makefile_cflags_index = n
elif line.startswith("PKGS "):
makefile_pkgs = line.rstrip() + " "
makefile_pkgs_index = n
makefile.close()
except Exception as e:
# this is the thing printed when it can't read the makefile
sys.stderr.write("Failed to open make.conf;\n%s\n" % e)
sys.exit(1)
args = {}
def add_arg(text, **kwargs):
args.setdefault(text, {"PKGS": {}, "CXXFLAGS": {}})
if "PKGS" in kwargs:
for pkg in kwargs["PKGS"]:
if pkg.startswith("+"):
args[text]["PKGS"][pkg[1:]] = True
elif pkg.startswith("-"):
args[text]["PKGS"][pkg[1:]] = False
if "CXXFLAGS" in kwargs:
for cflag in kwargs["CXXFLAGS"]:
if cflag.startswith("+"):
args[text]["CXXFLAGS"][cflag[1:]] = True
elif cflag.startswith("-"):
args[text]["CXXFLAGS"][cflag[1:]] = False
if "about" in kwargs:
args[text]["about"] = kwargs["about"]
# the first argument (eg "disable-zlib") is the command line arg that
# will be prepended with --
# the CXXFLAGS keyword argument expects a list of things to add or remove to CXXFLAGS
# the PKGS keyword argument expects a list of things to add or remove
# from PKGS, if the package name is prepended with -, it is removed
# if it is prepended with +, it is added
add_arg("disable-zlib", CXXFLAGS=["+-D_NO_GZIP"], PKGS=["-zlib"], about="Disable zlib")
add_arg("enable-zlib", CXXFLAGS=["--D_NO_GZIP"], PKGS=["+zlib"], about="Enable zlib")
add_arg("disable-lzma", CXXFLAGS=["+-D_NO_LZMA"], PKGS=["-liblzma"], about="Disable lzma")
add_arg("enable-lzma", CXXFLAGS=["--D_NO_LZMA"], PKGS=["+liblzma"], about="Enable lzma")
add_arg("disable-postgres", CXXFLAGS=["+-D_NO_POSTGRES"], PKGS=["-libpq"], about="Disable postgres")
add_arg("enable-postgres", CXXFLAGS=["--D_NO_POSTGRES"], PKGS=["+libpq"], about="Enable postgres")
add_arg("disable-libevent-threads", CXXFLAGS=["+-D_NO_LIBEVENT_THREADS"], PKGS=["-libevent_pthreads"], about="Disable libevent threads support")
add_arg("enable-libevent-threads", CXXFLAGS=["--D_NO_LIBEVENT_THREADS"], PKGS=["+libevent_pthreads"], about="Enable libevent threads support")
add_arg("enable-c++11", CXXFLAGS=["+-std=c++11"], about="Enable C++11 specify features")
add_arg("disable-c++11", CXXFLAGS=["--std=c++11"], about="Disable C++11 specify features")
help_set = set(["--help", "-h"])
if len(set(sys.argv) & set(["--help", "-h"])) > 0:
print "Configuration options:"
for option in args:
if "about" in args[option]:
print " --%s: %s" % (option, args[option]["about"])
made_changes = False
def parse_arg(program_arg):
global made_changes
global makefile_cflags
global makefile_pkgs
if program_arg in help_set:
return
if not program_arg.startswith("--"):
sys.stderr.write("wrongly formatted arg '%s'!\n" % program_arg)
sys.exit(1)
program_arg = program_arg[2:]
if program_arg == "disable-all":
for available_option in args:
if available_option.startswith("disable-"):
parse_arg("--%s" % available_option)
return False
if program_arg == "enable-all":
for available_option in args:
if available_option.startswith("enable-"):
parse_arg("--%s" % available_option)
return False
if program_arg in args:
cflags = args[program_arg]["CXXFLAGS"]
for cflag in cflags:
if cflags[cflag]:
if not " %s " % cflag in makefile_cflags:
# this is printed when a clag is added
print "Adding '%s' to CXXFLAGS" % cflag
makefile_cflags += "%s " % cflag
made_changes = True
else:
# this is the thing printed when a CFLAG is already added
print "'%s' is already added to CXXFLAGS" % cflag
else:
if " %s " % cflag in makefile_cflags:
# this is the thing printed when removing a CFLAG
print "Removing '%s' from CXXFLAGS" % cflag
makefile_cflags = makefile_cflags.replace(" %s" % cflag, "")
made_changes = True
else:
# this is the thing printed when a CFLAG is already removed
print "'%s' is already removed from CXXFLAGS" % cflag
makefile_lines[makefile_cflags_index] = makefile_cflags
pkgs = args[program_arg]["PKGS"]
for pkg in pkgs:
if pkgs[pkg]:
if not " %s " % pkg in makefile_pkgs:
# this is the thing printed when adding a package
print "Adding '%s' to PKGS" % pkg
makefile_pkgs += "%s " % pkg
made_changes = True
else:
# this is the thing printed when a package is already added
print "'%s' is already added to PKGS" % pkg
else:
if " %s " % pkg in makefile_pkgs:
# this is the thing printed when removing a package
print "Removing '%s' from PKGS" % pkg
makefile_pkgs = makefile_pkgs.replace(" %s" % pkg, "")
made_changes = True
else:
# this is the thing printed when a package is already removed
print "'%s' is already removed from PKGS" % pkg
makefile_lines[makefile_pkgs_index] = makefile_pkgs
else:
sys.stderr.write("Uknown arg provided: '%s'\n" % program_arg)
for arg in sys.argv[1:]:
if not parse_arg(arg) == None:
break
if not made_changes:
# this is the thing printed when nothing is changed in the makefile
sys.stderr.write("Nothing changed\n")
sys.exit(0)
try:
makefile = open("%s/make.conf" % directory, "w")
for line in makefile_lines:
makefile.write("%s\n" % line)
makefile.close()
# this is the thing printed when everything is done
print "Done!"
except Exception as e:
# this is the thing printed when it can't write the makefile
sys.stderr.write("Failed to open make.conf to write configuration;\n%s\n" % e)
sys.exit(1)