Commits

Sepehr Taghdisian committed efc500f

added waf build

Comments (0)

Files changed (1)

+#!/usr/bin/env python
+
+import os, sys, platform, inspect, glob
+
+top = '.'
+out = 'build'
+ROOTDIR = os.path.dirname(inspect.getfile(inspect.currentframe()))
+
+def init(ctx):
+    from waflib.Build import BuildContext, CleanContext, InstallContext, UninstallContext
+    for y in (BuildContext, CleanContext, InstallContext, UninstallContext):
+        name = y.__name__.replace('Context', '').lower()
+        class DebugCtx(y):
+            cmd = name + '_debug'   # command names like 'build_debug', 'clean_debug', etc
+            variant = 'debug'
+        class ReleaseCtx(y):
+            # if a 'cmd' is not given, the default 'build', 'clean',
+            # etc actions will be redirected to the 'release' variant dir
+            variant = 'release'
+
+def compiler_is_msvc(conf):
+    cc = conf.env['CXX'][0].lower()
+    if 'cl.exe' in cc or 'icc.exe' in cc:
+        return True
+    else:
+        return False
+
+def setup_compiler(conf):
+    # general include dirs
+    conf.env.prepend_value('INCLUDES', os.path.join(ROOTDIR, 'include'))
+
+    if compiler_is_msvc(conf):
+        conf.env.append_unique('DEFINES', ['_CRT_SECURE_NO_WARNINGS', '_CRT_NONSTDC_NO_DEPRECATE',
+            '_SCL_SECURE_NO_WARNINGS', '_MBCS'])
+
+    # debug specific flags
+    base_env = conf.env.derive()
+    conf.setenv('debug', env=base_env.derive())
+    conf.env.SUFFIX = '-dbg'
+    conf.env.append_unique('DEFINES', ['_DEBUG'])
+    if compiler_is_msvc(conf):
+        conf.env.append_unique('CXXFLAGS', ['/Od', '/Z7', '/MDd'])
+        conf.env.append_unique('LINKFLAGS', '/DEBUG')
+    else:
+        conf.env.append_unique('CXXFLAGS', ['-g', '-O0'])
+
+    # release specific flag
+    conf.setenv('release', env=base_env.derive())
+    conf.env.append_unique('DEFINES', ['NDEBUG'])
+    conf.env.SUFFIX = ''
+    if compiler_is_msvc(conf):
+        conf.env.append_unique('LINKFLAGS', '/RELEASE')
+        conf.env.append_unique('CXXFLAGS', ['/O2', '/Oi', '/MD'])
+    else:
+        conf.env.append_unique('CXXFLAGS', ['-O2', '-fomit-frame-pointer'])
+
+def options(opt):
+    opt.load('compiler_cxx')
+
+    opt.add_option('--prefix', action='store', default='', dest='PREFIX',
+        help='Install path prefix')
+
+def configure(conf):
+    conf.check_waf_version(mini='1.7.11')
+    conf.load('compiler_cxx')
+    setup_compiler(conf)
+
+    conf.env.PREFIX = os.path.abspath(conf.options.PREFIX)
+
+def build(bld):
+    files = bld.path.ant_glob('src/efsw/*.cpp')
+    if sys.platform == 'win32':
+        files.extend(bld.path.ant_glob('src/efsw/platform/win/*.cpp'))
+    else:
+        files.extend(bld.path.ant_glob('src/efsw/platform/posix/*.cpp'))
+
+    # install headers
+    if bld.env.ROOTDIR != bld.env.PREFIX:
+        bld.install_files('${PREFIX}', bld.path.ant_glob('include/efsw/*.h*'), relative_trick=True)
+
+    bld.shlib(
+        source = files,
+        defines = ['EFSW_EXPORTS', 'EFSW_DYNAMIC'],
+        includes = ['include', 'src'],
+        lib = ['stdc++'],
+        target = 'efsw' + bld.env.SUFFIX,
+        install_path = os.path.join(bld.env.PREFIX, 'lib'))