-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathconfigure
More file actions
executable file
·182 lines (148 loc) · 5.06 KB
/
configure
File metadata and controls
executable file
·182 lines (148 loc) · 5.06 KB
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python
# ./configure --platform=linux
# > PLATFORM_LFLAGS=-lGL
# ./configure --platform=osx
# > PLATFORM_LFLAGS=-framework OpenGL
# ./configure --debug
# > DEBUG=-g -O0 -fno-inline
# > EXECUTABLE=platformerd
# > DEBUG_DEFINES=-DFOB_LOGGING -DFOB_ASSERTS_ENABLED
import subprocess
import getopt
import sys
import re
#-----------------------------------------------------------------------------
# Return the platform-specific header include paths.
#
def GetHeaderPaths(platform):
paths = "-I./inc "
if "linux" == platform:
paths += " -I/usr/local/include"
paths += " -I/usr/local/include/SDL"
paths += " -I/usr/include/SDL"
elif "osx" == platform:
paths += " -I/Library/Frameworks/SDL.framework/Headers"
paths += " -I/Library/Frameworks/SDL_image.framework/Headers"
elif "windows" == platform:
pass
return paths
#-----------------------------------------------------------------------------
# Return the platform-specific linker flags.
#
def GetLinkerFlags(platform):
if "linux" == platform:
return "-lGL"
elif "osx" == platform:
return "-framework OpenGL " + \
"-framework SDL " + \
"-framework SDL_image " + \
"-framework Cocoa"
elif "windows" == platform:
return ""
#-----------------------------------------------------------------------------
# Define a constant which specifies the platform we're working on.
#
def GetPlatformFlags(platform):
if "linux" == platform:
return "-DPLATFORM_LINUX"
elif "osx" == platform:
return "-DPLATFORM_OSX"
elif "windows" == platform:
return "-DPLATFORM_WINDOWS"
#-----------------------------------------------------------------------------
# Return a string that hopefully represents what the platform is.
#
def GetPlatform():
os = subprocess.Popen(
["uname", "-s"],
stdout = subprocess.PIPE
).communicate()[0].lower().strip()
if os == "darwin":
return "osx"
elif os == "linux":
return "linux"
else:
return "windows"
#-----------------------------------------------------------------------------
# Print out some useful text explaining how to use this script.
#
def Usage():
print "usage: " + __file__ + " [options]"
print "options:"
print "\t[-d|--debug] configure for a debug build"
#-----------------------------------------------------------------------------
# Main
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#
if __name__ == "__main__":
debug = False
makefile = "makefile"
#-------------------------------------------------------------------------
# Process all of our command-line options.
#
try:
opts, args = getopt.getopt(
sys.argv[1:],
"hpd",
["help", "platform", "debug"]
)
except getopt.GetoptError, err:
print str(err)
Usage()
sys.exit(2)
for option, argument in opts:
if option in ("-h", "--help"):
Usage()
sys.exit()
elif option in ("-d", "--debug"):
debug = True;
else:
assert False, "unhandled option"
#
# Finish processing command-line options.
#-------------------------------------------------------------------------
# First, copy makefile.template to makefile.
subprocess.Popen(["cp", "makefile.template", makefile]);
# Find the platform we're on.
platform = GetPlatform()
# Set the include directories.
lines = open(makefile).readlines()
out = open(makefile, "w")
for line in lines:
if re.match("CINCLUDES=", line):
line = "CINCLUDES=" + GetHeaderPaths(platform) + "\n";
out.write(line)
out.close()
# Set the linker flags.
lines = open(makefile).readlines()
out = open(makefile, "w")
for line in lines:
if re.match("PLATFORM_LFLAGS=", line):
line = "PLATFORM_LFLAGS=" + GetLinkerFlags(platform) + "\n"
out.write(line)
out.close()
# Set the platform defines.
lines = open(makefile).readlines()
out = open(makefile, "w")
for line in lines:
if re.match("PLATFORM_DEFINES=", line):
line = "PLATFORM_DEFINES=" + GetPlatformFlags(platform) + "\n"
out.write(line)
out.close()
if debug:
# Setup our DEBUG values.
lines = open(makefile).readlines()
out = open(makefile, "w")
for line in lines:
# > DEBUG=-g -O0 -fno-inline
if re.match("DEBUG=", line):
line = "DEBUG=-g -O0 -fno-inline\n"
# > DEBUG_DEFINES=-DFOB_LOGGING -DFOB_ASSERTS_ENABLED
elif re.match("DEBUG_DEFINES=", line):
line = "DEBUG_DEFINES=-DFOB_LOGGING -DFOB_ASSERTS_ENABLED\n"
# > EXECUTABLE=platformerd
elif re.match("EXECUTABLE=", line):
line = "EXECUTABLE=platformerd"
out.write(line)
out.close()