Source
57
57
from distutils.ccompiler import new_compiler, CCompiler
58
58
from distutils.sysconfig import customize_compiler
59
59
from distutils.core import Extension, Distribution
60
60
from distutils.ccompiler import get_default_compiler
61
61
from distutils.ccompiler import show_compilers
62
62
from distutils.command.build_ext import build_ext
63
63
from distutils.errors import DistutilsExecError, CompileError
64
64
from distutils.dir_util import copy_tree, remove_tree
65
65
from distutils.core import Command
66
66
from distutils.util import spawn, get_platform
67
-
from distutils.dist import Distribution
68
67
69
68
from functools import reduce
70
69
from itertools import dropwhile,takewhile
71
70
from collections import defaultdict
72
71
from subprocess import call as Proc
73
72
from subprocess import Popen, PIPE
74
73
from datetime import datetime
75
74
from inspect import currentframe, getframeinfo
76
75
from textwrap import dedent
77
76
from shutil import copy2, move, copyfileobj
98
97
99
98
lib_ext = "dylib" if sys.platform == 'darwin' else 'so'
100
99
build_config_file = "build.json"
101
100
102
101
parser=argparse.ArgumentParser()
103
102
104
103
parser.add_argument('--version', help='version')
105
104
parser.add_argument('--debug', help='debug', action='store_true')
106
105
parser.add_argument('--relwithdebinfo', help='Release build with debug and optimization flags', action='store_true')
107
106
parser.add_argument('--stripsyms', help='Strip debug info out of the executable files from --relwithdebinfo. Used with release builds.', action='store_true')
108
-
parser.add_argument('--prebuilt', help="Don't build any external (non-python) sources. Assume previously built via genmake+make.", action='store_true')
109
107
parser.add_argument('bdist_wheel', help='bdist_wheel')
110
108
111
109
args=parser.parse_args()
112
110
_debug_build_ = args.debug
113
111
_rel_with_deb_info_ = args.relwithdebinfo
114
112
_strip_syms_ = args.stripsyms
115
-
_prebuilt_ = args.prebuilt
116
113
print("_debug_build_: " + str(_debug_build_))
117
114
print("_rel_with_deb_info_: " + str(_rel_with_deb_info_))
118
115
print("_strip_syms_: " + str(_strip_syms_))
119
-
print("_prebuilt_: " + str(_prebuilt_))
120
116
121
117
# Remove the "non-standard" arguments from sys.argv so as not to confuse dist_tools
122
118
if "--version" in sys.argv:
123
119
sys.argv.remove("--version")
124
120
if "--debug" in sys.argv:
125
121
sys.argv.remove("--debug")
126
122
if "--relwithdebinfo" in sys.argv:
127
123
sys.argv.remove("--relwithdebinfo")
128
124
if "--stripsyms" in sys.argv:
129
125
sys.argv.remove("--stripsyms")
130
-
if "--prebuilt" in sys.argv:
131
-
sys.argv.remove("--prebuilt")
126
+
132
127
133
128
module_name = 'casatools'
134
129
135
130
pyversion = float(sys.version_info[0]) + float(sys.version_info[1]) / 10.0
136
131
xml_jar_file = 'xml-casa-assembly-1.66.jar'
137
132
xml_jar_path = os.path.join( 'scripts', 'java', xml_jar_file)
138
133
xml_jar_url = 'http://casa.nrao.edu/download/devel/xml-casa/java/%s' % xml_jar_file
139
134
140
135
real_gnu = None
141
136
gxx_version_number = 0
1017
1012
'-fno-omit-frame-pointer', '-DWITHOUT_ACS', '-DWITHOUT_BOOST', \
1018
1013
'-DUSE_THREADS', '-DCASATOOLS', '-Dcasacore=casa6core', '-DYYERROR_IS_DECLARED', \
1019
1014
'-fPIC' ] + mpi_cxx_flags + platform_cflags[sys.platform],
1020
1015
'binding/': ['-DAIPS_64B', '-DAIPS_AUTO_STL', '-DAIPS_DEBUG', '-DAIPS_HAS_QWT', \
1021
1016
'-DAIPS_LINUX', '-DAIPS_LITTLE_ENDIAN', '-DAIPS_STDLIB', \
1022
1017
'-DCASACORE_NEEDS_RETHROW', '-DCASA_USECASAPATH', '-DQWT6', \
1023
1018
'-DUseCasacoreNamespace', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', \
1024
1019
'-DNO_CRASH_REPORTER', '-fno-omit-frame-pointer', '-DWITHOUT_ACS', '-DWITHOUT_BOOST', \
1025
1020
'-DUSE_THREADS', '-DCASATOOLS', '-Dcasacore=casa6core', '-fPIC' ] \
1026
1021
+ platform_cflags[sys.platform],
1027
-
'sakura-source/': platform_cflags[sys.platform],
1028
1022
'src/': ['-DAIPS_64B', '-DAIPS_AUTO_STL', '-DAIPS_DEBUG', '-DAIPS_HAS_QWT', \
1029
1023
'-DAIPS_LINUX', '-DAIPS_LITTLE_ENDIAN', '-DAIPS_STDLIB', \
1030
1024
'-DCASACORE_NEEDS_RETHROW', '-DCASA_USECASAPATH', '-DQWT6', \
1031
1025
'-DUseCasacoreNamespace', '-D_FILE_OFFSET_BITS=64', '-D_LARGEFILE_SOURCE', \
1032
1026
'-DNO_CRASH_REPORTER', '-fno-omit-frame-pointer', '-DWITHOUT_ACS', '-DWITHOUT_BOOST', \
1033
1027
'-DUSE_THREADS', '-DCASATOOLS', '-Dcasacore=casa6core', '-fPIC' ] \
1034
1028
+ platform_cflags[sys.platform] }
1035
1029
1036
1030
def get_ccache():
1037
1031
return [ props['build.compiler.ccache'] ] if 'build.compiler.ccache' in props and len(props['build.compiler.ccache']) > 0 else [ ]
1071
1065
return [
1072
1066
'-Ibuild/%s/include' % distutils_dir_name('grpc-install'),
1073
1067
'-Ibinding/include', '-Ibinding/generated/include', '-Ilibcasatools/generated/include',
1074
1068
'-Isrc/code', '-Isrc', '-Icasacore', '-Iinclude',
1075
1069
'-Isakura-source/src'
1076
1070
]
1077
1071
1078
1072
def get_new_c_compiler_flags():
1079
1073
return get_optimization_flags()
1080
1074
1081
-
def get_cxx_compiler_flags_from_setuputils():
1082
-
# I (BGB) think that -pthread gets added to the wheel build in
1083
-
# distutils/sysconfig.py:customize_compiler() -> get_config_pars('CC'),
1084
-
# but I wasn't able to chase it down fully TODO find original source
1085
-
return ['-pthread']
1086
-
1087
-
def get_cxx_compiler_includes_from_setuputils():
1088
-
# create instance of casa_build_ext (as in setuputils externals) to get the include flags from it
1089
-
wheel_build_ext_cmd = casa_build_ext(Distribution())
1090
-
wheel_build_ext_cmd.ensure_finalized()
1091
-
# I (BGB) don't know where "-Ibinding" is coming from for bdist_util TODO find argument origins
1092
-
# I also don't think that this argument really matters, but I'm adding it here just to ensure
1093
-
# that make and bdist_wheel build with all of the same arguments.
1094
-
incs = wheel_build_ext_cmd.include_dirs + ["binding"]
1095
-
return ['-I'+inc for inc in incs]
1096
-
1097
1075
def get_use_grpc():
1098
1076
return ( [ '-DUSE_GRPC' ] if props['option.grpc'] != "0" else [ ] )
1099
1077
1100
1078
1101
1079
def get_fortran_compiler_flags(ext):
1102
1080
arch = platform.architecture()[0].lower()
1103
1081
if (ext == ".f90"):
1104
1082
cc_args = ["-O3", "-fPIC", "-c", "-ffree-form", "-ffree-line-length-none"]
1105
1083
if relwithdebinfo_build():
1106
1084
cc_args.insert(0, "-g")
1120
1098
cc_args.append("-m32")
1121
1099
elif arch == "64bit":
1122
1100
cc_args.append("-m64")
1123
1101
else:
1124
1102
print(
1125
1103
"\nPlatform has architecture '%s' which is unknown to "
1126
1104
"the setup script. Proceed with caution\n" % arch
1127
1105
)
1128
1106
return cc_args
1129
1107
1130
-
sys_cflags=''
1131
-
def update_sys_cflags():
1132
-
global sys_cflags
1133
-
sys_cflags = sep.join(
1134
-
list(
1135
-
filter(
1136
-
lambda flag: not flag.startswith('-O'),sysconfig.get_config_var('CFLAGS').split()
1137
-
)
1138
-
)
1139
-
)
1140
-
return sys_cflags
1141
-
1142
1108
def customize_compiler(self):
1143
1109
"""inject customization into distutils.
1144
1110
1145
1111
Getting distutils to use a specfic compiler with a fully-quaified
1146
1112
path and specfic flags is difficult. By default, it seems to just
1147
1113
use 'gcc', i.e. whichever compiler happens to be in the user's
1148
1114
path. I want to select a specific compiler using autoconf.
1149
1115
1150
-
I (DS?) found this reference useful:
1116
+
I found this reference useful:
1151
1117
https://github.com/rmcgibbo/npcuda-example/blob/master/cython/setup.py
1152
-
1153
-
I (BGB) believe that "self" here is an instance of distutils.UnixCCompiler.
1154
-
https://github.com/python/cpython/blob/main/Lib/distutils/ccompiler.py
1155
1118
"""
1156
1119
1157
1120
self.compiler_cxx = [ props['build.compiler.cxx'] ]
1158
1121
print('* Note: build.compiler.cxx: {}'.format('build.compiler.cxx'))
1159
1122
1160
1123
# make it swallow fortran files....
1161
1124
self.src_extensions.extend( [".f",".f90"] )
1162
1125
1163
1126
# save references to the default compiler_so and _comple methods
1164
1127
default_compiler_so = self.compiler_so
1190
1153
with open(local_path_file,'rb') as f:
1191
1154
local_library_path = pickle.load(f)
1192
1155
else:
1193
1156
local_library_path = [ ]
1194
1157
1195
1158
if os.path.isfile(local_mangle_file):
1196
1159
with open(local_mangle_file,'rb') as f:
1197
1160
library_mangle = pickle.load(f)
1198
1161
else:
1199
1162
library_mangle = { }
1200
-
1201
-
# Mimic the makefile so that the same build objects can be used:
1202
-
filtered_sys_cflags = filter_optim_debug(update_sys_cflags()).split() # yes, we join only to take advantage of filter_optim_debug
1203
1163
1204
1164
def _link(target_desc, objects, output_filename, output_dir=None,
1205
1165
libraries=None, library_dirs=None, runtime_library_dirs=None,
1206
1166
export_symbols=None, debug=0, extra_preargs=None,
1207
1167
extra_postargs=None, build_temp=None, target_lang=None):
1208
1168
fn = os.path.basename(output_filename)
1209
1169
if fn.startswith('_') and fn.endswith('.so') or \
1210
1170
fn.startswith('lib') and fn.endswith('.so') and \
1211
1171
reduce( lambda acc,v: acc or v.endswith('_wrap.o'), objects, False ):
1212
1172
## the latest python innovation is removing unused symbols, the macos flavor is '-Wl,-dead_strip_dylibs'
1252
1212
pickle.dump(library_mangle,f)
1253
1213
1254
1214
1255
1215
## allowing pthread library path (e.g. /opt/local/lib for macos) to be first results
1256
1216
## in any macports (or other) protobuf library being used in preference to the one
1257
1217
## we built...
1258
1218
self.linker_so = list(takewhile(lambda x: not x.startswith('-L'),self.linker_so)) + \
1259
1219
['-L' + get_casac_dir() + os.sep + 'lib'] + \
1260
1220
list(dropwhile(lambda x: not x.startswith('-L'),self.linker_so))
1261
1221
1262
-
# For some unknown reason, two of the linker arguments are concatenated together without a space.
1263
-
# "-L/opt/rh/rh-python36/root/usr/lib64-Wl,-z,relro"
1264
-
for i in range(len(self.linker_so)):
1265
-
if "-Wl,-z,relro" in self.linker_so[i] and self.linker_so[i].index("-Wl,-z,relro") != 0: # terrible hack
1266
-
self.linker_so[i] = self.linker_so[i].split("-Wl,-z,relro")[0]
1267
-
self.linker_so.insert(i+1, "-Wl,-z,relro")
1268
-
break
1269
-
1270
1222
superld(target_desc, objects, output_filename, output_dir,
1271
1223
[library_mangle[l] if l in library_mangle else l for l in libraries],
1272
1224
library_dirs+local_library_path, runtime_library_dirs, export_symbols,
1273
1225
debug, extra_preargs, extra_postargs, build_temp, target_lang)
1274
1226
1275
1227
self.linker_so = default_linker_so
1276
1228
1277
1229
# now redefine the _compile method. This gets executed for each
1278
1230
# object but distutils doesn't have the ability to change compilers
1279
1231
# based on source extension: we add it.
1280
1232
def _compile(obj, src, ext, cc_args, postargs, pp_opts):
1281
-
if _prebuilt_:
1282
-
# Don't rebuild external (non-python) sources
1283
-
return
1284
-
1285
1233
if ext == ".f" or ext == ".f90" :
1286
1234
print("fortran compile...")
1287
1235
if sys.platform == 'darwin' or sys.platform.startswith('linux'):
1288
1236
compiler_so = new_compiler_fortran
1289
1237
"""
1290
1238
if (ext == ".f90"):
1291
1239
cc_args = ["-O3", "-fPIC", "-c", "-ffree-form", "-ffree-line-length-none"]
1292
1240
if (ext == ".f"):
1293
1241
cc_args = ["-O3", "-fPIC", "-c", "-fno-automatic", "-ffixed-line-length-none"] + %s
1294
1242
if real_gnu and len(props['build.flags.compile.openmp']) > 0:
1304
1252
else:
1305
1253
print("\nPlatform has architecture '%%s' which is unknown to "
1306
1254
"the setup script. Proceed with caution\n" %% arch)
1307
1255
""" % gfortran_flag_additions
1308
1256
cc_args = get_fortran_compiler_flags(ext)
1309
1257
try:
1310
1258
self.spawn(compiler_so + cc_args + [src, '-o', obj] + postargs)
1311
1259
except DistutilsExecError as msg:
1312
1260
raise CompileError(msg)
1313
1261
else:
1314
-
tmp_sys_cflags = []
1315
1262
if ext == ".c" :
1316
1263
print("c compile...")
1317
1264
new_compiler = new_compiler_cc
1318
1265
else:
1319
1266
print("c++ compile...")
1320
1267
new_compiler = new_compiler_cxx
1321
-
tmp_sys_cflags = filtered_sys_cflags
1322
1268
## get the cflags for the module being built; key is a subdir, value are flags
1323
1269
m_cflags = map(lambda x: x[1] if x[0] in src else [], module_cflags.items())
1324
1270
m_cflags = [item for sublist in m_cflags for item in sublist] ### python has not yet hit upon a flatten function...
1325
1271
#self.set_executable('compiler_so', clean_args(new_compiler + m_cflags + ( [ '-DUSE_GRPC' ] if props['option.grpc'] != "0" else [ ] )))
1326
-
self.set_executable('compiler_so', clean_args(new_compiler + m_cflags + tmp_sys_cflags + get_use_grpc()))
1272
+
self.set_executable('compiler_so', clean_args(new_compiler + m_cflags + get_use_grpc()))
1327
1273
supercc(obj, src, ext, clean_args(cc_args), clean_args(postargs), clean_args(pp_opts))
1328
1274
1329
1275
# reset the default compiler_so (may not be necessary)
1330
1276
self.compiler_so = default_compiler_so
1331
1277
1332
1278
# inject our redefined _compile method into the class
1333
1279
self._compile = _compile
1334
1280
self.link = _link
1335
1281
1336
1282
1392
1338
imports = "\n".join([ "from %s.__casac__.%s import %s" % (module_name,t,t) for t in TOOLS ])
1393
1339
alllist = ",\n ".join([ "'%s'" % t for t in TOOLS ])
1394
1340
with open(os.path.join(casacdir,'__init__.py'),"w") as fd:
1395
1341
fd.write("from __future__ import absolute_import\n")
1396
1342
fd.write("__name__ = '__casac__'\n")
1397
1343
fd.write("__all__ = [ %s ]\n\n" % alllist)
1398
1344
fd.write("%s\n" % imports)
1399
1345
1400
1346
# run the customize_compiler
1401
1347
class casa_build_ext(build_ext):
1402
-
# Builds the c files into the pre-compiled binaries to include in the distributed wheel.
1403
-
# The compiler is determined by the call to customize_compiler.
1404
-
# Most of the work is done by the parent build_ext class in the run() method.
1405
1348
user_options = build_ext.user_options + [
1406
1349
# The format is (long option, short option, description).
1407
1350
('debug', None, 'build a debugging version'),
1408
1351
('version=', None, 'Silence distutils when passing version for bdist_wheel from the command line'),
1409
1352
]
1410
1353
1411
1354
def initialize_options(self):
1412
1355
self.version = None
1413
1356
build_ext.initialize_options(self)
1414
1357
global _debug_build_
1415
1358
if _debug_build_:
1416
1359
self.debug = 1
1417
1360
else:
1418
1361
self.debug = 0
1419
1362
1420
-
# build_ext::finalize_options() adds the includes for {devdir}/venv/include and /opt/rh/rh-python36/root/usr/include/python3.6m
1421
-
# These includes are added to self.include_dirs
1422
-
#def finalize_options(self):
1423
-
# build_ext.finalize_options(self)
1424
-
1425
1363
def build_extensions(self):
1426
1364
customize_compiler(self.compiler)
1427
1365
customize_swig(self)
1428
1366
build_ext.build_extensions(self)
1429
1367
1430
1368
def run(self):
1431
1369
1432
1370
global a_priori_directory_exclusions
1433
1371
global a_priori_exclusions
1434
1372
do_wheel_closure = doing_wheel_build
1690
1628
# third party libs for linking
1691
1629
def get_tp_libs():
1692
1630
if casa_have_mpi:
1693
1631
mpi_libs = ['open-pal', 'open-rte', 'mpi', 'mpi_cxx']
1694
1632
else:
1695
1633
mpi_libs = []
1696
1634
1697
1635
return [
1698
1636
'sqlite3','xslt','xml2','xerces-c','fftw3f_threads','fftw3f', 'fftw3_threads',
1699
1637
'fftw3','lapack','wcs','cfitsio','rpfits','blas'
1700
-
] + get_grpc_libs() + ['readline', 'gfortran', 'dl'] + mpi_libs + [f"python{pyversion}m"]
1638
+
] + get_grpc_libs() + ['readline', 'gfortran', 'dl'] + mpi_libs
1701
1639
1702
1640
def get_gfortran_lib_path( ):
1703
1641
proc = Popen([ props['build.compiler.fortran'], "-print-search-dirs"], stdout=PIPE, stderr=PIPE )
1704
1642
out,err = pipe_decode(proc.communicate( ))
1705
1643
exit_code = proc.wait( )
1706
1644
if exit_code != 0:
1707
1645
sys.exit('failed to find libgfortran')
1708
1646
1709
1647
for line in out.split('\n'):
1710
1648
if line.startswith('libraries: ='):
1756
1694
tool_libs_target = "tool_libs_link"
1757
1695
straight_copies_target = "straight_file_copies"
1758
1696
all_target = "all"
1759
1697
build_distutils_temp = os.path.join('build',distutils_dir_name('temp'))
1760
1698
depdir = '.d'
1761
1699
sep = ' '
1762
1700
cpp = sep.join(get_ccache() + [props['build.compiler.cxx']])
1763
1701
cc = sep.join(get_ccache() + [props['build.compiler.cc']])
1764
1702
f77 = props['build.compiler.fortran']
1765
1703
casatools_obj_list = []
1766
-
sys_cflags = update_sys_cflags()
1704
+
sys_cflags = sep.join(
1705
+
list(
1706
+
filter(lambda flag: not flag.startswith('-O'),sysconfig.get_config_var('CFLAGS').split())
1707
+
)
1708
+
)
1767
1709
1768
1710
python_inc = props['build.python.include']
1769
1711
sepl = " -l"
1770
1712
(gldflags, gprop_libs) = get_link_props()
1771
1713
# gldflags = g1
1772
1714
# gprop_libs = g2
1773
1715
link_libs = list(dict.fromkeys((gprop_libs + get_tp_libs() + arch_libs)))
1774
1716
# casatools link
1775
1717
linker = props['build.compiler.cxx']
1776
1718
ldflags1 = sep.join(props['build.flags.compile.pthread'] + arch_flags)
1790
1732
)
1791
1733
mk.write("\nCXX := " + cpp)
1792
1734
mk.write("\nCC := " + cc)
1793
1735
mk.write("\nF77 := " + f77)
1794
1736
mk.write("\nOPTIM_FLAGS := -O2 -Wp,-D_FORTIFY_SOURCE=2")
1795
1737
1796
1738
#mk.write("\nOPTIM_FLAGS := -O2 \n")
1797
1739
mk.write("\nDEPDIR := " + depdir + "\n")
1798
1740
mk.write("# override optimization for debug builds")
1799
1741
mk.write("\ndebug: OPTIM_FLAGS := -g \n")
1800
-
mk.write("\nrelwithdebinfo: OPTIM_FLAGS := -g $(OPTIM_FLAGS) \n")
1801
1742
mk.write("\n.PHONY: " + all_target + "\n")
1802
1743
mk.write(all_target + ": " + sep.join(targets) + "\n")
1803
1744
mk.write('\ndebug: ' + all_target)
1804
-
mk.write('\nrelwithdebinfo: ' + all_target)
1805
1745
mk.write(
1806
1746
sep.join([
1807
1747
"\n", clean_target, ": "
1808
1748
"\n\t @rm -rf " + build_distutils_temp + " $(DEPDIR)",
1809
1749
"\n.PHONY: ", clean_target, "\n"
1810
1750
])
1811
1751
)
1812
1752
1813
1753
def filter_optim_debug(cmd):
1814
-
# take out explicit optimization/debugging flags, these are controlled instead with the make target
1754
+
# take out explicit optimization/debugging flags
1815
1755
cmd = cmd.replace('-g ', '')
1816
1756
cmd = re.sub('-Wp,-D_FORTIFY_SOURCE=\d+', '', cmd)
1817
1757
return re.sub('-O\d+','', cmd)
1818
1758
1819
1759
def write_make_cpp(additional_subdir_filters=[], use_sakura=True, use_atm=True):
1820
1760
# c++ casacore and casacode + others but not gcwrap
1821
1761
CODE_SRC = source_files(
1822
1762
"src/code", file_suffix_filter=".cc",
1823
1763
subdir_filter=[
1824
1764
'tests', 'test', 'apps', 'display', 'plotms', 'guitools', 'display3d',
1847
1787
obj_name = os.path.join(build_distutils_temp, "{base}.o")
1848
1788
g_dep_name = os.path.join("$(DEPDIR)", build_distutils_temp, "{base}.d")
1849
1789
g_dep_targ = g_dep_name + ": ;\nPRECIOUS: " + g_dep_name
1850
1790
# use makefile as a dependency
1851
1791
cpp_obj = (
1852
1792
obj_name + ': {src} ' + g_dep_name + ' makefile'\
1853
1793
+ '\n\t$(CXX) $(OPTIM_FLAGS) {flags} {includes} {cflags} ' \
1854
1794
+ '{dflags} -c $< -o $@' \
1855
1795
+ '\n\t$(POSTCOMPILE)'
1856
1796
)
1857
-
# this should mimic module_cflags
1858
-
src_and_flags = [
1859
-
(CODE_SRC, module_cflags['/code/']),
1860
-
(CORE_SRC, module_cflags['casacore/']),
1861
-
(SAKURA_SRC, module_cflags['sakura-source/']),
1862
-
(CODE_ATM, module_cflags['/code/']),
1863
-
(GRPC_REGISTRAR, platform_cflags[sys.platform]),
1864
-
(SOURCE_BINDING, module_cflags['binding/'])
1797
+
src = [
1798
+
CODE_SRC, CORE_SRC, SAKURA_SRC, CODE_ATM, GRPC_REGISTRAR, SOURCE_BINDING
1865
1799
]
1866
-
1867
-
includes = sep.join(get_new_cxx_compiler_includes() + get_cxx_compiler_includes_from_setuputils() + get_cflags())
1868
-
flags = sep.join(["$(DEPFLAGS)"] + get_new_cxx_compiler_flags() + get_cxx_compiler_flags_from_setuputils())
1800
+
cflags = [
1801
+
module_cflags['/code/'], module_cflags['casacore/'],
1802
+
platform_cflags[sys.platform], module_cflags['/code/'],
1803
+
platform_cflags[sys.platform], module_cflags['binding/']
1804
+
]
1805
+
includes = sep.join(get_new_cxx_compiler_includes() + get_cflags())
1806
+
flags = sep.join(["$(DEPFLAGS)"] + get_new_cxx_compiler_flags())
1869
1807
flags = flags + " -fPIC"
1808
+
# add_cflags = sysconfig.get_config_var('CFLAGS')
1870
1809
# filter out the optimization flags which Darrell has done for C and C++ compiles for setup.py build
1871
-
sys_cflags = update_sys_cflags()
1810
+
global sys_cflags
1811
+
sys_cflags = sep.join(
1812
+
list(
1813
+
filter(
1814
+
lambda flag: not flag.startswith('-O'),sysconfig.get_config_var('CFLAGS').split()
1815
+
)
1816
+
)
1817
+
)
1872
1818
grpc_dirs = ["-I" + get_grpc_srcdir() + " -I" + get_grpc_incdir()] if duse_grpc else []
1873
1819
mkdirs_cc_target = "mk_cc_obj_dirs"
1874
1820
targdirs = set()
1875
1821
cpp_list = []
1876
1822
with open("makefile", "a") as mk:
1877
-
for (mysrc, myflags) in src_and_flags:
1823
+
for (mysrc, myflags) in zip(src, cflags):
1878
1824
dflags = sep.join(myflags + duse_grpc + grpc_dirs)
1879
1825
myinc = includes
1880
1826
if mysrc == SOURCE_BINDING:
1881
1827
myinc += " -I" + python_inc
1882
1828
for s in mysrc:
1883
1829
b = os.path.splitext(s)[0]
1884
1830
objfile = obj_name.format(base=b)
1885
1831
cpp_list.append(objfile)
1886
1832
targdirs.add(os.path.dirname(objfile))
1887
1833
targ_entry = filter_optim_debug(
2023
1969
# casatools link
2024
1970
# linker = props['build.compiler.cxx']
2025
1971
#(prop_ldflags, prop_libs) = get_link_props()
2026
1972
# remove duplicates, preserving order
2027
1973
global link_libs
2028
1974
2029
1975
# ldflags1 = sep.join(props['build.flags.compile.pthread'] + arch_flags)
2030
1976
# FIXME hardcoded because I don't know where it comes from
2031
1977
# ldflags1 += ' -shared -L/opt/rh/rh-python36/root/usr/lib64 -Wl,-z,relro -Wl,-rpath,'
2032
1978
# ldflags1 += '/opt/rh/rh-python36/root/usr/lib64 -Wl,--enable-new-dtags'
2033
-
# I don't know where setuputils gets its -lpython3.6m ~BGB
2034
1979
modulelib = os.sep.join([moduledir, "__casac__", "lib"])
2035
1980
ldflags2 = '-L/opt/rh/rh-python36/root/usr/lib64 -L' + modulelib
2036
1981
# this needs to be added for the gcwrap tool libraries, but if added here, it breaks
2037
1982
# the libcasatools link
2038
1983
# -lcasatools.cpython-36m-x86_64-linux-gnu '
2039
1984
global sepl
2040
1985
ldflags2 += sepl + sepl.join(link_libs)
2041
1986
2042
1987
# The ORIGIN bit may be needed for the gcwrap tool libs, as may be the __casac__ path
2043
1988
# $$ escapes the literal $ from make, the \ escapes the literal $ from the shell
2137
2082
+ "-D_REENTRANT -I/usr/include/cfitsio -I/usr/include/eigen3 "
2138
2083
+ "-I/opt/casa/03/include -DWITHOUT_DBUS " \
2139
2084
+ "-I/usr/include/libxml2 -I/usr/include -I/usr/include/wcslib "
2140
2085
+ "-fopenmp -I/opt/rh/rh-python36/root/usr/include -Wall " \
2141
2086
+ "--param=ssp-buffer-size=4 -DAIPS_64B -DAIPS_AUTO_STL " \
2142
2087
+ "-DAIPS_DEBUG -DAIPS_HAS_QWT -DAIPS_LINUX " \
2143
2088
+ "-DAIPS_LITTLE_ENDIAN -DAIPS_STDLIB " \
2144
2089
+ "-DCASACORE_NEEDS_RETHROW -DCASA_USECASAPATH -DQWT6 " \
2145
2090
+ "-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE " \
2146
2091
+ "-DNO_CRASH_REPORTER -fno-omit-frame-pointer -DWITHOUT_ACS " \
2147
-
+ f"-DUSE_GRPC -Ibuild/binding.linux-x86_64-{pyversion}/grpc " \
2148
-
+ f"-Ibuild/lib.linux-x86_64-{pyversion}/casatools/__casac__/include "
2092
+
+ "-DUSE_GRPC -Ibuild/binding.linux-x86_64-3.6/grpc " \
2093
+
+ "-Ibuild/lib.linux-x86_64-3.6/casatools/__casac__/include "
2149
2094
# -shared causes a segfault
2150
-
+ f"-lpython{pyversion}m " + dflags + " "
2095
+
+ "-lpython3.6m " + dflags + " "
2151
2096
+ "-o " + exefile + " " + wflags + " "
2152
2097
+ f + " "
2153
2098
)
2154
2099
# ommitting POSTCOMPILE for now
2155
2100
# + '\n\t$(POSTCOMPILE)')
2156
2101
# mk.write(
2157
2102
# "\n\n" + test_targ.format(src=f, base=base)
2158
2103
# )
2159
2104
# mk.write("\n" + g_dep_targ.format(base=base))
2160
2105
# mk.write("\n" + g_dep_targ.format(base=base))
2344
2289
CODE_BINDING = source_files("src/tools", file_suffix_filter=".cc")
2345
2290
obj_name = os.path.join('build',distutils_dir_name('temp')) + os.sep + '{base}.o'
2346
2291
dep_name = os.path.join("$(DEPDIR)", build_distutils_temp, "{base}.d")
2347
2292
obj_create = (
2348
2293
obj_name + ': {src} ' + dep_name + ' makefile'
2349
2294
+ '\n\t$(CXX) $(OPTIM_FLAGS) {flags} {includes} {cflags} {dflags} -c $< -o $@'
2350
2295
+ '\n\t$(POSTCOMPILE)'
2351
2296
)
2352
2297
dep_targ = dep_name + ": ;\nPRECIOUS: " + dep_name
2353
2298
cflags = module_cflags['binding/'] + platform_cflags[sys.platform]
2354
-
includes = sep.join(get_new_cxx_compiler_includes() + get_cxx_compiler_includes_from_setuputils() + get_cflags() + ["-Isrc"])
2299
+
includes = sep.join(get_new_cxx_compiler_includes() + get_cflags() + ["-Isrc"])
2355
2300
tool_inc = "-Ibinding/generated/tools/{toolname} -Isrc/tools/{toolname}"
2356
-
flags = sep.join(["$(DEPFLAGS)"] + get_new_cxx_compiler_flags() + get_cxx_compiler_flags_from_setuputils())
2301
+
flags = sep.join(["$(DEPFLAGS)"] + get_new_cxx_compiler_flags())
2357
2302
add_cflags = sysconfig.get_config_var('CFLAGS')
2358
2303
duse_grpc = get_use_grpc()
2359
2304
grpc_dirs = ["-I" + get_grpc_srcdir() + " -I" + get_grpc_incdir()]
2360
2305
dflags = sep.join(cflags + duse_grpc + grpc_dirs)
2361
2306
cpp_list = []
2362
2307
mkdirs_statics_wrap_target = "mk_static_cc_obj_dirs"
2363
2308
targdirs = set()
2364
2309
with open("makefile", "a") as mk:
2365
2310
for s in STATICS_CC + WRAP_CPP + CODE_BINDING:
2366
2311
base = os.path.splitext(s)[0]
2516
2461
# testing
2517
2462
do_testing()
2518
2463
write_dependency_tracking()
2519
2464
2520
2465
# extra state for building unit tests
2521
2466
g_build_state['lib-path']['libcasatools'] = libcasatools
2522
2467
g_build_state['grpc'] = { 'include': [ os.path.join('build', distutils_dir_name('lib'), module_name, '__casac__', "include") ],
2523
2468
'cflags': [ '-DUSE_GRPC' ],
2524
2469
'lflags': [ ],
2525
2470
'libs': [ '-lgrpc++', '-lgrpc', '-lgpr', '-lprotobuf' ] }
2526
-
g_build_state['python'] = { 'libs': [ f"-lpython{pyversion}m" ],
2471
+
g_build_state['python'] = { 'libs': [ '-lpython3.6m' ],
2527
2472
'cflags': [ ],
2528
2473
'lflags': [ ],
2529
2474
'include': [ ] }
2530
2475
2531
2476
# dump build state for building unit tests
2532
2477
with open( build_config_file, 'w' ) as f:
2533
2478
json.dump( g_build_state, f )
2534
2479
2535
2480
print(
2536
2481
"Successfully generated makefile! Now, run 'make [-j<n>]' "
2806
2751
author="CASA development team",
2807
2752
author_email="aips2-request@nrao.edu",
2808
2753
url="https://open-bitbucket.nrao.edu/projects/CASA/repos/casatools/browse",
2809
2754
download_url="https://casa.nrao.edu/download/",
2810
2755
license="GNU Library or Lesser General Public License (LGPL)",
2811
2756
platforms=["posix"],
2812
2757
distclass=casa_binary_dist,
2813
2758
description = __doc__.split("\n")[0],
2814
2759
long_description="\n".join(__doc__.split("\n")[2:]),
2815
2760
classifiers=filter(None, classifiers.split("\n")),
2816
-
# declare this as the "casatools" package
2817
2761
package_dir={module_name: os.path.join('build',distutils_dir_name('lib'), module_name)},
2818
2762
packages=[ module_name ],
2819
-
# define our own "genmake", "ia", and "test" commands, override the setuptools built-in "build_ext" and "bdist_wheel" commands
2820
-
# which of these commands is executed is determined by the command line arguments used to start this script
2821
2763
cmdclass={ 'build_ext': casa_build_ext, 'test': casa_test, 'bdist_wheel': wheel_build, 'genmake': create_makefile, 'ia': create_makefile_ia } \
2822
2764
if wheel_build \
2823
2765
else { 'build_ext': casa_build_ext, 'test': casa_test, 'genmake': create_makefile, 'ia': create_makefile_ia },
2824
-
# precompiled binaries aka externals to include in the distribution
2825
2766
ext_modules=ext,
2826
2767
install_requires=[ 'numpy' ] )