-
Notifications
You must be signed in to change notification settings - Fork 118
/
SConscript.py
116 lines (102 loc) · 4.06 KB
/
SConscript.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
109
110
111
112
113
114
115
116
###### Hall C Software Main SConscript File #####
###### Author: Edward Brash ([email protected]) June 2013
import os
import re
import sys
import subprocess
import platform
import time
import SCons.Util
Import('pbaseenv')
####### write src/hc_compiledata.h header file ######
hcheadersbase = Glob('src/*.h', exclude=['src/THcGlobals.h', 'src/HallC_LinkDef.h'])
cmd = "cat src/HallC_LinkDef.h_preamble > src/HallC_LinkDef.h"
os.system(cmd)
for hcheaderfile in hcheadersbase:
filename = '%s' % hcheaderfile
basefilename = filename.rsplit('.', 1)
newbasefilename = basefilename[0].rsplit('/', 1)
# Assume filenames beginning with Scaler are decoder classes
if newbasefilename[1] == 'hc_compiledata':
continue
if newbasefilename[1][:6] == 'Scaler' or newbasefilename[1] == "TIBlobModule":
cmd1 = "echo '#pragma link C++ class Decoder::%s+;' >> src/HallC_LinkDef.h" % newbasefilename[1]
else:
cmd1 = "echo '#pragma link C++ class %s+;' >> src/HallC_LinkDef.h" % newbasefilename[1]
os.system(cmd1)
cmd = "cat src/HallC_LinkDef.h_postamble >> src/HallC_LinkDef.h"
os.system(cmd)
if sys.version_info >= (2, 7):
try:
cmd = "git rev-parse HEAD 2>/dev/null"
gitrev = subprocess.check_output(cmd, shell=True).rstrip()
except:
gitrev = ''
try:
cmd = pbaseenv.subst('$CXX') + " --version 2>/dev/null | head -1"
cxxver = subprocess.check_output(cmd, shell=True).rstrip()
except:
cxxver = ''
# subprocess gives us byte string literals in Python 3, but we'd like
# Unicode strings
if sys.version_info >= (3, 0):
gitrev = gitrev.decode()
cxxver = cxxver.decode()
else:
FNULL = open(os.devnull, 'w')
try:
gitrev = subprocess.Popen(['git', 'rev-parse', 'HEAD', '2>dev/null'],
stdout=subprocess.PIPE, stderr=FNULL).communicate()[0].rstrip()
except:
gitrev = ''
try:
outp = subprocess.Popen([pbaseenv.subst('$CXX'), '--version'],
stdout=subprocess.PIPE, stderr=FNULL).communicate()[0]
lines = outp.splitlines()
cxxver = lines[0]
except:
cxxver = ''
compiledata = 'src/hc_compiledata.h'
f = open(compiledata, 'w')
f.write('#ifndef HCANA_COMPILEDATA_H\n')
f.write('#define HCANA_COMPILEDATA_H\n')
f.write('\n')
f.write('#define HC_INCLUDEPATH "%s"\n' % (pbaseenv.subst('$HC_SRC')))
f.write('#define HC_VERSION "%s"\n' % pbaseenv.subst('$HC_VERSION'))
f.write('#define HC_DATE "%s"\n' % time.strftime("%b %d %Y"))
f.write('#define HC_DATETIME "%s"\n' % time.strftime("%a %b %d %Y"))
# f.write('#define HC_DATETIME "%s"\n' % time.strftime("%a %b %d %H:%M:%S %Z %Y"))
f.write('#define HC_PLATFORM "%s"\n' % platform.platform())
f.write('#define HC_BUILDNODE "%s"\n' % platform.node())
f.write('#define HC_BUILDDIR "%s"\n' % os.getcwd())
try:
builduser = pbaseenv['ENV']['LOGNAME']
except:
builduser = ''
f.write('#define HC_BUILDUSER "%s"\n' % builduser)
f.write('#define HC_GITVERS "%s"\n' % gitrev[:7])
f.write('#define HC_CXXVERS "%s"\n' % cxxver)
f.write('#define HC_ROOTVERS "%s"\n' % pbaseenv.subst('$ROOTVERS'))
f.write('#define HCANA_VERSION_CODE %s\n' % pbaseenv.subst('$VERCODE'))
f.write('#define HCANA_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))\n')
f.write('\n')
f.write('#endif\n')
f.close()
####### Start of main SConscript ###########
# SCons seems to ignore $RPATH on macOS... sigh
if pbaseenv['PLATFORM'] == 'darwin':
try:
for rp in pbaseenv['RPATH']:
pbaseenv.Append(LINKFLAGS=['-Wl,-rpath,' + rp])
except KeyError:
pass
sources = os.path.join('src','main.cxx')
hcana_prog = pbaseenv.Program(target='hcana', source=sources)
# Installation
install_prefix = pbaseenv.subst('$INSTALLDIR')
bin_dir = os.path.join(install_prefix, 'bin')
rel_lib_dir = os.path.join(pbaseenv['RPATH_ORIGIN_TAG'],
os.path.join('..', pbaseenv.subst('$LIBSUBDIR')))
src_dir = os.path.join(install_prefix, 'src', 'hcana')
pbaseenv.InstallWithRPATH(bin_dir, hcana_prog, [rel_lib_dir])
pbaseenv.Install(src_dir, sources)