| 1 |
#!/usr/bin/env python |
| 2 |
|
| 3 |
from optparse import OptionParser |
| 4 |
from os.path import abspath, dirname, join |
| 5 |
from subprocess import call |
| 6 |
from sys import argv, stderr, stdout |
| 7 |
|
| 8 |
from install.util import ( |
| 9 |
MAJOR_VERSION, |
| 10 |
MINOR_VERSION, |
| 11 |
PLATFORM_MACX, |
| 12 |
PLATFORM_UNIX, |
| 13 |
PLATFORM_WIN32, |
| 14 |
REVISION, |
| 15 |
findExecutable, |
| 16 |
getPlatform |
| 17 |
) |
| 18 |
|
| 19 |
def main(): |
| 20 |
parser = OptionParser("usage: %prog [options] [qmake-args]") |
| 21 |
parser.add_option("--bin-dir", action="store", default=None, dest="binDir", |
| 22 |
help="Install directory for midisnoop executable") |
| 23 |
parser.add_option("--build-dir", action="store", default=None, |
| 24 |
dest="buildDir", help="Build directory") |
| 25 |
parser.add_option("--data-dir", action="store", default=None, |
| 26 |
dest="dataDir", |
| 27 |
help="Install directory for general data files") |
| 28 |
parser.add_option("--data-root-dir", action="store", default=None, |
| 29 |
dest="dataRootDir", help="Install root for data files") |
| 30 |
parser.add_option("--debug", action="store_true", default=False, |
| 31 |
dest="debug", help="Build a debug executable") |
| 32 |
parser.add_option("--exec-prefix", action="store", default=None, |
| 33 |
dest="execPrefix", |
| 34 |
help="Install prefix for executable data") |
| 35 |
parser.add_option("--make-dir", action="store", default=None, |
| 36 |
dest="makeDir", help="Make directory") |
| 37 |
parser.add_option("--prefix", action="store", default=None, dest="prefix", |
| 38 |
help="Install prefix") |
| 39 |
options, args = parser.parse_args() |
| 40 |
|
| 41 |
pkgConfigPath = findExecutable("pkg-config") |
| 42 |
if pkgConfigPath is None: |
| 43 |
stderr.write("Warning: pkg-config not found\n") |
| 44 |
elif call([pkgConfigPath, "--exists", "rtmidi"]) or \ |
| 45 |
call([pkgConfigPath, "--atleast-version=2.0.1", "rtmidi"]): |
| 46 |
exit("Error: rtmidi version >= 2.0.1 is required for compilation") |
| 47 |
|
| 48 |
qmakePath = findExecutable("qmake") |
| 49 |
if qmakePath is None: |
| 50 |
exit("Error: qmake is required for build configuration") |
| 51 |
|
| 52 |
platform = getPlatform() |
| 53 |
platformArgs = [] |
| 54 |
if platform == PLATFORM_MACX: |
| 55 |
platformArgs += ["-spec", "macx-g++"] |
| 56 |
platformStr = "MACX" |
| 57 |
elif platform == PLATFORM_WIN32: |
| 58 |
platformStr = "WIN32" |
| 59 |
else: |
| 60 |
platformStr = "UNIX" |
| 61 |
|
| 62 |
scriptDir = abspath(dirname(argv[0])) |
| 63 |
|
| 64 |
buildDir = options.buildDir |
| 65 |
if buildDir is None: |
| 66 |
buildDir = "build" |
| 67 |
buildDir = abspath(join(scriptDir, buildDir)) |
| 68 |
|
| 69 |
makeDir = options.makeDir |
| 70 |
if makeDir is None: |
| 71 |
makeDir = "make" |
| 72 |
makeDir = abspath(join(scriptDir, makeDir)) |
| 73 |
|
| 74 |
prefix = options.prefix |
| 75 |
if prefix is None: |
| 76 |
prefix = "/usr/local" |
| 77 |
else: |
| 78 |
prefix = abspath(prefix) |
| 79 |
|
| 80 |
dataRootDir = options.dataRootDir |
| 81 |
if dataRootDir is None: |
| 82 |
dataRootDir = "share" |
| 83 |
dataRootDir = abspath(join(prefix, dataRootDir)) |
| 84 |
|
| 85 |
execPrefix = options.execPrefix |
| 86 |
if execPrefix is None: |
| 87 |
execPrefix = prefix |
| 88 |
else: |
| 89 |
execPrefix = abspath(execPrefix) |
| 90 |
|
| 91 |
binDir = options.binDir |
| 92 |
if binDir is None: |
| 93 |
binDir = "bin" |
| 94 |
binDir = abspath(join(execPrefix, binDir)) |
| 95 |
|
| 96 |
dataDir = options.dataDir |
| 97 |
if dataDir is None: |
| 98 |
dataDir = dataRootDir |
| 99 |
else: |
| 100 |
dataDir = abspath(join(prefix, dataDir)) |
| 101 |
|
| 102 |
# Run `qmake` |
| 103 |
qmakeArgs = [qmakePath, "-recursive"] + platformArgs + args + \ |
| 104 |
["MAJOR_VERSION=%d" % MAJOR_VERSION, "MINOR_VERSION=%d" % MINOR_VERSION, |
| 105 |
"REVISION=%d" % REVISION, "BUILDDIR=%s" % buildDir, |
| 106 |
"MAKEDIR=%s" % makeDir, "PREFIX=%s" % prefix, |
| 107 |
"DATAROOTDIR=%s" % dataRootDir, "EXECPREFIX=%s" % execPrefix, |
| 108 |
"BINDIR=%s" % binDir, "DATADIR=%s" % dataDir] |
| 109 |
if options.debug: |
| 110 |
qmakeArgs.append("DEBUG=1") |
| 111 |
if call(qmakeArgs): |
| 112 |
parser.error("qmake returned an error") |
| 113 |
|
| 114 |
stdout.write("Configure successful. Run `make` to build, and " |
| 115 |
"`make install` to install.\n") |
| 116 |
|
| 117 |
if __name__ == "__main__": |
| 118 |
main() |