#! /usr/bin/env python from __future__ import print_function VERSION='1.0.0' APPNAME='codas3' top = '.' from waflib import Configure, Logs, Utils # Override the waf default--it doesn't install static libraries. from waflib.Tools.c import cstlib # from waflib.Tools.fc import fcstlib # not needed here, but # can be handled as below cstlib.inst_to = '${LIBDIR}' import glob, os, sys lib_src_dirs = ['dbsource', 'ioserv', 'ioserv/main', 'use_db', 'matlab', 'ocean', 'vector', 'vstat', 'adcp/use_adcp'] bin_src_dirs = '''util ocean/cmd grid vecplot profstat adcp/adcpsect adcp/edit adcp/cal adcp/scanload adcp/ping2mat adcp/util adcp/nav ctd/load ctd/util '''.split() # test override: #bin_src_dirs = bin_src_dirs[:1] libsrclist = [] for libdir in lib_src_dirs: libsrclist.extend(glob.glob(os.path.join(libdir, '*.c'))) libsrc = ' '.join(libsrclist) binsrclist = [] for bindir in bin_src_dirs: binsrclist.extend(glob.glob(os.path.join(bindir, '*.c'))) def options(opt): opt.load('compiler_c gnu_dirs') opt.add_option('--shared', action='store_true', default=False, help='link to shared library') opt.add_option('--python_env', action='store_true', default=False, help='Use Python sys.prefix as the prefix' ' e.g. when using virtualenv or Anaconda.' ' Note: this overrides any other prefix option.') def configure(conf): conf.load('compiler_c') conf.check_cc(fragment="int main() { return 0; }\n") # The following might not be necessary or helpful: # if not conf.env['CC_NAME'] == 'msvc': # conf.load('gnu_dirs') if conf.options.python_env: if sys.platform == 'win32': # For anaconda; not sure whether it makes sense for a virtualenv. conf.env['PREFIX'] = os.path.join(sys.prefix, 'Library') else: conf.env['PREFIX'] = sys.prefix conf.env['BINDIR'] = os.path.join(conf.env.PREFIX, 'bin') conf.env['LIBDIR'] = os.path.join(conf.env.PREFIX, 'lib') if conf.check_endianness() == 'little': conf.define('WAF_CONF_BIG_ENDIAN', 0) else: conf.define('WAF_CONF_BIG_ENDIAN', 1) try: conf.check_cc(header_name='string.h', function_name='stricmp') Logs.info('Found stricmp') except conf.errors.ConfigurationError: Logs.info('No stricmp') #conf.check_cc(header_name='math.h', function_name='round', lib='m') # For now, assume every compiler has round. # There is no built-in CFLAGS_stlib (like CFLAGS_shlib), so this is # a crude way to force the static lib to be position-independent, # as required for linking into python extensions. if not conf.env['CC_NAME'] == 'msvc': conf.env.append_value('CFLAGS', ['-fPIC']) conf.env.libm = 'm' else: conf.env.libm = '' print(conf.env) with open('waf_env.txt', 'w') as envfile: print(conf.env, file=envfile) # Handle Windows backslash with escape prefix = conf.env['PREFIX'] prefix = prefix.replace('\\', '\\\\') conf.define('WAF_PREFIX', prefix) conf.write_config_header('include/config.h') includes = ['include'] def build(bld): if bld.options.shared: bld.env.codaslib = 'codas3_shared' print("Using shared library.") bld.shlib( source=libsrc, includes=includes, target='codas3_shared') else: bld.env.codaslib = 'codas3_static' print("Using static library.") bld.stlib( source=libsrc, includes=includes, target='codas3_static') for p in bin_src_dirs: bld.recurse(p) # The config step writes config.h in build/includes. incdir = bld.path.find_dir('include') bld.install_files('${PREFIX}/include/codas3', incdir.ant_glob('*.h')) bld.install_files('${PREFIX}/include/codas3', 'build/include/config.h') # When installed, everything is in "include"; there is not "include/adcp". #def post(conf): # print("in post", conf.env.DEST_OS, conf.cmd) # if conf.env.DEST_OS == 'linux' and conf.cmd == 'install': # conf.exec_command('/sbin/ldconfig -n %s' % conf.env.LIBDIR) # print("ran ldconfig")