forked from Omnifinity/OpenVR-Tracking-Example
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbuild.py
executable file
·109 lines (79 loc) · 2.59 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
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
#!/usr/bin/env python3
import os, fnmatch
from os.path import expanduser
from platform import system
from shutil import copy2
from subprocess import call
import shlex
import sys
def makeWinPath(path):
path = path.replace("/cygdrive/c","C:\\")
path = path.replace("/","\\")
path = path.replace("\\\\","\\")
path = path.replace("\\","\\\\")
return path
nux = "nux" in system().lower()
win = "win" in system().lower()
found = False
print("\nThis script will output a script to build the VR Track example.\n")
testfile_rel_path = "src/openvr_api_public.cpp"
if (len(sys.argv) > 1):
ipath = sys.argv[1]
ifile = os.path.join(ipath, testfile_rel_path)
found = os.path.isfile(ifile)
if not found:
ipath = input("Enter path to the openvr repository clone or press enter\nto have the script search your home directory.\n> ")
ifile = os.path.join(ipath, testfile_rel_path)
found = os.path.isfile(ifile)
if found:
openvr_path = ifile[:-(len(testfile_rel_path)+1)]
if not found:
print("Attempting to search home directory for openvr sdk....")
for root, dirs, files in os.walk(expanduser("~")):
for name in files:
absn = os.path.join(root, name)
match = '*src/openvr_api_public.cpp'
if fnmatch.fnmatch(absn, match):
ssdist = len(match) - 0
openvr_path = absn[:-ssdist]
found = True
break
if (not found) and win:
print("Attempting to search C:\\Users\\ for openvr sdk....")
winroot = "C:\\Users\\"
for root, dirs, files in os.walk(winroot):
for name in files:
absn = os.path.join(root, name)
match = '*src/openvr_api_public.cpp'
if fnmatch.fnmatch(absn, match):
ssdist = len(match) - 0
openvr_path = absn[:-ssdist]
found = True
break
if not found:
print("Failed to find the openvr sdk. Clone Valve's openvr sdk and try again.")
sys.exit()
if win:
openvr_path = makeWinPath(openvr_path)
print("Found the openvr sdk: '" + openvr_path + "'")
if nux:
openvr_bin = openvr_path + "/bin/linux64"
if win:
openvr_bin = openvr_path + "\\bin\\win64"
openvr_bin = makeWinPath(openvr_bin)
print("Found the openvr binaries: '" + openvr_bin + "'\n")
print("Generating compile command...")
comp = 'g++ -L%s -I%s -Wl,-rpath,%s -Wall -Wextra -std=c++0x -o build/track *.cpp *.c -lopenvr_api' % (openvr_bin,openvr_path,openvr_bin)
print(" - Command: " + comp + "\n")
os.mkdir("build")
if nux:
outfile = "build/compile.sh"
if win:
outfile = "build\\compile.bat"
outfile = makeWinPath(outfile)
out = open(outfile,'w+')
if nux:
out.write("#! /bin/sh \n")
print("Writing output file to: '" + outfile + "'\n")
out.write(comp + "\n")
print("Finished.")