Browse Source

waflib: add some waf plugins by FWGS

pull/2/head
Alibek Omarov 6 years ago
parent
commit
ec50c4571c
  1. 51
      scripts/waflib/cxx11.py
  2. 58
      scripts/waflib/force_32bit.py
  3. 33
      scripts/waflib/fwgslib.py
  4. 33
      scripts/waflib/gitversion.py
  5. 68
      scripts/waflib/sdl2.py

51
scripts/waflib/cxx11.py

@ -0,0 +1,51 @@ @@ -0,0 +1,51 @@
# encoding: utf-8
# cxx11.py -- check if compiler can compile C++11 code with lambdas
# Copyright (C) 2018 a1batross
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from fwgslib import get_flags_by_compiler
# Input:
# CXX11_MANDATORY(optional) -- fail if C++11 not available
# Output:
# HAVE_CXX11 -- true if C++11 available, otherwise else
def check_cxx11(ctx, msg):
try:
# not best way, but this check
# was written for exactly mainui_cpp,
# where lambdas are mandatory
ctx.check_cxx(
fragment='int main( void ){ auto pfnLambda = [](){}; return 0;}',
msg = msg)
except ctx.errors.ConfigurationError:
return False
return True
def configure(conf):
conf.env.HAVE_CXX11 = True # predict state
if not check_cxx11(conf, 'Checking if \'{0}\' supports C++11'.format(conf.env.COMPILER_CC)):
modern_cpp_flags = {
'msvc': [],
'default': ['-std=c++11']
}
flags = get_flags_by_compiler(modern_cpp_flags, conf.env.COMPILER_CC)
if(len(flags) == 0):
conf.env.HAVE_CXX11 = False
else:
env_stash = conf.env
conf.env.append_unique('CXXFLAGS', flags)
if not check_cxx11(conf, '...trying with additional flags'):
conf.env.HAVE_CXX11 = False
conf.env = env_stash
if getattr(conf.env, 'CXX11_MANDATORY'):
conf.fatal('C++11 support not available!')

58
scripts/waflib/force_32bit.py

@ -0,0 +1,58 @@ @@ -0,0 +1,58 @@
# encoding: utf-8
# force_32bit.py -- force compiler to create 32-bit code
# Copyright (C) 2018 a1batross
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
from fwgslib import get_flags_by_compiler
# Input:
# BIT32_MANDATORY(optional) -- fail if 32bit mode not available
# BIT32_ALLOW64(optional) -- ignore all checks, just set DEST_SIZEOF_VOID_P to 8
# Output:
# DEST_SIZEOF_VOID_P -- an integer, equals sizeof(void*) on target
def check_32bit(ctx, msg):
try:
ctx.check_cc(
fragment='''int main( void )
{
int check[sizeof(void*) == 4 ? 1: -1];
return 0;
}''',
msg = msg)
except ctx.errors.ConfigurationError:
return False
return True
def configure(conf):
if getattr(conf.env, 'BIT32_ALLOW64'):
conf.env.DEST_SIZEOF_VOID_P = 8
else:
if check_32bit(conf, 'Checking if \'{0}\' can target 32-bit'.format(conf.env.COMPILER_CC)):
conf.env.DEST_SIZEOF_VOID_P = 4 # predict state
else:
flag = '-m32'
# Think different.
if(conf.env.DEST_OS == 'darwin'):
flag = '-arch i386'
env_stash = conf.env
conf.env.append_value('LINKFLAGS', [flag])
conf.env.append_value('CFLAGS', [flag])
conf.env.append_value('CXXFLAGS', [flag])
if check_32bit(conf, '...trying with additional flags'.format(conf.env.COMPILER_CC)):
conf.env.DEST_SIZEOF_VOID_P = 4
else:
conf.env.DEST_SIZEOF_VOID_P = 8
conf.env = env_stash
if getattr(conf.env, 'BIT32_MANDATORY') and conf.env.DEST_SIZEOF_VOID_P == 8:
conf.fatal('Compiler can\'t create 32-bit code!')
4

33
scripts/waflib/fwgslib.py

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
# encoding: utf-8
# fwgslib.py -- utils for Waf build system by FWGS
# Copyright (C) 2018 a1batross
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
def get_subproject_name(ctx):
return os.path.basename(os.path.realpath(str(ctx.path)))
def get_flags_by_compiler(flags, compiler):
out = []
if compiler in flags:
out += flags[compiler]
elif 'default' in flags:
out += flags['default']
return out
def get_flags_by_type(flags, type, compiler):
out = []
if 'common' in flags:
out += get_flags_by_compiler(flags['common'], compiler)
if type in flags:
out += get_flags_by_compiler(flags[type], compiler)
return out

33
scripts/waflib/gitversion.py

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
# encoding: utf-8
# gitversion.py -- waf plugin to get git version
# Copyright (C) 2018 a1batross
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
def get_git_version():
# try grab the current version number from git
version = None
if os.path.exists('.git'):
try:
version = os.popen('git describe --dirty --always').read().strip()
except Exception as e:
pass
if(len(version) == 0):
version = None
return version
def configure(conf):
conf.start_msg('Checking git hash')
conf.env.GIT_VERSION = get_git_version()
conf.end_msg(conf.env.GIT_VERSION if conf.env.GIT_VERSION else 'no')

68
scripts/waflib/sdl2.py

@ -0,0 +1,68 @@ @@ -0,0 +1,68 @@
# encoding: utf-8
# sdl2.py -- sdl2 waf plugin
# Copyright (C) 2018 a1batross
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
import os
def options(opt):
opt.add_option(
'--sdl2', action='store', type='string', dest = 'SDL2_PATH', default = None,
help = 'SDL2 path to build(required for Windows)')
opt.add_option(
'--skip-sdl2-sanity-check', action='store_false', default = True, dest='SDL2_SANITY_CHECK',
help = 'Skip checking SDL2 sanity')
def configure(conf):
if conf.options.SDL2_PATH:
conf.start_msg('Configuring SDL2 by provided path')
conf.env.HAVE_SDL2 = 1
conf.env.INCLUDES_SDL2 = [
os.path.abspath(os.path.join(conf.options.SDL2_PATH, 'include')),
os.path.abspath(os.path.join(conf.options.SDL2_PATH, 'include/SDL2'))
]
libpath = 'lib'
if conf.env.COMPILER_CC == 'msvc':
if conf.env.DEST_CPU == 'x86_64':
libpath = 'lib/x64'
else:
libpath = 'lib/' + conf.env.DEST_CPU
conf.env.LIBPATH_SDL2 = [os.path.abspath(os.path.join(conf.options.SDL2_PATH, libpath))]
conf.env.LIB_SDL2 = ['SDL2']
conf.end_msg('yes: {0}, {1}, {2}'.format(conf.env.LIB_SDL2, conf.env.LIBPATH_SDL2, conf.env.INCLUDES_SDL2))
else:
try:
conf.check_cfg(
path='sdl2-config',
args='--cflags --libs',
package='',
msg='Checking for library SDL2',
uselib_store='SDL2')
except conf.errors.ConfigurationError:
conf.env.HAVE_SDL2 = 0
if conf.env.HAVE_SDL2 and conf.options.SDL2_SANITY_CHECK:
try:
conf.check_cc(
fragment='''
#define SDL_MAIN_HANDLED
#include <SDL.h>
int main( void )
{
SDL_Init( SDL_INIT_EVERYTHING );
return 0;
}''',
msg = 'Checking for library SDL2 sanity',
use = 'SDL2',
execute = False)
except conf.errors.ConfigurationError:
conf.env.HAVE_SDL2 = 0
Loading…
Cancel
Save