Repository navigation
Expand file tree
/
Copy pathinstallPackageMakefiles.py
More file actions
executable file
·161 lines (127 loc) · 5.31 KB
/
Copy pathinstallPackageMakefiles.py
File metadata and controls
executable file
·161 lines (127 loc) · 5.31 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
#!/usr/bin/env python
#===========================================================================
#
# install the makefiles for a given package
#
#===========================================================================
from __future__ import print_function
import os
import sys
import shutil
from sys import platform
from optparse import OptionParser
from datetime import datetime
def main():
global options
global subdirList
global makefileCreateList
global thisScriptName
thisScriptName = os.path.basename(__file__)
# parse the command line
usage = "usage: %prog [options]"
try:
coreDir = os.environ['LROSE_CORE_DIR']
except:
coreDir = os.getcwd()
defaultCodeDir = os.path.join(coreDir, "codebase")
parser = OptionParser(usage)
parser.add_option('--debug',
dest='debug', default=False,
action="store_true",
help='Set debugging on')
parser.add_option('--codedir',
dest='codedir', default=defaultCodeDir,
help='Code dir from which we search for makefiles')
parser.add_option('--package',
dest='package', default="lrose-core",
help='Name of distribution for which we are building')
parser.add_option('--osx',
dest='osx', default=False,
action="store_true",
help='Configure for MAC OSX')
(options, args) = parser.parse_args()
# set flag to indicate OSX
# If we are on a mac, force this to true
isOsx = False
if (platform == "darwin"):
isOsx = True
if (options.osx):
isOsx = True
if (options.debug):
print("Running %s:" % thisScriptName, file=sys.stderr)
print(" codedir:", options.codedir, file=sys.stderr)
print(" package:", options.package, file=sys.stderr)
print(" osx: ", isOsx, file=sys.stderr)
# go to the code dir
os.chdir(options.codedir)
# install the makefiles
if (isOsx):
doInstallOsx()
else:
doInstall()
sys.exit(0)
########################################################################
# install the makefiles
def doInstall():
# search for given makefile name
packageMakefileName = "makefile" + "." + options.package
if (options.debug):
print("Searching for makefiles: ", packageMakefileName, file=sys.stderr)
# first remove any existing 'makefile' files
for root, dirs, files in os.walk(".", topdown=False):
for dir in dirs:
dirPath = os.path.join(root, dir)
# check if makefile exists, remove it if it does
makefilePath = os.path.join(root, "makefile")
if (os.path.isfile(makefilePath)):
if (options.debug):
print("Removing " + makefilePath, file=sys.stderr)
os.remove(makefilePath)
# find _makefiles dirs in tree
for root, dirs, files in os.walk(".", topdown=False):
for dir in dirs:
if (dir == "_makefiles"):
dirPath = os.path.join(root, dir)
makefilePath = os.path.join(root, "makefile")
# check if package makefile exists
packageMakefilePath = os.path.join(dirPath, packageMakefileName)
if (os.path.isfile(packageMakefilePath)):
# copy the package makefile to the root/makefile
if (options.debug):
print("Copying " + packageMakefilePath + \
" to " + makefilePath, file=sys.stderr)
shutil.copy(packageMakefilePath, makefilePath)
return
########################################################################
# install the makefiles
def doInstallOsx():
# search for given makefile name
packageMakefileName = "makefile" + "." + options.package
if (options.debug):
print("Searching for makefiles: ", packageMakefileName, file=sys.stderr)
# find _makefiles dirs in tree
for root, dirs, files in os.walk(".", topdown=False):
for dir in dirs:
if (dir == "_makefiles"):
dirPath = os.path.join(root, dir)
makefilePathLower = os.path.join(root, "makefile")
makefilePathUpper = os.path.join(root, "Makefile")
# check if package makefile exists
packageMakefilePath = os.path.join(dirPath, packageMakefileName)
if (os.path.isfile(packageMakefilePath)):
# remove makefile in the target dir
# because OSX is not properly case sensitive
if (os.path.isfile(makefilePathLower)):
os.remove(makefilePathLower)
if (os.path.isfile(makefilePathUpper)):
os.remove(makefilePathUpper)
# copy the package makefile to the root/makefile
if (options.debug):
print("Copying " + packageMakefilePath + \
" to " + makefilePathLower, file=sys.stderr)
shutil.copy(packageMakefilePath, makefilePathLower)
return
########################################################################
# Run - entry point
if __name__ == "__main__":
main()