]>
jfr.im git - irc/quakenet/newserv.git/blob - configure
22 # immediate (no newline) print
29 def __init__(self
, file):
32 for x
in file.readlines():
33 x
= x
.replace("\r\n", "").replace("\n", "")
35 if xs
== "" or xs
.startswith("#"):
38 if x
.startswith("[") and x
.endswith("]"):
41 self
.__d
[x
[1:-1]] = (sectiondata
, keydata
)
46 sectiondata
[key
] = x
[i
+1:]
47 keydata
.append((key
, sectiondata
[key
]))
49 def has_key(self
, key
):
50 return self
.__d
.has_key(key
)
52 def setdefault(self
, key
, value
=None):
57 def __getitem__(self
, key
):
58 return self
.__d
[key
][0]
61 return self
.__d
[key
][1]
63 class ConfigureIniParser(IniParser
):
64 def __init__(self
, file):
65 IniParser
.__init
__(self
, file)
69 self
.updatemodules(self
.keys("modules"))
72 for k
, v
in self
.setdefault("selectlibs", {}).items():
73 self
.selectlibs
[k
] = v
.split()
75 libs
= self
.setdefault("core", {"libs": ""}
)["libs"].split()
76 libs
= [(x
, self
["lib%s" % x
]) for x
in libs
]
78 v
.setdefault("libname", k
)
79 v
.setdefault("format", "lib%s.so")
80 v
.setdefault("headerpath", None)
81 v
.setdefault("additionaldirs", None)
82 v
.setdefault("alwayspresent", None)
84 if v
["additionaldirs"]:
85 v
["additionaldirs"] = v
["additionaldirs"].split()
86 v
["libname"] = v
["libname"].split()
88 self
.libs
= dict(libs
)
89 self
.searchincludes
= self
["search"]["include"].split()
90 self
.searchlibs
= self
["search"]["lib"].split()
92 for k
, v
in self
.setdefault("makes", {}).items():
96 if self
.has_key("osvars"):
97 for k
, v
in self
.keys("osvars"):
98 self
.osflags
.setdefault(k
, []).append(v
)
100 self
.subs
= [("-%s-" % k
, v
) for k
, v
in self
.setdefault("subs", {}).items()]
101 self
.options
= self
["options"]
103 def configprint(self
):
104 vprint("--- config --------------------------------------------")
106 if x
.startswith("_"):
109 if not isinstance(v
, list) and not isinstance(v
, dict):
111 vprint("%-50s: %s" % (`x`
, `v`
))
112 vprint("--- config --------------------------------------------")
114 def updatemodules(self
, x
, workspace
= None):
116 if workspace
and workspace
!= ".":
117 name
= workspace
+ "/" + k
120 self
.buildorder
.append(name
)
121 self
.modules
[name
] = v
.split()
123 class MultiConfigureIniParser(ConfigureIniParser
):
124 def __init__(self
, files
):
125 ConfigureIniParser
.__init
__(self
, files
[0][1])
127 for workspace
, file in files
[1:]:
129 if c2
.has_key("modules"):
130 self
.updatemodules(c2
.keys("modules"), workspace
)
132 if c2
.has_key("search"):
133 if c2
["search"].has_key("include"):
134 self
.searchincludes
= self
.searchincludes
+ c2
["search"]["include"].split()
135 if c2
["search"].has_key("lib"):
136 self
.searchlibs
= self
.searchlibs
+ c2
["search"]["lib"].split()
138 if c2
.has_key("options"):
139 self
.options
.update(c2
["options"])
141 def librarycheck(libraries
, includes
, libs
):
142 def findlibrarypaths(library
, x
, includes
, libs
):
143 if x
["alwayspresent"]:
145 def locate(needle
, haystack
):
147 vprint("searching for %s in: %s" % (needle
, haystack
))
150 p
= os
.path
.join(x
, needle
)
151 if os
.path
.exists(p
):
156 def mergepaths(a
, b
):
160 ret
.append(os
.path
.join(x
, y
))
163 libname
= x
["libname"]
165 searchdir
= mergepaths(includes
, libname
)
166 incpath
= locate(x
["include"], searchdir
)
171 incpath
= os
.path
.abspath(os
.path
.join(incpath
, x
["headerpath"]))
173 searchdir
= mergepaths(libs
, libname
)
174 if x
["additionaldirs"]:
175 searchdir
= mergepaths(searchdir
, [""] + x
["additionaldirs"])
177 for l
in x
.has_key("soname") and [x
["soname"]] or libname
:
178 libpath
= locate(x
["format"] % l
, searchdir
)
180 return libpath
, l
, incpath
185 for k
in libraries
.keys():
186 iprint("checking for %s... " % k
)
187 ret
= findlibrarypaths(k
, libraries
[k
], includes
, libs
)
195 libpath
, libname
, incpath
= ret
199 libline
= "LIB%s=-L%s -l%s" % (uk
, libpath
, libname
)
200 incline
= "INC%s=-I%s" % (uk
, incpath
)
201 output
.append(libline
)
202 output
.append(incline
)
206 vprint("library path: %s" % libline
)
207 vprint("include path: %s" % incline
)
209 return output
, libsfound
211 def systemcheck(makes
, osflags
):
214 iprint("checking for system... ")
215 system
= platform
.system()
218 iprint("checking for make version... ")
219 make
= makes
.setdefault(system
, "gmake")
222 for v
in osflags
.setdefault(system
, []):
226 def modulecheck(modules
, libsfound
, buildorder
, selectlibs
, overrides
):
227 defaultselections
= {}
229 for k
, v
in selectlibs
.items():
230 if overrides
.has_key(k
):
231 assert overrides
[k
] in libsfound
233 defaultselections
[k
] = overrides
[k
]
238 defaultselections
[k
] = x
242 for k
, v
in modules
.items():
244 if x
not in libsfound
:
249 notfound
= set(filter(lambda x
: not os
.path
.exists(x
), building
))
251 cantbuild
= set(modules
) - building
252 building
= building
- notfound
257 orderedbuild
.append(x
)
259 build
= ["DIRS=%s" % (" ".join(orderedbuild
))]
260 return build
, orderedbuild
, notfound
, cantbuild
, defaultselections
262 def writemakefile(inc
, out
, appendstart
=None, appendend
=None, silent
=False):
264 p
.write("## AUTOMATICALLY GENERATED -- EDIT %s INSTEAD\n\n" % inc
)
266 p
.write("\n".join(appendstart
))
271 for l
in f
.readlines():
277 p
.write("\n".join(appendend
))
282 lprint("configure: wrote %s" % out
)
284 def writeconfigh(file, modules
, defaultselections
):
286 f
.write("/* AUTOMATICALLY GENERATED -- DO NOT EDIT */\n")
289 f
.write("#define HAVE_%s\n" % x
.upper())
290 for k
, v
in defaultselections
.items():
291 f
.write("#define USE_%s_%s\n" % (k
.upper(), v
.upper()))
294 lprint("configure: wrote %s" % file)
296 def configure(config
, selectoverrides
, workspaces
):
297 # figure out make and any custom OS flags
298 flags
, make
= systemcheck(config
.makes
, config
.osflags
)
300 # find the libraries/includes we have and their paths
301 f
, libsfound
= librarycheck(config
.libs
, config
.searchincludes
, config
.searchlibs
)
302 for k
, v
in selectoverrides
.items():
303 if not v
in libsfound
:
304 lprint("configure: can't set %s to %s as %s was not found." % (k
, v
, v
))
309 # see which modules we can build
310 buildlines
, building
, notfound
, cantbuild
, defaultselections
= modulecheck(config
.modules
, libsfound
, config
.buildorder
, config
.selectlibs
, selectoverrides
)
312 for k
, v
in defaultselections
.items():
313 lprint("configure: selected %s as %s" % (v
, k
))
314 flags
.append("LIB%s=$(LIB%s)" % (k
.upper(), v
.upper()))
315 flags
.append("INC%s=$(INC%s)" % (k
.upper(), v
.upper()))
317 writemakefile("build.mk.in", "build.mk", appendend
=flags
+ ["=".join(x
) for x
in config
.options
.items()] + ["DIRS=" + " ".join(building
), "WORKSPACES=" + " ".join(workspaces
)])
319 writeconfigh("config.h", libsfound
, defaultselections
)
321 lprint("configure: selected: %s" % " ".join(building
))
322 if len(notfound
) > 0:
323 lprint("configure: couldn't find: %s" % " ".join(notfound
))
325 if len(cantbuild
) > 0:
326 lprint("configure: can't select: %s" % " ".join(cantbuild
))
330 print " Usage: %s [-h] [-v] [options]" % sys
.argv
[0]
332 print " Additional options are:"
333 for k
, v
in validopts
.items():
334 print " --with-%s=[%s]" % (v
[0], "|".join(v
[1]))
336 print " -L [additional lib dir]"
337 print " -I [additional include dir]"
338 print " -m [additional module]"
341 def main(workspacesfile
):
344 workspacesconfig
= IniParser(open(workspacesfile
, "r"))
349 for workspace
in ["."] + workspacesconfig
["workspaces"].keys():
350 path
= workspace
+ "/configure.ini"
351 if os
.path
.exists(path
):
352 print "found workspace: %s" % workspace
353 workspaces
.append(workspace
)
354 files
.append( (workspace
, open(path
, "r")) )
356 local_path
= workspace
+ "/configure.ini.local"
357 if os
.path
.exists(local_path
):
358 files
.append( (workspace
, open(local_path
, "r")) )
360 config
= MultiConfigureIniParser(files
)
364 for k
, v
in config
.selectlibs
.items():
365 mopts
.append("with-%s=" % k
)
366 validopts
["--with-%s" % k
] = (k
, v
)
369 opts
, args
= getopt
.getopt(sys
.argv
[1:], "hvcI:L:m:", mopts
)
370 except getopt
.GetoptError
, err
:
381 if validopts
.has_key(o
):
399 assert False, "bad option"
401 LOG
= open(".configure.log", "w")
402 vprint("invoked as: %r" % sys
.argv
)
403 config
.updatemodules([(x
, "") for x
in modules
])
404 config
.searchlibs
.extend(libs
)
405 config
.searchincludes
.extend(includes
)
408 configure(config
, overrides
, workspaces
)
410 if __name__
== "__main__":
411 main("workspaces.ini")