Integrate Waf build system
This commit is contained in:
parent
81d035893a
commit
61f94cfd11
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
build/
|
||||
waf3-*/
|
||||
waf-*/
|
||||
.waf3-*/
|
||||
.waf-*/
|
||||
*.kate-swp
|
||||
.lock*
|
||||
*.pyc
|
146
cl_dll/wscript
Normal file
146
cl_dll/wscript
Normal file
@ -0,0 +1,146 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# a1batross, mittorn, 2018
|
||||
|
||||
from waflib import Utils
|
||||
import os
|
||||
|
||||
def options(opt):
|
||||
grp = opt.add_option_group('Client options')
|
||||
|
||||
grp.add_option('--enable-vgui', action = 'store_true', dest = 'USE_VGUI', default = False,
|
||||
help = 'Enable VGUI1')
|
||||
grp.add_option('--enable-vgui2', action = 'store_true', dest = 'USE_VGUI2', default = False,
|
||||
help = 'Enable VGUI2. UNDONE')
|
||||
grp.add_option('--enable-novgui-motd', action = 'store_true', dest = 'USE_NOVGUI_MOTD', default = False,
|
||||
help = 'Prefer non-VGUI MOTD when USE_VGUI is enabled')
|
||||
grp.add_option('--enable-novgui-scoreboard', action = 'store_true', dest = 'USE_NOVGUI_SCOREBOARD', default = False,
|
||||
help = 'Prefer non-VGUI Scoreboard when USE_VGUI is enabled')
|
||||
grp.add_option('--disable-goldsrc-support', action = 'store_false', dest = 'GOLDSOURCE_SUPPORT',
|
||||
default=True, help = 'disable GoldSource compatibility')
|
||||
|
||||
opt.load('vgui')
|
||||
|
||||
def configure(conf):
|
||||
conf.env.USE_VGUI = conf.options.USE_VGUI
|
||||
conf.env.USE_NOVGUI_MOTD = conf.options.USE_NOVGUI_MOTD
|
||||
conf.env.USE_NOVGUI_SCOREBOARD = conf.options.USE_NOVGUI_SCOREBOARD
|
||||
conf.env.USE_VOICEMGR = conf.options.USE_VOICEMGR
|
||||
conf.env.GOLDSOURCE_SUPPORT = conf.options.GOLDSOURCE_SUPPORT
|
||||
if conf.env.USE_VGUI:
|
||||
conf.load('vgui')
|
||||
if not conf.check_vgui():
|
||||
conf.fatal('VGUI was enabled but VGUI cannot be used')
|
||||
|
||||
def build(bld):
|
||||
libs = ['VGUI']
|
||||
defines = ['CLIENT_DLL']
|
||||
includes = ['.',
|
||||
'../dlls',
|
||||
'../common',
|
||||
'../engine',
|
||||
'../pm_shared',
|
||||
'../game_shared',
|
||||
'../public']
|
||||
source = [
|
||||
'./ev_thewastes.cpp',
|
||||
'./thewastes/hl_baseentity.cpp',
|
||||
'./thewastes/hl_events.cpp',
|
||||
'./thewastes/hl_objects.cpp',
|
||||
'./thewastes/hl_weapons.cpp',
|
||||
'../common/interface.cpp',
|
||||
'../dlls/thewastes.cpp',
|
||||
'../dlls/wpn_shared/tw_akimbos.cpp',
|
||||
'../dlls/wpn_shared/tw_automatics.cpp',
|
||||
'../dlls/wpn_shared/tw_explosives.cpp',
|
||||
'../dlls/wpn_shared/tw_melee.cpp',
|
||||
'../dlls/wpn_shared/tw_shotguns.cpp',
|
||||
'../dlls/wpn_shared/tw_sidearms.cpp',
|
||||
'../game_shared/vgui_scrollbar2.cpp',
|
||||
'../game_shared/vgui_slider2.cpp',
|
||||
'../game_shared/voice_banmgr.cpp',
|
||||
'../game_shared/voice_status.cpp',
|
||||
'../game_shared/voice_vgui_tweakdlg.cpp',
|
||||
'./ammo.cpp',
|
||||
'./ammo_secondary.cpp',
|
||||
'./ammohistory.cpp',
|
||||
'./cdll_int.cpp',
|
||||
'./com_weapons.cpp',
|
||||
'./death.cpp',
|
||||
'./demo.cpp',
|
||||
'./entity.cpp',
|
||||
'./env_fog.cpp',
|
||||
'./ev_common.cpp',
|
||||
'./events.cpp',
|
||||
'./flashlight.cpp',
|
||||
'./GameStudioModelRenderer.cpp',
|
||||
'./geiger.cpp',
|
||||
'./health.cpp',
|
||||
'./hud.cpp',
|
||||
'./hud_msg.cpp',
|
||||
'./hud_redraw.cpp',
|
||||
'./hud_servers.cpp',
|
||||
'./hud_spectator.cpp',
|
||||
'./hud_update.cpp',
|
||||
'./in_camera.cpp',
|
||||
'./input.cpp',
|
||||
'./inputw32.cpp',
|
||||
'./menu.cpp',
|
||||
'./message.cpp',
|
||||
'./overview.cpp',
|
||||
'./parsebsp.cpp',
|
||||
'./ParseBspEnt.cpp',
|
||||
'./parsemsg.cpp',
|
||||
'./ParticleBase.cpp',
|
||||
'../pm_shared/pm_debug.c',
|
||||
'../pm_shared/pm_math.c',
|
||||
'../pm_shared/pm_shared.c',
|
||||
'./saytext.cpp',
|
||||
'./status_icons.cpp',
|
||||
'./statusbar.cpp',
|
||||
'./studio_util.cpp',
|
||||
'./studioevent.cpp',
|
||||
'./StudioModelRenderer.cpp',
|
||||
'./text_message.cpp',
|
||||
'./thewastes_hud.cpp',
|
||||
'./train.cpp',
|
||||
'./tri.cpp',
|
||||
'./twm.cpp',
|
||||
'./util.cpp',
|
||||
'../game_shared/vgui_checkbutton2.cpp',
|
||||
'./vgui_ConsolePanel.cpp',
|
||||
'./vgui_ControlConfigPanel.cpp',
|
||||
'./vgui_CustomObjects.cpp',
|
||||
'../game_shared/vgui_grid.cpp',
|
||||
'../game_shared/vgui_helpers.cpp',
|
||||
'./vgui_int.cpp',
|
||||
'./vgui_ItemSelection.cpp',
|
||||
'../game_shared/vgui_listbox.cpp',
|
||||
'../game_shared/vgui_loadtga.cpp',
|
||||
'./vgui_MOTDWindow.cpp',
|
||||
'./vgui_SchemeManager.cpp',
|
||||
'./vgui_ScorePanel.cpp',
|
||||
'./vgui_ServerBrowser.cpp',
|
||||
'./vgui_teammenu.cpp',
|
||||
'./vgui_TheWastesViewport.cpp',
|
||||
'./view.cpp',
|
||||
]
|
||||
|
||||
if bld.env.DEST_OS not in ['android', 'dos']:
|
||||
install_path = os.path.join(bld.env.GAMEDIR, bld.env.CLIENT_INSTALL_DIR)
|
||||
else:
|
||||
install_path = bld.env.PREFIX
|
||||
|
||||
bld.shlib(
|
||||
source = source,
|
||||
target = 'client' + bld.env.POSTFIX,
|
||||
name = 'client',
|
||||
features = 'c cxx',
|
||||
includes = includes,
|
||||
defines = defines,
|
||||
use = libs,
|
||||
install_path = install_path,
|
||||
subsystem = bld.env.MSVC_SUBSYSTEM,
|
||||
idx = bld.get_taskgen_count()
|
||||
)
|
||||
|
108
dlls/wscript
Normal file
108
dlls/wscript
Normal file
@ -0,0 +1,108 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# a1batross, mittorn, 2018
|
||||
|
||||
from waflib import Utils
|
||||
import os
|
||||
|
||||
def options(opt):
|
||||
return
|
||||
|
||||
def configure(conf):
|
||||
if conf.env.COMPILER_CC == 'msvc':
|
||||
# hl.def removes MSVC function name decoration from GiveFnptrsToDll on Windows.
|
||||
# Without this, the lookup for this function fails.
|
||||
hlDefNode = conf.path.find_resource("./thewastes.def")
|
||||
|
||||
if hlDefNode is not None:
|
||||
conf.env.append_value('LINKFLAGS', '/def:%s' % hlDefNode.abspath())
|
||||
else:
|
||||
conf.fatal("Could not find hl.def")
|
||||
|
||||
def build(bld):
|
||||
source = [
|
||||
'./animating.cpp',
|
||||
'./animation.cpp',
|
||||
'./bmodels.cpp',
|
||||
'./buttons.cpp',
|
||||
'./cbase.cpp',
|
||||
'./client.cpp',
|
||||
'./combat.cpp',
|
||||
'./doors.cpp',
|
||||
'./effects.cpp',
|
||||
'./explode.cpp',
|
||||
'./func_break.cpp',
|
||||
'./func_tank.cpp',
|
||||
'./game.cpp',
|
||||
'./game_deathmatch.cpp',
|
||||
'./game_lastmanstanding.cpp',
|
||||
'./game_singleplay.cpp',
|
||||
'./game_teamplay.cpp',
|
||||
'./gamerules.cpp',
|
||||
'./ggrenade.cpp',
|
||||
'./globals.cpp',
|
||||
'./h_ai.cpp',
|
||||
'./h_cycler.cpp',
|
||||
'./h_export.cpp',
|
||||
'./items.cpp',
|
||||
'./lights.cpp',
|
||||
'./maprules.cpp',
|
||||
'./monsters.cpp',
|
||||
'./mortar.cpp',
|
||||
'./nodes.cpp',
|
||||
'./observer.cpp',
|
||||
'./pathcorner.cpp',
|
||||
'./plane.cpp',
|
||||
'./plats.cpp',
|
||||
'./player.cpp',
|
||||
'../pm_shared/pm_debug.c',
|
||||
'../pm_shared/pm_math.c',
|
||||
'../pm_shared/pm_shared.c',
|
||||
'./schedule.cpp',
|
||||
'./scripted.cpp',
|
||||
'./skill.cpp',
|
||||
'./sound.cpp',
|
||||
'./soundent.cpp',
|
||||
'./spectator.cpp',
|
||||
'./subs.cpp',
|
||||
'./thewastes.cpp',
|
||||
'./triggers.cpp',
|
||||
'./turret.cpp',
|
||||
'./wpn_shared/tw_akimbos.cpp',
|
||||
'./wpn_shared/tw_automatics.cpp',
|
||||
'./wpn_shared/tw_explosives.cpp',
|
||||
'./wpn_shared/tw_melee.cpp',
|
||||
'./wpn_shared/tw_shotguns.cpp',
|
||||
'./wpn_shared/tw_sidearms.cpp',
|
||||
'./util.cpp',
|
||||
'../game_shared/voice_gamemgr.cpp',
|
||||
'./weapons.cpp',
|
||||
'./world.cpp',
|
||||
]
|
||||
defines = []
|
||||
includes = [
|
||||
'.',
|
||||
'../common',
|
||||
'../engine',
|
||||
'../pm_shared',
|
||||
'../game_shared',
|
||||
'../public'
|
||||
]
|
||||
|
||||
if bld.env.DEST_OS not in ['android', 'dos']:
|
||||
install_path = os.path.join(bld.env.GAMEDIR, bld.env.SERVER_INSTALL_DIR)
|
||||
else:
|
||||
install_path = bld.env.PREFIX
|
||||
|
||||
bld.shlib(
|
||||
source = source,
|
||||
target = bld.env.SERVER_LIBRARY_NAME + bld.env.POSTFIX,
|
||||
name = 'server',
|
||||
features = 'c cxx',
|
||||
includes = includes,
|
||||
defines = defines,
|
||||
install_path = install_path,
|
||||
subsystem = bld.env.MSVC_SUBSYSTEM,
|
||||
idx = bld.get_taskgen_count()
|
||||
)
|
||||
|
6
mod_options.txt
Normal file
6
mod_options.txt
Normal file
@ -0,0 +1,6 @@
|
||||
CLIENT_WEAPONS=ON
|
||||
GAMEDIR=thewastes # Gamedir path
|
||||
SERVER_INSTALL_DIR=dlls # Where put server dll
|
||||
CLIENT_INSTALL_DIR=cl_dlls # Where put client dll
|
||||
SERVER_LIBRARY_NAME=thewastes # Library name for PC platforms
|
||||
|
261
public/build.h
Normal file
261
public/build.h
Normal file
@ -0,0 +1,261 @@
|
||||
/*
|
||||
build.h - compile-time build information
|
||||
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <http://unlicense.org/>
|
||||
*/
|
||||
#pragma once
|
||||
#ifndef BUILD_H
|
||||
#define BUILD_H
|
||||
|
||||
/*
|
||||
All XASH_* macros set by this header are guaranteed to have positive value
|
||||
otherwise not defined.
|
||||
|
||||
Every macro is intended to be the unified interface for buildsystems that lack
|
||||
platform & CPU detection, and a neat quick way for checks in platform code
|
||||
For Q_build* macros, refer to buildenums.h
|
||||
|
||||
Any new define must be undefined at first
|
||||
You can generate #undef list below with this oneliner:
|
||||
$ sed 's/\t//g' build.h | grep '^#define XASH' | awk '{ print $2 }' | \
|
||||
sort | uniq | awk '{ print "#undef " $1 }'
|
||||
|
||||
Then you can use another oneliner to query all variables:
|
||||
$ grep '^#undef XASH' build.h | awk '{ print $2 }'
|
||||
*/
|
||||
|
||||
#undef XASH_64BIT
|
||||
#undef XASH_AMD64
|
||||
#undef XASH_ANDROID
|
||||
#undef XASH_APPLE
|
||||
#undef XASH_ARM
|
||||
#undef XASH_ARM_HARDFP
|
||||
#undef XASH_ARM_SOFTFP
|
||||
#undef XASH_ARMv4
|
||||
#undef XASH_ARMv5
|
||||
#undef XASH_ARMv6
|
||||
#undef XASH_ARMv7
|
||||
#undef XASH_ARMv8
|
||||
#undef XASH_BIG_ENDIAN
|
||||
#undef XASH_DOS4GW
|
||||
#undef XASH_E2K
|
||||
#undef XASH_EMSCRIPTEN
|
||||
#undef XASH_FREEBSD
|
||||
#undef XASH_HAIKU
|
||||
#undef XASH_IOS
|
||||
#undef XASH_IRIX
|
||||
#undef XASH_JS
|
||||
#undef XASH_LINUX
|
||||
#undef XASH_LINUX_UNKNOWN
|
||||
#undef XASH_LITTLE_ENDIAN
|
||||
#undef XASH_MIPS
|
||||
#undef XASH_MOBILE_PLATFORM
|
||||
#undef XASH_NETBSD
|
||||
#undef XASH_OPENBSD
|
||||
#undef XASH_POSIX
|
||||
#undef XASH_PPC
|
||||
#undef XASH_RISCV
|
||||
#undef XASH_RISCV_DOUBLEFP
|
||||
#undef XASH_RISCV_SINGLEFP
|
||||
#undef XASH_RISCV_SOFTFP
|
||||
#undef XASH_SERENITY
|
||||
#undef XASH_WIN32
|
||||
#undef XASH_X86
|
||||
#undef XASH_NSWITCH
|
||||
#undef XASH_PSVITA
|
||||
|
||||
//================================================================
|
||||
//
|
||||
// PLATFORM DETECTION CODE
|
||||
//
|
||||
//================================================================
|
||||
#if defined _WIN32
|
||||
#define XASH_WIN32 1
|
||||
#elif defined __EMSCRIPTEN__
|
||||
#define XASH_EMSCRIPTEN 1
|
||||
#elif defined __WATCOMC__ && defined __DOS__
|
||||
#define XASH_DOS4GW 1
|
||||
#else // POSIX compatible
|
||||
#define XASH_POSIX 1
|
||||
#if defined __linux__
|
||||
#if defined __ANDROID__
|
||||
#define XASH_ANDROID 1
|
||||
#else
|
||||
#include <features.h>
|
||||
// if our system libc has features.h header
|
||||
// try to detect it to not confuse other libcs with built with glibc game libraries
|
||||
#if !defined __GLIBC__
|
||||
#define XASH_LINUX_UNKNOWN 1
|
||||
#endif
|
||||
#endif
|
||||
#define XASH_LINUX 1
|
||||
#elif defined __FreeBSD__
|
||||
#define XASH_FREEBSD 1
|
||||
#elif defined __NetBSD__
|
||||
#define XASH_NETBSD 1
|
||||
#elif defined __OpenBSD__
|
||||
#define XASH_OPENBSD 1
|
||||
#elif defined __HAIKU__
|
||||
#define XASH_HAIKU 1
|
||||
#elif defined __serenity__
|
||||
#define XASH_SERENITY 1
|
||||
#elif defined __sgi
|
||||
#define XASH_IRIX 1
|
||||
#elif defined __APPLE__
|
||||
#include <TargetConditionals.h>
|
||||
#define XASH_APPLE 1
|
||||
#if TARGET_OS_IOS
|
||||
#define XASH_IOS 1
|
||||
#endif // TARGET_OS_IOS
|
||||
#elif defined __SWITCH__
|
||||
#define XASH_NSWITCH 1
|
||||
#elif defined __vita__
|
||||
#define XASH_PSVITA 1
|
||||
#else
|
||||
#error
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// XASH_SAILFISH is special: SailfishOS by itself is a normal GNU/Linux platform
|
||||
// It doesn't make sense to split it to separate platform
|
||||
// but we still need XASH_MOBILE_PLATFORM for the engine.
|
||||
// So this macro is defined entirely in build-system: see main wscript
|
||||
// HLSDK/PrimeXT/other SDKs users note: you may ignore this macro
|
||||
#if XASH_ANDROID || XASH_IOS || XASH_NSWITCH || XASH_PSVITA || XASH_SAILFISH
|
||||
#define XASH_MOBILE_PLATFORM 1
|
||||
#endif
|
||||
|
||||
//================================================================
|
||||
//
|
||||
// ENDIANNESS DEFINES
|
||||
//
|
||||
//================================================================
|
||||
|
||||
#if !defined XASH_ENDIANNESS
|
||||
#if defined XASH_WIN32 || __LITTLE_ENDIAN__
|
||||
//!!! Probably all WinNT installations runs in little endian
|
||||
#define XASH_LITTLE_ENDIAN 1
|
||||
#elif __BIG_ENDIAN__
|
||||
#define XASH_BIG_ENDIAN 1
|
||||
#elif defined __BYTE_ORDER__ && defined __ORDER_BIG_ENDIAN__ && defined __ORDER_LITTLE_ENDIAN__ // some compilers define this
|
||||
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define XASH_BIG_ENDIAN 1
|
||||
#elif __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define XASH_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
#else
|
||||
#include <sys/param.h>
|
||||
#if __BYTE_ORDER == __BIG_ENDIAN
|
||||
#define XASH_BIG_ENDIAN 1
|
||||
#elif __BYTE_ORDER == __LITTLE_ENDIAN
|
||||
#define XASH_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
#endif // !XASH_WIN32
|
||||
#endif
|
||||
|
||||
//================================================================
|
||||
//
|
||||
// CPU ARCHITECTURE DEFINES
|
||||
//
|
||||
//================================================================
|
||||
#if defined __x86_64__ || defined _M_X64
|
||||
#define XASH_64BIT 1
|
||||
#define XASH_AMD64 1
|
||||
#elif defined __i386__ || defined _X86_ || defined _M_IX86
|
||||
#define XASH_X86 1
|
||||
#elif defined __aarch64__ || defined _M_ARM64
|
||||
#define XASH_64BIT 1
|
||||
#define XASH_ARM 8
|
||||
#elif defined __mips__
|
||||
#define XASH_MIPS 1
|
||||
#elif defined __EMSCRIPTEN__
|
||||
#define XASH_JS 1
|
||||
#elif defined __e2k__
|
||||
#define XASH_64BIT 1
|
||||
#define XASH_E2K 1
|
||||
#elif defined __PPC__ || defined __powerpc__
|
||||
#define XASH_PPC 1
|
||||
#if defined __PPC64__ || defined __powerpc64__
|
||||
#define XASH_64BIT 1
|
||||
#endif
|
||||
#elif defined _M_ARM // msvc
|
||||
#define XASH_ARM 7
|
||||
#define XASH_ARM_HARDFP 1
|
||||
#elif defined __arm__
|
||||
#if __ARM_ARCH == 8 || __ARM_ARCH_8__
|
||||
#define XASH_ARM 8
|
||||
#elif __ARM_ARCH == 7 || __ARM_ARCH_7__
|
||||
#define XASH_ARM 7
|
||||
#elif __ARM_ARCH == 6 || __ARM_ARCH_6__ || __ARM_ARCH_6J__
|
||||
#define XASH_ARM 6
|
||||
#elif __ARM_ARCH == 5 || __ARM_ARCH_5__
|
||||
#define XASH_ARM 5
|
||||
#elif __ARM_ARCH == 4 || __ARM_ARCH_4__
|
||||
#define XASH_ARM 4
|
||||
#else
|
||||
#error "Unknown ARM"
|
||||
#endif
|
||||
|
||||
#if defined __SOFTFP__ || __ARM_PCS_VFP == 0
|
||||
#define XASH_ARM_SOFTFP 1
|
||||
#else // __SOFTFP__
|
||||
#define XASH_ARM_HARDFP 1
|
||||
#endif // __SOFTFP__
|
||||
#elif defined __riscv
|
||||
#define XASH_RISCV 1
|
||||
|
||||
#if __riscv_xlen == 64
|
||||
#define XASH_64BIT 1
|
||||
#elif __riscv_xlen != 32
|
||||
#error "Unknown RISC-V ABI"
|
||||
#endif
|
||||
|
||||
#if defined __riscv_float_abi_soft
|
||||
#define XASH_RISCV_SOFTFP 1
|
||||
#elif defined __riscv_float_abi_single
|
||||
#define XASH_RISCV_SINGLEFP 1
|
||||
#elif defined __riscv_float_abi_double
|
||||
#define XASH_RISCV_DOUBLEFP 1
|
||||
#else
|
||||
#error "Unknown RISC-V float ABI"
|
||||
#endif
|
||||
#else
|
||||
#error "Place your architecture name here! If this is a mistake, try to fix conditions above and report a bug"
|
||||
#endif
|
||||
|
||||
#if XASH_ARM == 8
|
||||
#define XASH_ARMv8 1
|
||||
#elif XASH_ARM == 7
|
||||
#define XASH_ARMv7 1
|
||||
#elif XASH_ARM == 6
|
||||
#define XASH_ARMv6 1
|
||||
#elif XASH_ARM == 5
|
||||
#define XASH_ARMv5 1
|
||||
#elif XASH_ARM == 4
|
||||
#define XASH_ARMv4 1
|
||||
#endif
|
||||
|
||||
#endif // BUILD_H
|
180
scripts/waifulib/compiler_optimizations.py
Normal file
180
scripts/waifulib/compiler_optimizations.py
Normal file
@ -0,0 +1,180 @@
|
||||
# encoding: utf-8
|
||||
# compiler_optimizations.py -- main entry point for configuring C/C++ compilers
|
||||
# Copyright (C) 2021 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.
|
||||
|
||||
try: from fwgslib import get_flags_by_type, get_flags_by_compiler
|
||||
except: from waflib.extras.fwgslib import get_flags_by_type, get_flags_by_compiler
|
||||
from waflib.Configure import conf
|
||||
from waflib import Logs
|
||||
|
||||
'''
|
||||
Flags can be overriden and new types can be added
|
||||
by importing this as normal Python module
|
||||
|
||||
Example:
|
||||
#!/usr/bin/env python
|
||||
from waflib.extras import compiler_optimizations
|
||||
|
||||
compiler_optimizations.VALID_BUILD_TYPES += 'gottagofast'
|
||||
compiler_optimizations.CFLAGS['gottagofast'] = {
|
||||
'gcc': ['-Ogentoo']
|
||||
}
|
||||
'''
|
||||
|
||||
VALID_BUILD_TYPES = ['fastnative', 'fast', 'release', 'debug', 'sanitize', 'msan', 'none']
|
||||
|
||||
LINKFLAGS = {
|
||||
'common': {
|
||||
'msvc': ['/DEBUG'], # always create PDB, doesn't affect result binaries
|
||||
'gcc': ['-Wl,--no-undefined'],
|
||||
'owcc': ['-Wl,option stack=512k']
|
||||
},
|
||||
'msan': {
|
||||
'clang': ['-fsanitize=memory', '-pthread'],
|
||||
'default': ['NO_MSAN_HERE']
|
||||
},
|
||||
'sanitize': {
|
||||
'clang': ['-fsanitize=undefined', '-fsanitize=address', '-pthread'],
|
||||
'gcc': ['-fsanitize=undefined', '-fsanitize=address', '-pthread'],
|
||||
'msvc': ['/SAFESEH:NO']
|
||||
},
|
||||
'debug': {
|
||||
'msvc': ['/INCREMENTAL', '/SAFESEH:NO']
|
||||
}
|
||||
}
|
||||
|
||||
CFLAGS = {
|
||||
'common': {
|
||||
# disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP
|
||||
'msvc': ['/D_USING_V110_SDK71_', '/FS', '/Zc:threadSafeInit-', '/MT', '/MP', '/Zc:__cplusplus'],
|
||||
'clang': ['-g', '-gdwarf-2', '-fvisibility=hidden', '-fno-threadsafe-statics'],
|
||||
'gcc': ['-g', '-fvisibility=hidden'],
|
||||
'owcc': ['-fno-short-enum', '-ffloat-store', '-g3']
|
||||
},
|
||||
'fast': {
|
||||
'msvc': ['/O2', '/Oy', '/Zi'],
|
||||
'gcc': {
|
||||
'3': ['-O3', '-fomit-frame-pointer'],
|
||||
'default': ['-Ofast', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer']
|
||||
},
|
||||
'clang': ['-Ofast'],
|
||||
'default': ['-O3']
|
||||
},
|
||||
'fastnative': {
|
||||
'msvc': ['/O2', '/Oy', '/Zi'],
|
||||
'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'],
|
||||
'clang': ['-Ofast', '-march=native'],
|
||||
'default': ['-O3']
|
||||
},
|
||||
'release': {
|
||||
'msvc': ['/O2', '/Zi'],
|
||||
'owcc': ['-O3', '-foptimize-sibling-calls', '-fomit-leaf-frame-pointer', '-fomit-frame-pointer', '-fschedule-insns', '-funsafe-math-optimizations', '-funroll-loops', '-frerun-optimizer', '-finline-functions', '-finline-limit=512', '-fguess-branch-probability', '-fno-strict-aliasing', '-floop-optimize'],
|
||||
'default': ['-O3']
|
||||
},
|
||||
'debug': {
|
||||
'msvc': ['/Od', '/ZI'],
|
||||
'owcc': ['-O0', '-fno-omit-frame-pointer', '-funwind-tables', '-fno-omit-leaf-frame-pointer'],
|
||||
'default': ['-O0']
|
||||
},
|
||||
'msan': {
|
||||
'clang': ['-O2', '-g', '-fno-omit-frame-pointer', '-fsanitize=memory', '-pthread'],
|
||||
'default': ['NO_MSAN_HERE']
|
||||
},
|
||||
'sanitize': {
|
||||
'msvc': ['/Od', '/RTC1', '/Zi', '/fsanitize=address'],
|
||||
'gcc': ['-O0', '-fsanitize=undefined', '-fsanitize=address', '-pthread'],
|
||||
'clang': ['-O0', '-fsanitize=undefined', '-fsanitize=address', '-pthread'],
|
||||
'default': ['-O0']
|
||||
},
|
||||
}
|
||||
|
||||
LTO_CFLAGS = {
|
||||
'msvc': ['/GL'],
|
||||
'gcc': ['-flto'],
|
||||
'clang': ['-flto']
|
||||
}
|
||||
|
||||
LTO_LINKFLAGS = {
|
||||
'msvc': ['/LTCG'],
|
||||
'gcc': ['-flto'],
|
||||
'clang': ['-flto']
|
||||
}
|
||||
|
||||
POLLY_CFLAGS = {
|
||||
'gcc': ['-fgraphite-identity'],
|
||||
'clang': ['-mllvm', '-polly']
|
||||
# msvc sosat :(
|
||||
}
|
||||
|
||||
def options(opt):
|
||||
grp = opt.add_option_group('Compiler optimization options')
|
||||
|
||||
grp.add_option('-T', '--build-type', action='store', dest='BUILD_TYPE', default='release',
|
||||
help = 'build type: debug, release or none(custom flags)')
|
||||
|
||||
grp.add_option('--enable-lto', action = 'store_true', dest = 'LTO', default = False,
|
||||
help = 'enable Link Time Optimization if possible [default: %default]')
|
||||
|
||||
grp.add_option('--enable-poly-opt', action = 'store_true', dest = 'POLLY', default = False,
|
||||
help = 'enable polyhedral optimization if possible [default: %default]')
|
||||
|
||||
def configure(conf):
|
||||
conf.start_msg('Build type')
|
||||
|
||||
if not conf.options.BUILD_TYPE in VALID_BUILD_TYPES:
|
||||
conf.end_msg(conf.options.BUILD_TYPE, color='RED')
|
||||
conf.fatal('Invalid build type. Valid are: %s' % ', '.join(VALID_BUILD_TYPES))
|
||||
|
||||
conf.end_msg(conf.options.BUILD_TYPE)
|
||||
|
||||
conf.msg('LTO build', 'yes' if conf.options.LTO else 'no')
|
||||
conf.msg('PolyOpt build', 'yes' if conf.options.POLLY else 'no')
|
||||
|
||||
# -march=native should not be used
|
||||
if conf.options.BUILD_TYPE.startswith('fast'):
|
||||
Logs.warn('WARNING: \'%s\' build type should not be used in release builds', conf.options.BUILD_TYPE)
|
||||
|
||||
try:
|
||||
conf.env.CC_VERSION[0]
|
||||
except IndexError:
|
||||
conf.env.CC_VERSION = (0,)
|
||||
|
||||
@conf
|
||||
def get_optimization_flags(conf):
|
||||
'''Returns a list of compile flags,
|
||||
depending on build type and options set by user
|
||||
|
||||
NOTE: it doesn't filter out unsupported flags
|
||||
|
||||
:returns: tuple of cflags and linkflags
|
||||
'''
|
||||
linkflags = conf.get_flags_by_type(LINKFLAGS, conf.options.BUILD_TYPE, conf.env.COMPILER_CC, conf.env.CC_VERSION[0])
|
||||
|
||||
cflags = conf.get_flags_by_type(CFLAGS, conf.options.BUILD_TYPE, conf.env.COMPILER_CC, conf.env.CC_VERSION[0])
|
||||
|
||||
if conf.options.LTO:
|
||||
linkflags+= conf.get_flags_by_compiler(LTO_LINKFLAGS, conf.env.COMPILER_CC)
|
||||
cflags += conf.get_flags_by_compiler(LTO_CFLAGS, conf.env.COMPILER_CC)
|
||||
|
||||
if conf.options.POLLY:
|
||||
cflags += conf.get_flags_by_compiler(POLLY_CFLAGS, conf.env.COMPILER_CC)
|
||||
|
||||
if conf.env.DEST_OS == 'nswitch' and conf.options.BUILD_TYPE == 'debug':
|
||||
# enable remote debugger
|
||||
cflags.append('-DNSWITCH_DEBUG')
|
||||
elif conf.env.DEST_OS == 'psvita':
|
||||
# this optimization is broken in vitasdk
|
||||
cflags.append('-fno-optimize-sibling-calls')
|
||||
# remove fvisibility to allow everything to be exported by default
|
||||
cflags.remove('-fvisibility=hidden')
|
||||
|
||||
return cflags, linkflags
|
178
scripts/waifulib/library_naming.py
Normal file
178
scripts/waifulib/library_naming.py
Normal file
@ -0,0 +1,178 @@
|
||||
#! /usr/bin/env python
|
||||
# Copyright 2019 (C) a1batross
|
||||
|
||||
from waflib import Configure, Errors, Utils
|
||||
|
||||
# TODO: make generic
|
||||
CHECK_SYMBOL_EXISTS_FRAGMENT = '''
|
||||
#include "build.h"
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
(void)argv;
|
||||
#ifndef %s
|
||||
return ((int*)(&%s))[argc];
|
||||
#else
|
||||
(void)argc;
|
||||
return 0;
|
||||
#endif
|
||||
}
|
||||
'''
|
||||
|
||||
# generated(see comments in public/build.h)
|
||||
# cat build.h | grep '^#undef XASH' | awk '{ print "'\''" $2 "'\''," }'
|
||||
DEFINES = [
|
||||
'XASH_64BIT',
|
||||
'XASH_AMD64',
|
||||
'XASH_ANDROID',
|
||||
'XASH_APPLE',
|
||||
'XASH_ARM',
|
||||
'XASH_ARM_HARDFP',
|
||||
'XASH_ARM_SOFTFP',
|
||||
'XASH_ARMv4',
|
||||
'XASH_ARMv5',
|
||||
'XASH_ARMv6',
|
||||
'XASH_ARMv7',
|
||||
'XASH_ARMv8',
|
||||
'XASH_BIG_ENDIAN',
|
||||
'XASH_DOS4GW',
|
||||
'XASH_E2K',
|
||||
'XASH_EMSCRIPTEN',
|
||||
'XASH_FREEBSD',
|
||||
'XASH_HAIKU',
|
||||
'XASH_IOS',
|
||||
'XASH_IRIX',
|
||||
'XASH_JS',
|
||||
'XASH_LINUX',
|
||||
'XASH_LINUX_UNKNOWN',
|
||||
'XASH_LITTLE_ENDIAN',
|
||||
'XASH_MIPS',
|
||||
'XASH_MOBILE_PLATFORM',
|
||||
'XASH_NETBSD',
|
||||
'XASH_OPENBSD',
|
||||
'XASH_POSIX',
|
||||
'XASH_PPC',
|
||||
'XASH_RISCV',
|
||||
'XASH_RISCV_DOUBLEFP',
|
||||
'XASH_RISCV_SINGLEFP',
|
||||
'XASH_RISCV_SOFTFP',
|
||||
'XASH_SERENITY',
|
||||
'XASH_WIN32',
|
||||
'XASH_X86',
|
||||
'XASH_NSWITCH',
|
||||
'XASH_PSVITA',
|
||||
]
|
||||
|
||||
def configure(conf):
|
||||
conf.env.stash()
|
||||
conf.start_msg('Determining library postfix')
|
||||
tests = map(lambda x: {
|
||||
'fragment': CHECK_SYMBOL_EXISTS_FRAGMENT % (x, x),
|
||||
'includes': [conf.path.find_node('public/').abspath()],
|
||||
'define_name': x }, DEFINES )
|
||||
|
||||
conf.multicheck(*tests, msg = '', mandatory = False, quiet = True)
|
||||
|
||||
# engine/common/build.c
|
||||
if conf.env.XASH_ANDROID:
|
||||
buildos = "android"
|
||||
elif conf.env.XASH_LINUX_UNKNOWN:
|
||||
buildos = "linuxunkabi"
|
||||
elif conf.env.XASH_WIN32 or conf.env.XASH_LINUX or conf.env.XASH_APPLE:
|
||||
buildos = "" # no prefix for default OS
|
||||
elif conf.env.XASH_FREEBSD:
|
||||
buildos = "freebsd"
|
||||
elif conf.env.XASH_NETBSD:
|
||||
buildos = "netbsd"
|
||||
elif conf.env.XASH_OPENBSD:
|
||||
buildos = "openbsd"
|
||||
elif conf.env.XASH_EMSCRIPTEN:
|
||||
buildos = "emscripten"
|
||||
elif conf.env.XASH_DOS4GW:
|
||||
buildos = "dos4gw" # unused, just in case
|
||||
elif conf.env.XASH_HAIKU:
|
||||
buildos = "haiku"
|
||||
elif conf.env.XASH_SERENITY:
|
||||
buildos = "serenityos"
|
||||
elif conf.env.XASH_NSWITCH:
|
||||
buildos = "nswitch"
|
||||
elif conf.env.XASH_PSVITA:
|
||||
buildos = "psvita"
|
||||
elif conf.env.XASH_IRIX:
|
||||
buildos = "irix"
|
||||
else:
|
||||
conf.fatal("Place your operating system name in build.h and library_naming.py!\n"
|
||||
"If this is a mistake, try to fix conditions above and report a bug")
|
||||
|
||||
if conf.env.XASH_AMD64:
|
||||
buildarch = "amd64"
|
||||
elif conf.env.XASH_X86:
|
||||
if conf.env.XASH_WIN32 or conf.env.XASH_LINUX or conf.env.XASH_APPLE:
|
||||
buildarch = ""
|
||||
else:
|
||||
buildarch = "i386"
|
||||
elif conf.env.XASH_ARM and conf.env.XASH_64BIT:
|
||||
buildarch = "arm64"
|
||||
elif conf.env.XASH_ARM:
|
||||
buildarch = "armv"
|
||||
if conf.env.XASH_ARMv8:
|
||||
buildarch += "8_32"
|
||||
elif conf.env.XASH_ARMv7:
|
||||
buildarch += "7"
|
||||
elif conf.env.XASH_ARMv6:
|
||||
buildarch += "6"
|
||||
elif conf.env.XASH_ARMv5:
|
||||
buildarch += "5"
|
||||
elif conf.env.XASH_ARMv4:
|
||||
buildarch += "4"
|
||||
else:
|
||||
raise conf.fatal('Unknown ARM')
|
||||
|
||||
if conf.env.XASH_ARM_HARDFP:
|
||||
buildarch += "hf"
|
||||
else:
|
||||
buildarch += "l"
|
||||
elif conf.env.XASH_MIPS:
|
||||
buildarch = "mips"
|
||||
if conf.env.XASH_64BIT:
|
||||
buildarch += "64"
|
||||
if conf.env.XASH_LITTLE_ENDIAN:
|
||||
buildarch += "el"
|
||||
elif conf.env.XASH_RISCV:
|
||||
buildarch = "riscv"
|
||||
if conf.env.XASH_64BIT:
|
||||
buildarch += "64"
|
||||
else:
|
||||
buildarch += "32"
|
||||
|
||||
if conf.env.XASH_RISCV_DOUBLEFP:
|
||||
buildarch += "d"
|
||||
elif conf.env.XASH_RISCV_SINGLEFP:
|
||||
buildarch += "f"
|
||||
elif conf.env.XASH_JS:
|
||||
buildarch = "javascript"
|
||||
elif conf.env.XASH_E2K:
|
||||
buildarch = "e2k"
|
||||
elif conf.env.XASH_PPC:
|
||||
buildarch = "ppc"
|
||||
if conf.env.XASH_64BIT:
|
||||
buildarch += "64"
|
||||
if conf.env.XASH_LITTLE_ENDIAN:
|
||||
buildarch += "el"
|
||||
else:
|
||||
raise conf.fatal("Place your architecture name in build.h and library_naming.py!\n"
|
||||
"If this is a mistake, try to fix conditions above and report a bug")
|
||||
|
||||
conf.env.revert()
|
||||
|
||||
if buildos == 'android':
|
||||
# force disable for Android, as Android ports aren't distributed in normal way and doesn't follow library naming
|
||||
conf.env.POSTFIX = ''
|
||||
elif buildos != '' and buildarch != '':
|
||||
conf.env.POSTFIX = '_%s_%s' % (buildos,buildarch)
|
||||
elif buildarch != '':
|
||||
conf.env.POSTFIX = '_%s' % buildarch
|
||||
else:
|
||||
conf.env.POSTFIX = ''
|
||||
|
||||
conf.end_msg(conf.env.POSTFIX)
|
49
scripts/waifulib/strip_on_install.py
Normal file
49
scripts/waifulib/strip_on_install.py
Normal file
@ -0,0 +1,49 @@
|
||||
#! /usr/bin/env python
|
||||
# Modified: Alibek Omarov <a1ba.omarov@gmail.com>
|
||||
# Originally taken from Thomas Nagy's blogpost
|
||||
|
||||
"""
|
||||
Strip executables upon installation
|
||||
"""
|
||||
|
||||
import shutil, os
|
||||
from waflib import Build, Utils, Context, Errors, Logs
|
||||
|
||||
def options(opt):
|
||||
grp = opt.option_groups['install/uninstall options']
|
||||
grp.add_option('--no-strip', dest='no_strip', action='store_true', default=False,
|
||||
help='don\'t strip binaries. You must pass this flag to install command(default: False)')
|
||||
|
||||
def configure(conf):
|
||||
if conf.env.DEST_BINFMT in ['elf', 'mac-o']:
|
||||
conf.find_program('strip', var='STRIP')
|
||||
if not conf.env.STRIPFLAGS:
|
||||
conf.env.STRIPFLAGS = os.environ['STRIPFLAGS'] if 'STRIPFLAGS' in os.environ else []
|
||||
|
||||
def copy_fun(self, src, tgt):
|
||||
inst_copy_fun(self, src, tgt)
|
||||
|
||||
if self.generator.bld.options.no_strip:
|
||||
return
|
||||
|
||||
if self.env.DEST_BINFMT not in ['elf', 'mac-o']: # don't strip unknown formats or PE
|
||||
return
|
||||
|
||||
if getattr(self.generator, 'link_task', None) and self.generator.link_task.outputs[0] in self.inputs:
|
||||
cmd = self.env.STRIP + self.env.STRIPFLAGS + [tgt]
|
||||
try:
|
||||
self.generator.bld.cmd_and_log(cmd, output=Context.BOTH, quiet=Context.BOTH)
|
||||
if not self.generator.bld.progress_bar:
|
||||
c1 = Logs.colors.NORMAL
|
||||
c2 = Logs.colors.CYAN
|
||||
|
||||
f1 = os.path.getsize(src)
|
||||
f2 = os.path.getsize(tgt)
|
||||
|
||||
Logs.info('%s+ strip %s%s%s (%d bytes change)', c1, c2, tgt, c1, f2 - f1)
|
||||
except Errors.WafError as e:
|
||||
print(e.stdout, e.stderr)
|
||||
|
||||
inst_copy_fun = Build.inst.copy_fun
|
||||
Build.inst.copy_fun = copy_fun
|
||||
|
79
scripts/waifulib/vgui.py
Normal file
79
scripts/waifulib/vgui.py
Normal file
@ -0,0 +1,79 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# mittorn, 2018
|
||||
|
||||
from waflib.Configure import conf
|
||||
import os
|
||||
|
||||
VGUI_SUPPORTED_OS = ['win32', 'darwin', 'linux']
|
||||
|
||||
VGUI_FRAGMENT = '''#include <VGUI.h>
|
||||
int main() { return 0; }'''
|
||||
|
||||
def options(opt):
|
||||
grp = opt.add_option_group('VGUI options')
|
||||
|
||||
vgui_dev_path = os.path.join(opt.path.path_from(opt.path), 'vgui_support', 'vgui-dev')
|
||||
|
||||
grp.add_option('--vgui', action = 'store', dest = 'VGUI_DEV', default=vgui_dev_path,
|
||||
help = 'path to vgui-dev repo [default: %default]')
|
||||
|
||||
grp.add_option('--skip-vgui-sanity-check', action = 'store_false', dest = 'VGUI_SANITY_CHECK', default=True,
|
||||
help = 'skip checking VGUI sanity [default: %default]' )
|
||||
return
|
||||
|
||||
@conf
|
||||
def check_vgui(conf):
|
||||
conf.start_msg('Does this architecture support VGUI?')
|
||||
|
||||
if conf.env.DEST_CPU != 'x86' and not (conf.env.DEST_CPU == 'x86_64' and not conf.options.ALLOW64):
|
||||
conf.end_msg('no')
|
||||
Logs.warn('vgui is not supported on this CPU: ' + str(conf.env.DEST_CPU))
|
||||
return False
|
||||
else: conf.end_msg('yes')
|
||||
|
||||
conf.start_msg('Does this OS support VGUI?')
|
||||
if conf.env.DEST_OS not in VGUI_SUPPORTED_OS:
|
||||
conf.end_msg('no')
|
||||
Logs.warn('vgui is not supported on this OS: ' + str(conf.env.DEST_OS))
|
||||
return False
|
||||
else: conf.end_msg('yes')
|
||||
|
||||
conf.start_msg('Does this toolchain able to link VGUI?')
|
||||
if conf.env.DEST_OS == 'win32' and conf.env.COMPILER_CXX == 'g++':
|
||||
conf.end_msg('no')
|
||||
# we have ABI incompatibility ONLY on MinGW
|
||||
Logs.warn('vgui can\'t be linked with MinGW')
|
||||
return False
|
||||
else: conf.end_msg('yes')
|
||||
|
||||
conf.start_msg('Configuring VGUI by provided path')
|
||||
vgui_dev = conf.options.VGUI_DEV
|
||||
|
||||
if conf.env.DEST_OS == 'win32':
|
||||
conf.env.LIB_VGUI = ['vgui']
|
||||
conf.env.LIBPATH_VGUI = [os.path.abspath(os.path.join(vgui_dev, 'lib/win32_vc6/'))]
|
||||
else:
|
||||
libpath = os.path.abspath(os.path.join(vgui_dev, 'lib'))
|
||||
if conf.env.DEST_OS == 'linux':
|
||||
conf.env.LIB_VGUI = [':vgui.so']
|
||||
conf.env.LIBPATH_VGUI = [libpath]
|
||||
elif conf.env.DEST_OS == 'darwin':
|
||||
conf.env.LDFLAGS_VGUI = [os.path.join(libpath, 'vgui.dylib')]
|
||||
else:
|
||||
conf.fatal('vgui is not supported on this OS: ' + conf.env.DEST_OS)
|
||||
conf.env.INCLUDES_VGUI = [os.path.abspath(os.path.join(vgui_dev, 'include'))]
|
||||
|
||||
conf.env.HAVE_VGUI = 1
|
||||
conf.end_msg('yes: {0}, {1}, {2}'.format(conf.env.LIB_VGUI, conf.env.LIBPATH_VGUI, conf.env.INCLUDES_VGUI))
|
||||
|
||||
if conf.env.HAVE_VGUI and conf.options.VGUI_SANITY_CHECK:
|
||||
try:
|
||||
conf.check_cxx(fragment=VGUI_FRAGMENT,
|
||||
msg = 'Checking for library VGUI sanity',
|
||||
use = 'VGUI',
|
||||
execute = False)
|
||||
except conf.errors.ConfigurationError:
|
||||
conf.fatal("Can't compile simple program. Check your path to vgui-dev repository.")
|
||||
|
||||
return True
|
660
scripts/waifulib/xcompile.py
Normal file
660
scripts/waifulib/xcompile.py
Normal file
@ -0,0 +1,660 @@
|
||||
# encoding: utf-8
|
||||
# xcompile.py -- crosscompiling utils
|
||||
# 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.
|
||||
|
||||
try: from fwgslib import get_flags_by_compiler
|
||||
except: from waflib.extras.fwgslib import get_flags_by_compiler
|
||||
from waflib import Logs, TaskGen
|
||||
from waflib.Tools import c_config
|
||||
from collections import OrderedDict
|
||||
import os
|
||||
import sys
|
||||
|
||||
ANDROID_NDK_ENVVARS = ['ANDROID_NDK_HOME', 'ANDROID_NDK']
|
||||
ANDROID_NDK_SUPPORTED = [10, 19, 20, 23, 25]
|
||||
ANDROID_NDK_HARDFP_MAX = 11 # latest version that supports hardfp
|
||||
ANDROID_NDK_GCC_MAX = 17 # latest NDK that ships with GCC
|
||||
ANDROID_NDK_UNIFIED_SYSROOT_MIN = 15
|
||||
ANDROID_NDK_SYSROOT_FLAG_MAX = 19 # latest NDK that need --sysroot flag
|
||||
ANDROID_NDK_API_MIN = { 10: 3, 19: 16, 20: 16, 23: 16, 25: 19 } # minimal API level ndk revision supports
|
||||
|
||||
ANDROID_STPCPY_API_MIN = 21 # stpcpy() introduced in SDK 21
|
||||
ANDROID_64BIT_API_MIN = 21 # minimal API level that supports 64-bit targets
|
||||
|
||||
NSWITCH_ENVVARS = ['DEVKITPRO']
|
||||
|
||||
PSVITA_ENVVARS = ['VITASDK']
|
||||
|
||||
# This class does support ONLY r10e and r19c/r20 NDK
|
||||
class Android:
|
||||
ctx = None # waf context
|
||||
arch = None
|
||||
toolchain = None
|
||||
api = None
|
||||
ndk_home = None
|
||||
ndk_rev = 0
|
||||
is_hardfloat = False
|
||||
clang = False
|
||||
|
||||
def __init__(self, ctx, arch, toolchain, api):
|
||||
self.ctx = ctx
|
||||
self.api = api
|
||||
self.toolchain = toolchain
|
||||
self.arch = arch
|
||||
|
||||
for i in ANDROID_NDK_ENVVARS:
|
||||
self.ndk_home = os.getenv(i)
|
||||
if self.ndk_home != None:
|
||||
break
|
||||
else:
|
||||
ctx.fatal('Set %s environment variable pointing to the root of Android NDK!' %
|
||||
' or '.join(ANDROID_NDK_ENVVARS))
|
||||
|
||||
# TODO: this were added at some point of NDK development
|
||||
# but I don't know at which version
|
||||
# r10e don't have it
|
||||
source_prop = os.path.join(self.ndk_home, 'source.properties')
|
||||
if os.path.exists(source_prop):
|
||||
with open(source_prop) as ndk_props_file:
|
||||
for line in ndk_props_file.readlines():
|
||||
tokens = line.split('=')
|
||||
trimed_tokens = [token.strip() for token in tokens]
|
||||
|
||||
if 'Pkg.Revision' in trimed_tokens:
|
||||
self.ndk_rev = int(trimed_tokens[1].split('.')[0])
|
||||
|
||||
if self.ndk_rev not in ANDROID_NDK_SUPPORTED:
|
||||
ctx.fatal('Unknown NDK revision: %d' % (self.ndk_rev))
|
||||
else:
|
||||
self.ndk_rev = ANDROID_NDK_SUPPORTED[0]
|
||||
|
||||
if 'clang' in self.toolchain or self.ndk_rev > ANDROID_NDK_GCC_MAX:
|
||||
self.clang = True
|
||||
|
||||
if self.arch == 'armeabi-v7a-hard':
|
||||
if self.ndk_rev <= ANDROID_NDK_HARDFP_MAX:
|
||||
self.arch = 'armeabi-v7a' # Only armeabi-v7a have hard float ABI
|
||||
self.is_hardfloat = True
|
||||
else:
|
||||
ctx.fatal('NDK does not support hardfloat ABI')
|
||||
|
||||
if self.api < ANDROID_NDK_API_MIN[self.ndk_rev]:
|
||||
self.api = ANDROID_NDK_API_MIN[self.ndk_rev]
|
||||
Logs.warn('API level automatically was set to %d due to NDK support' % self.api)
|
||||
|
||||
if self.is_arm64() or self.is_amd64() and self.api < ANDROID_64BIT_API_MIN:
|
||||
self.api = ANDROID_64BIT_API_MIN
|
||||
Logs.warn('API level for 64-bit target automatically was set to %d' % self.api)
|
||||
|
||||
def is_host(self):
|
||||
'''
|
||||
Checks if we using host compiler(implies clang)
|
||||
'''
|
||||
return self.toolchain == 'host'
|
||||
|
||||
def is_arm(self):
|
||||
'''
|
||||
Checks if selected architecture is **32-bit** ARM
|
||||
'''
|
||||
return self.arch.startswith('armeabi')
|
||||
|
||||
def is_x86(self):
|
||||
'''
|
||||
Checks if selected architecture is **32-bit** or **64-bit** x86
|
||||
'''
|
||||
return self.arch == 'x86'
|
||||
|
||||
def is_amd64(self):
|
||||
'''
|
||||
Checks if selected architecture is **64-bit** x86
|
||||
'''
|
||||
return self.arch == 'x86_64'
|
||||
|
||||
def is_arm64(self):
|
||||
'''
|
||||
Checks if selected architecture is AArch64
|
||||
'''
|
||||
return self.arch == 'aarch64'
|
||||
|
||||
def is_clang(self):
|
||||
'''
|
||||
Checks if selected toolchain is Clang (TODO)
|
||||
'''
|
||||
return self.clang
|
||||
|
||||
def is_hardfp(self):
|
||||
return self.is_hardfloat
|
||||
|
||||
def ndk_triplet(self, llvm_toolchain = False, toolchain_folder = False):
|
||||
if self.is_x86():
|
||||
if toolchain_folder:
|
||||
return 'x86'
|
||||
else:
|
||||
return 'i686-linux-android'
|
||||
elif self.is_arm():
|
||||
if llvm_toolchain:
|
||||
return 'armv7a-linux-androideabi'
|
||||
else:
|
||||
return 'arm-linux-androideabi'
|
||||
elif self.is_amd64() and toolchain_folder:
|
||||
return 'x86_64'
|
||||
else:
|
||||
return self.arch + '-linux-android'
|
||||
|
||||
def apk_arch(self):
|
||||
if self.is_arm64():
|
||||
return 'arm64-v8a'
|
||||
return self.arch
|
||||
|
||||
def gen_host_toolchain(self):
|
||||
# With host toolchain we don't care about OS
|
||||
# so just download NDK for Linux x86_64
|
||||
if 'HOST_TOOLCHAIN' in self.ctx.environ:
|
||||
return self.ctx.environ['HOST_TOOLCHAIN']
|
||||
if self.is_host():
|
||||
return 'linux-x86_64'
|
||||
|
||||
if sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
|
||||
osname = 'windows'
|
||||
elif sys.platform.startswith('darwin'):
|
||||
osname = 'darwin'
|
||||
elif sys.platform.startswith('linux'):
|
||||
osname = 'linux'
|
||||
else:
|
||||
self.ctx.fatal('Unsupported by NDK host platform')
|
||||
|
||||
if sys.maxsize > 2**32:
|
||||
arch = 'x86_64'
|
||||
else: arch = 'x86'
|
||||
|
||||
return '%s-%s' % (osname, arch)
|
||||
|
||||
def gen_gcc_toolchain_path(self):
|
||||
path = 'toolchains'
|
||||
toolchain_host = self.gen_host_toolchain()
|
||||
|
||||
if self.is_clang():
|
||||
toolchain_folder = 'llvm'
|
||||
else:
|
||||
if self.is_host():
|
||||
toolchain = '4.9'
|
||||
else:
|
||||
toolchain = self.toolchain
|
||||
|
||||
toolchain_folder = '%s-%s' % (self.ndk_triplet(toolchain_folder = True), toolchain)
|
||||
|
||||
return os.path.abspath(os.path.join(self.ndk_home, path, toolchain_folder, 'prebuilt', toolchain_host))
|
||||
|
||||
def gen_toolchain_path(self):
|
||||
if self.is_clang():
|
||||
triplet = '%s%d-' % (self.ndk_triplet(llvm_toolchain = True), self.api)
|
||||
else:
|
||||
triplet = self.ndk_triplet() + '-'
|
||||
return os.path.join(self.gen_gcc_toolchain_path(), 'bin', triplet)
|
||||
|
||||
def gen_binutils_path(self):
|
||||
if self.ndk_rev >= 23:
|
||||
return os.path.join(self.gen_gcc_toolchain_path(), 'bin')
|
||||
return os.path.join(self.gen_gcc_toolchain_path(), self.ndk_triplet(), 'bin')
|
||||
|
||||
def cc(self):
|
||||
if self.is_host():
|
||||
s = 'clang'
|
||||
environ = getattr(self.ctx, 'environ', os.environ)
|
||||
|
||||
if 'CC' in environ:
|
||||
s = environ['CC']
|
||||
|
||||
return '%s --target=%s%d' % (s, self.ndk_triplet(), self.api)
|
||||
return self.gen_toolchain_path() + ('clang' if self.is_clang() else 'gcc')
|
||||
|
||||
def cxx(self):
|
||||
if self.is_host():
|
||||
s = 'clang++'
|
||||
environ = getattr(self.ctx, 'environ', os.environ)
|
||||
|
||||
if 'CXX' in environ:
|
||||
s = environ['CXX']
|
||||
|
||||
return '%s --target=%s%d' % (s, self.ndk_triplet(), self.api)
|
||||
return self.gen_toolchain_path() + ('clang++' if self.is_clang() else 'g++')
|
||||
|
||||
def strip(self):
|
||||
if self.is_host():
|
||||
environ = getattr(self.ctx, 'environ', os.environ)
|
||||
|
||||
if 'STRIP' in environ:
|
||||
return environ['STRIP']
|
||||
return 'llvm-strip'
|
||||
|
||||
if self.ndk_rev >= 23:
|
||||
return os.path.join(self.gen_binutils_path(), 'llvm-strip')
|
||||
return os.path.join(self.gen_binutils_path(), 'strip')
|
||||
|
||||
def system_stl(self):
|
||||
# TODO: proper STL support
|
||||
return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include'))
|
||||
|
||||
def libsysroot(self):
|
||||
arch = self.arch
|
||||
if self.is_arm():
|
||||
arch = 'arm'
|
||||
elif self.is_arm64():
|
||||
arch = 'arm64'
|
||||
path = 'platforms/android-%s/arch-%s' % (self.api, arch)
|
||||
|
||||
return os.path.abspath(os.path.join(self.ndk_home, path))
|
||||
|
||||
def sysroot(self):
|
||||
if self.ndk_rev >= ANDROID_NDK_UNIFIED_SYSROOT_MIN:
|
||||
return os.path.abspath(os.path.join(self.ndk_home, 'sysroot'))
|
||||
else:
|
||||
return self.libsysroot()
|
||||
|
||||
def cflags(self, cxx = False):
|
||||
cflags = []
|
||||
|
||||
if self.ndk_rev <= ANDROID_NDK_SYSROOT_FLAG_MAX:
|
||||
cflags += ['--sysroot=%s' % (self.sysroot())]
|
||||
else:
|
||||
if self.is_host():
|
||||
cflags += [
|
||||
'--sysroot=%s/sysroot' % (self.gen_gcc_toolchain_path()),
|
||||
'-isystem', '%s/usr/include/' % (self.sysroot())
|
||||
]
|
||||
|
||||
cflags += ['-I%s' % (self.system_stl())]
|
||||
if not self.is_clang():
|
||||
cflags += ['-DANDROID', '-D__ANDROID__']
|
||||
|
||||
if cxx and not self.is_clang() and self.toolchain not in ['4.8','4.9']:
|
||||
cflags += ['-fno-sized-deallocation']
|
||||
|
||||
if self.is_clang():
|
||||
# stpcpy() isn't available in early Android versions
|
||||
# disable it here so Clang won't use it
|
||||
if self.api < ANDROID_STPCPY_API_MIN:
|
||||
cflags += ['-fno-builtin-stpcpy']
|
||||
|
||||
if self.is_arm():
|
||||
if self.arch == 'armeabi-v7a':
|
||||
# ARMv7 support
|
||||
cflags += ['-mthumb', '-mfpu=neon', '-mcpu=cortex-a9']
|
||||
|
||||
if self.is_hardfp():
|
||||
cflags += ['-D_NDK_MATH_NO_SOFTFP=1', '-mfloat-abi=hard', '-DLOAD_HARDFP', '-DSOFTFP_LINK']
|
||||
|
||||
if self.is_host():
|
||||
# Clang builtin redefine w/ different calling convention bug
|
||||
# NOTE: I did not added complex.h functions here, despite
|
||||
# that NDK devs forgot to put __NDK_FPABI_MATH__ for complex
|
||||
# math functions
|
||||
# I personally don't need complex numbers support, but if you want it
|
||||
# just run sed to patch header
|
||||
for f in ['strtod', 'strtof', 'strtold']:
|
||||
cflags += ['-fno-builtin-%s' % f]
|
||||
else:
|
||||
cflags += ['-mfloat-abi=softfp']
|
||||
else:
|
||||
# ARMv5 support
|
||||
cflags += ['-march=armv5te', '-msoft-float']
|
||||
elif self.is_x86():
|
||||
cflags += ['-mtune=atom', '-march=atom', '-mssse3', '-mfpmath=sse']
|
||||
return cflags
|
||||
|
||||
# they go before object list
|
||||
def linkflags(self):
|
||||
linkflags = []
|
||||
if self.is_host():
|
||||
linkflags += ['--gcc-toolchain=%s' % self.gen_gcc_toolchain_path()]
|
||||
|
||||
if self.ndk_rev <= ANDROID_NDK_SYSROOT_FLAG_MAX:
|
||||
linkflags += ['--sysroot=%s' % (self.sysroot())]
|
||||
elif self.is_host():
|
||||
linkflags += ['--sysroot=%s/sysroot' % (self.gen_gcc_toolchain_path())]
|
||||
|
||||
if self.is_clang() or self.is_host():
|
||||
linkflags += ['-fuse-ld=lld']
|
||||
else: linkflags += ['-no-canonical-prefixes']
|
||||
|
||||
linkflags += ['-Wl,--hash-style=sysv', '-Wl,--no-undefined']
|
||||
return linkflags
|
||||
|
||||
def ldflags(self):
|
||||
ldflags = []
|
||||
|
||||
if self.ndk_rev < 23:
|
||||
ldflags += ['-lgcc']
|
||||
|
||||
if self.is_clang() or self.is_host():
|
||||
ldflags += ['-stdlib=libstdc++']
|
||||
else: ldflags += ['-no-canonical-prefixes']
|
||||
|
||||
if self.is_arm():
|
||||
if self.arch == 'armeabi-v7a':
|
||||
ldflags += ['-march=armv7-a', '-mthumb']
|
||||
|
||||
if not self.is_clang() and not self.is_host(): # lld only
|
||||
ldflags += ['-Wl,--fix-cortex-a8']
|
||||
|
||||
if self.is_hardfp():
|
||||
ldflags += ['-Wl,--no-warn-mismatch', '-lm_hard']
|
||||
else:
|
||||
ldflags += ['-march=armv5te']
|
||||
return ldflags
|
||||
|
||||
class NintendoSwitch:
|
||||
ctx = None # waf context
|
||||
arch = "arm64"
|
||||
dkp_dir = None
|
||||
portlibs_dir = None
|
||||
dka64_dir = None
|
||||
libnx_dir = None
|
||||
|
||||
def __init__(self, ctx):
|
||||
self.ctx = ctx
|
||||
|
||||
for i in NSWITCH_ENVVARS:
|
||||
self.dkp_dir = os.getenv(i)
|
||||
if self.dkp_dir != None:
|
||||
break
|
||||
else:
|
||||
ctx.fatal('Set %s environment variable pointing to the DEVKITPRO home!' %
|
||||
' or '.join(NSWITCH_ENVVARS))
|
||||
|
||||
self.dkp_dir = os.path.abspath(self.dkp_dir)
|
||||
|
||||
self.dka64_dir = os.path.join(self.dkp_dir, 'devkitA64')
|
||||
if not os.path.exists(self.dka64_dir):
|
||||
ctx.fatal('devkitA64 not found in `%s`. Install devkitA64!' % self.dka64_dir)
|
||||
|
||||
self.libnx_dir = os.path.join(self.dkp_dir, 'libnx')
|
||||
if not os.path.exists(self.libnx_dir):
|
||||
ctx.fatal('libnx not found in `%s`. Install libnx!' % self.libnx_dir)
|
||||
|
||||
self.portlibs_dir = os.path.join(self.dkp_dir, 'portlibs', 'switch')
|
||||
if not os.path.exists(self.portlibs_dir):
|
||||
ctx.fatal('No Switch libraries found in `%s`!' % self.portlibs_dir)
|
||||
|
||||
def gen_toolchain_prefix(self):
|
||||
return 'aarch64-none-elf-'
|
||||
|
||||
def gen_gcc_toolchain_path(self):
|
||||
return os.path.join(self.dka64_dir, 'bin', self.gen_toolchain_prefix())
|
||||
|
||||
def cc(self):
|
||||
return self.gen_gcc_toolchain_path() + 'gcc'
|
||||
|
||||
def cxx(self):
|
||||
return self.gen_gcc_toolchain_path() + 'g++'
|
||||
|
||||
def strip(self):
|
||||
return self.gen_gcc_toolchain_path() + 'strip'
|
||||
|
||||
def pkgconfig(self):
|
||||
# counter-intuitively, this motherfucker is in $DEVKITPRO/portlibs/switch/bin
|
||||
return os.path.join(self.portlibs_dir, 'bin', self.gen_toolchain_prefix() + 'pkg-config')
|
||||
|
||||
def cflags(self, cxx = False):
|
||||
cflags = []
|
||||
# arch flags
|
||||
cflags += ['-D__SWITCH__', '-march=armv8-a+crc+crypto', '-mtune=cortex-a57', '-mtp=soft', '-ftls-model=local-exec', '-fPIE']
|
||||
# help the linker out
|
||||
cflags += ['-ffunction-sections', '-fdata-sections']
|
||||
# base include dirs
|
||||
cflags += ['-isystem %s/include' % self.libnx_dir, '-I%s/include' % self.portlibs_dir]
|
||||
# the game wants GNU extensions
|
||||
if cxx:
|
||||
cflags += ['-std=gnu++17', '-D_GNU_SOURCE']
|
||||
else:
|
||||
cflags += ['-std=gnu11', '-D_GNU_SOURCE']
|
||||
return cflags
|
||||
|
||||
# they go before object list
|
||||
def linkflags(self):
|
||||
linkflags = ['-fPIE', '-specs=%s/switch.specs' % self.libnx_dir]
|
||||
# libsolder only supports sysv hashes and we need to build everything with -rdynamic
|
||||
linkflags += ['-Wl,--hash-style=sysv', '-rdynamic']
|
||||
# avoid pulling in and exposing mesa's internals, that crashes it for some god forsaken reason
|
||||
linkflags += ['-Wl,--exclude-libs=libglapi.a', '-Wl,--exclude-libs=libdrm_nouveau.a']
|
||||
return linkflags
|
||||
|
||||
def ldflags(self):
|
||||
# NOTE: shared libraries should be built without standard libs, so that they could import their contents from the NRO,
|
||||
# but executables, including the SDL2 sanity check, will generally require libstdc++ and libm, which we will add manually
|
||||
ldflags = [] # ['-lm', '-lstdc++']
|
||||
return ldflags
|
||||
|
||||
class PSVita:
|
||||
ctx = None # waf context
|
||||
arch ='armeabi-v7a-hard'
|
||||
vitasdk_dir = None
|
||||
|
||||
def __init__(self, ctx):
|
||||
self.ctx = ctx
|
||||
|
||||
for i in PSVITA_ENVVARS:
|
||||
self.vitasdk_dir = os.getenv(i)
|
||||
if self.vitasdk_dir != None:
|
||||
break
|
||||
else:
|
||||
ctx.fatal('Set %s environment variable pointing to the VitaSDK directory!' %
|
||||
' or '.join(PSVITA_ENVVARS))
|
||||
|
||||
def gen_toolchain_prefix(self):
|
||||
return 'arm-vita-eabi-'
|
||||
|
||||
def gen_gcc_toolchain_path(self):
|
||||
return os.path.join(self.vitasdk_dir, 'bin', self.gen_toolchain_prefix())
|
||||
|
||||
def cc(self):
|
||||
return self.gen_gcc_toolchain_path() + 'gcc'
|
||||
|
||||
def cxx(self):
|
||||
return self.gen_gcc_toolchain_path() + 'g++'
|
||||
|
||||
def strip(self):
|
||||
return self.gen_gcc_toolchain_path() + 'strip'
|
||||
|
||||
def ar(self):
|
||||
return self.gen_gcc_toolchain_path() + 'ar'
|
||||
|
||||
def pkgconfig(self):
|
||||
return self.gen_gcc_toolchain_path() + 'pkg-config'
|
||||
|
||||
def cflags(self, cxx = False):
|
||||
cflags = []
|
||||
# arch flags
|
||||
cflags += ['-D__vita__', '-mtune=cortex-a9', '-mfpu=neon']
|
||||
# necessary linker flags
|
||||
cflags += ['-Wl,-q', '-Wl,-z,nocopyreloc']
|
||||
# this optimization is broken in vitasdk
|
||||
cflags += ['-fno-optimize-sibling-calls']
|
||||
# disable some ARM bullshit
|
||||
cflags += ['-fno-short-enums', '-Wno-attributes']
|
||||
# base include dir
|
||||
cflags += ['-isystem %s/arm-vita-eabi/include' % self.vitasdk_dir]
|
||||
# SDL include dir
|
||||
cflags += ['-I%s/arm-vita-eabi/include/SDL2' % self.vitasdk_dir]
|
||||
return cflags
|
||||
|
||||
# they go before object list
|
||||
def linkflags(self):
|
||||
linkflags = ['-Wl,--hash-style=sysv', '-Wl,-q', '-Wl,-z,nocopyreloc', '-mtune=cortex-a9', '-mfpu=neon']
|
||||
# enforce no-short-enums again
|
||||
linkflags += ['-Wl,-no-enum-size-warning', '-fno-short-enums']
|
||||
return linkflags
|
||||
|
||||
def ldflags(self):
|
||||
ldflags = []
|
||||
return ldflags
|
||||
|
||||
def options(opt):
|
||||
xc = opt.add_option_group('Cross compile options')
|
||||
xc.add_option('--android', action='store', dest='ANDROID_OPTS', default=None,
|
||||
help='enable building for android, format: --android=<arch>,<toolchain>,<api>, example: --android=armeabi-v7a-hard,4.9,9')
|
||||
xc.add_option('--enable-magx', action='store_true', dest='MAGX', default=False,
|
||||
help='enable building for Motorola MAGX [default: %default]')
|
||||
xc.add_option('--enable-msvc-wine', action='store_true', dest='MSVC_WINE', default=False,
|
||||
help='enable building with MSVC using Wine [default: %default]')
|
||||
xc.add_option('--nswitch', action='store_true', dest='NSWITCH', default = False,
|
||||
help ='enable building for Nintendo Switch [default: %default]')
|
||||
xc.add_option('--psvita', action='store_true', dest='PSVITA', default = False,
|
||||
help ='enable building for PlayStation Vita [default: %default]')
|
||||
|
||||
def configure(conf):
|
||||
if conf.options.ANDROID_OPTS:
|
||||
values = conf.options.ANDROID_OPTS.split(',')
|
||||
if len(values) != 3:
|
||||
conf.fatal('Invalid --android paramater value!')
|
||||
|
||||
valid_archs = ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'aarch64']
|
||||
|
||||
if values[0] not in valid_archs:
|
||||
conf.fatal('Unknown arch: %s. Supported: %r' % (values[0], ', '.join(valid_archs)))
|
||||
|
||||
conf.android = android = Android(conf, values[0], values[1], int(values[2]))
|
||||
conf.environ['CC'] = android.cc()
|
||||
conf.environ['CXX'] = android.cxx()
|
||||
conf.environ['STRIP'] = android.strip()
|
||||
conf.env.CFLAGS += android.cflags()
|
||||
conf.env.CXXFLAGS += android.cflags(True)
|
||||
conf.env.LINKFLAGS += android.linkflags()
|
||||
conf.env.LDFLAGS += android.ldflags()
|
||||
|
||||
conf.env.HAVE_M = True
|
||||
if android.is_hardfp():
|
||||
conf.env.LIB_M = ['m_hard']
|
||||
else: conf.env.LIB_M = ['m']
|
||||
|
||||
conf.env.PREFIX = '/lib/%s' % android.apk_arch()
|
||||
|
||||
conf.msg('Selected Android NDK', '%s, version: %d' % (android.ndk_home, android.ndk_rev))
|
||||
# no need to print C/C++ compiler, as it would be printed by compiler_c/cxx
|
||||
conf.msg('... C/C++ flags', ' '.join(android.cflags()).replace(android.ndk_home, '$NDK/'))
|
||||
conf.msg('... link flags', ' '.join(android.linkflags()).replace(android.ndk_home, '$NDK/'))
|
||||
conf.msg('... ld flags', ' '.join(android.ldflags()).replace(android.ndk_home, '$NDK/'))
|
||||
elif conf.options.MAGX:
|
||||
# useless to change toolchain path, as toolchain meant to be placed in this path
|
||||
toolchain_path = '/opt/toolchains/motomagx/arm-eabi2/lib/'
|
||||
conf.env.INCLUDES_MAGX = [toolchain_path + i for i in ['ezx-z6/include', 'qt-2.3.8/include']]
|
||||
conf.env.LIBPATH_MAGX = [toolchain_path + i for i in ['ezx-z6/lib', 'qt-2.3.8/lib']]
|
||||
conf.env.LINKFLAGS_MAGX = ['-Wl,-rpath-link=' + i for i in conf.env.LIBPATH_MAGX]
|
||||
elif conf.options.MSVC_WINE:
|
||||
try:
|
||||
toolchain_path = conf.environ['MSVC_WINE_PATH']
|
||||
except KeyError:
|
||||
conf.fatal('Set MSVC_WINE_PATH environment variable to the MSVC toolchain root!')
|
||||
|
||||
conf.environ['CC'] = conf.environ['CXX'] = os.path.join(toolchain_path, 'bin', conf.env.MSVC_TARGETS[0], 'cl')
|
||||
conf.environ['LINK_CXX'] = os.path.join(toolchain_path, 'bin', conf.env.MSVC_TARGETS[0], 'link')
|
||||
conf.environ['AR'] = os.path.join(toolchain_path, 'bin', conf.env.MSVC_TARGETS[0], 'lib')
|
||||
conf.environ['WINRC'] = os.path.join(toolchain_path, 'bin', conf.env.MSVC_TARGETS[0], 'rc')
|
||||
conf.env.DEST_OS = 'win32'
|
||||
conf.env.DEST_CPU = conf.env.MSVC_TARGETS[0]
|
||||
conf.env.COMPILER_CXX = conf.env.COMPILER_CC = 'msvc'
|
||||
elif conf.options.NSWITCH:
|
||||
conf.nswitch = nswitch = NintendoSwitch(conf)
|
||||
conf.environ['CC'] = nswitch.cc()
|
||||
conf.environ['CXX'] = nswitch.cxx()
|
||||
conf.environ['STRIP'] = nswitch.strip()
|
||||
conf.env.PKGCONFIG = nswitch.pkgconfig()
|
||||
conf.env.CFLAGS += nswitch.cflags()
|
||||
conf.env.CXXFLAGS += nswitch.cflags(True)
|
||||
conf.env.LINKFLAGS += nswitch.linkflags()
|
||||
conf.env.LDFLAGS += nswitch.ldflags()
|
||||
conf.env.HAVE_M = True
|
||||
conf.env.LIB_M = ['m']
|
||||
conf.env.DEST_OS = 'nswitch'
|
||||
elif conf.options.PSVITA:
|
||||
conf.psvita = psvita = PSVita(conf)
|
||||
conf.environ['CC'] = psvita.cc()
|
||||
conf.environ['CXX'] = psvita.cxx()
|
||||
conf.environ['STRIP'] = psvita.strip()
|
||||
conf.environ['AR'] = psvita.ar()
|
||||
conf.env.PKGCONFIG = psvita.pkgconfig()
|
||||
conf.env.CFLAGS += psvita.cflags()
|
||||
conf.env.CXXFLAGS += psvita.cflags(True)
|
||||
conf.env.LINKFLAGS += psvita.linkflags()
|
||||
conf.env.LDFLAGS += psvita.ldflags()
|
||||
conf.env.HAVE_M = True
|
||||
conf.env.LIB_M = ['m']
|
||||
conf.env.VRTLD = ['vrtld']
|
||||
conf.env.DEST_OS = 'psvita'
|
||||
|
||||
conf.env.MAGX = conf.options.MAGX
|
||||
conf.env.MSVC_WINE = conf.options.MSVC_WINE
|
||||
MACRO_TO_DESTOS = OrderedDict({ '__ANDROID__' : 'android', '__SWITCH__' : 'nswitch', '__vita__' : 'psvita' })
|
||||
for k in c_config.MACRO_TO_DESTOS:
|
||||
MACRO_TO_DESTOS[k] = c_config.MACRO_TO_DESTOS[k] # ordering is important
|
||||
c_config.MACRO_TO_DESTOS = MACRO_TO_DESTOS
|
||||
|
||||
def post_compiler_cxx_configure(conf):
|
||||
conf.msg('Target OS', conf.env.DEST_OS)
|
||||
conf.msg('Target CPU', conf.env.DEST_CPU)
|
||||
conf.msg('Target binfmt', conf.env.DEST_BINFMT)
|
||||
|
||||
if conf.options.ANDROID_OPTS:
|
||||
if conf.android.ndk_rev == 19:
|
||||
conf.env.CXXFLAGS_cxxshlib += ['-static-libstdc++']
|
||||
conf.env.LDFLAGS_cxxshlib += ['-static-libstdc++']
|
||||
elif conf.options.MAGX:
|
||||
for lib in ['qte-mt', 'ezxappbase', 'ezxpm', 'log_util']:
|
||||
conf.check_cc(lib=lib, use='MAGX', uselib_store='MAGX')
|
||||
|
||||
return
|
||||
|
||||
def post_compiler_c_configure(conf):
|
||||
conf.msg('Target OS', conf.env.DEST_OS)
|
||||
conf.msg('Target CPU', conf.env.DEST_CPU)
|
||||
conf.msg('Target binfmt', conf.env.DEST_BINFMT)
|
||||
|
||||
return
|
||||
|
||||
from waflib.Tools import compiler_cxx, compiler_c
|
||||
|
||||
compiler_cxx_configure = getattr(compiler_cxx, 'configure')
|
||||
compiler_c_configure = getattr(compiler_c, 'configure')
|
||||
|
||||
def patch_compiler_cxx_configure(conf):
|
||||
if not conf.env.MSVC_WINE:
|
||||
compiler_cxx_configure(conf)
|
||||
else:
|
||||
conf.load('msvc', funs='no_autodetect')
|
||||
post_compiler_cxx_configure(conf)
|
||||
|
||||
def patch_compiler_c_configure(conf):
|
||||
if not conf.env.MSVC_WINE:
|
||||
compiler_c_configure(conf)
|
||||
else:
|
||||
conf.load('msvc', funs='no_autodetect')
|
||||
post_compiler_c_configure(conf)
|
||||
|
||||
setattr(compiler_cxx, 'configure', patch_compiler_cxx_configure)
|
||||
setattr(compiler_c, 'configure', patch_compiler_c_configure)
|
||||
|
||||
@TaskGen.feature('cshlib', 'cxxshlib', 'dshlib', 'fcshlib', 'vnum')
|
||||
@TaskGen.after_method('apply_link', 'propagate_uselib_vars')
|
||||
@TaskGen.before_method('apply_vnum')
|
||||
def apply_android_soname(self):
|
||||
"""
|
||||
Enforce SONAME on Android
|
||||
"""
|
||||
if self.env.DEST_OS != 'android':
|
||||
return
|
||||
|
||||
setattr(self, 'vnum', None) # remove vnum, so SONAME would not be overwritten
|
||||
link = self.link_task
|
||||
node = link.outputs[0]
|
||||
libname = node.name
|
||||
v = self.env.SONAME_ST % libname
|
||||
self.env.append_value('LINKFLAGS', v.split())
|
175
waf
vendored
Executable file
175
waf
vendored
Executable file
File diff suppressed because one or more lines are too long
252
wscript
Normal file
252
wscript
Normal file
@ -0,0 +1,252 @@
|
||||
#! /usr/bin/env python
|
||||
# encoding: utf-8
|
||||
# a1batross, mittorn, 2018
|
||||
|
||||
from waflib import Build, Configure, Context, Logs
|
||||
import sys
|
||||
import os
|
||||
import re
|
||||
|
||||
VERSION = '2.4'
|
||||
APPNAME = 'hlsdk-portable'
|
||||
top = '.'
|
||||
default_prefix = '/'
|
||||
|
||||
Context.Context.line_just = 60 # should fit for everything on 80x26
|
||||
|
||||
@Configure.conf
|
||||
def get_taskgen_count(self):
|
||||
try: idx = self.tg_idx_count
|
||||
except: idx = 0 # don't set tg_idx_count to not increase counter
|
||||
return idx
|
||||
|
||||
def options(opt):
|
||||
opt.load('reconfigure compiler_optimizations xcompile compiler_cxx compiler_c clang_compilation_database strip_on_install msdev msvs msvc subproject')
|
||||
|
||||
grp = opt.add_option_group('Common options')
|
||||
|
||||
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
|
||||
help = 'allow targetting 64-bit engine(Linux/Windows/OSX x86 only) [default: %default]')
|
||||
grp.add_option('--disable-werror', action = 'store_true', dest = 'DISABLE_WERROR', default = False,
|
||||
help = 'disable compilation abort on warning')
|
||||
grp.add_option('--enable-voicemgr', action = 'store_true', dest = 'USE_VOICEMGR', default = False,
|
||||
help = 'Enable VOICE MANAGER')
|
||||
|
||||
opt.add_subproject('dlls')
|
||||
opt.add_subproject('cl_dll')
|
||||
|
||||
def configure(conf):
|
||||
conf.load('fwgslib reconfigure compiler_optimizations')
|
||||
conf.env.MSVC_TARGETS = ['x86' if not conf.options.ALLOW64 else 'x64']
|
||||
|
||||
# Force XP compatibility, all build targets should add subsystem=bld.env.MSVC_SUBSYSTEM
|
||||
if conf.env.MSVC_TARGETS[0] == 'x86':
|
||||
conf.env.MSVC_SUBSYSTEM = 'WINDOWS,5.01'
|
||||
else:
|
||||
conf.env.MSVC_SUBSYSTEM = 'WINDOWS'
|
||||
|
||||
# Load compilers early
|
||||
conf.load('xcompile compiler_c compiler_cxx')
|
||||
|
||||
# HACKHACK: override msvc DEST_CPU value by something that we understand
|
||||
if conf.env.DEST_CPU == 'amd64':
|
||||
conf.env.DEST_CPU = 'x86_64'
|
||||
|
||||
if conf.env.COMPILER_CC == 'msvc':
|
||||
conf.load('msvc_pdb')
|
||||
|
||||
conf.load('msvs msdev subproject clang_compilation_database strip_on_install enforce_pic')
|
||||
|
||||
enforce_pic = True # modern defaults
|
||||
conf.check_pic(enforce_pic)
|
||||
|
||||
# We restrict 64-bit builds ONLY for Win/Linux/OSX running on Intel architecture
|
||||
# Because compatibility with original GoldSrc
|
||||
if conf.env.DEST_OS in ['win32', 'linux', 'darwin'] and conf.env.DEST_CPU == 'x86_64':
|
||||
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64
|
||||
if conf.env.BIT32_MANDATORY:
|
||||
Logs.info('WARNING: will build game for 32-bit target')
|
||||
else:
|
||||
conf.env.BIT32_MANDATORY = False
|
||||
|
||||
conf.load('force_32bit')
|
||||
|
||||
cflags, linkflags = conf.get_optimization_flags()
|
||||
cxxflags = list(cflags) # optimization flags are common between C and C++ but we need a copy
|
||||
|
||||
# on the Switch, allow undefined symbols by default, which is needed for libsolder to work
|
||||
# we'll specifically disallow them for the engine executable
|
||||
# additionally, shared libs are linked without standard libs, we'll add those back in the engine wscript
|
||||
if conf.env.DEST_OS == 'nswitch':
|
||||
linkflags.remove('-Wl,--no-undefined')
|
||||
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-nostartfiles'])
|
||||
conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-nostartfiles'])
|
||||
# same on the vita
|
||||
elif conf.env.DEST_OS == 'psvita':
|
||||
conf.env.append_unique('CFLAGS_cshlib', ['-fPIC'])
|
||||
conf.env.append_unique('CXXFLAGS_cxxshlib', ['-fPIC', '-fno-use-cxa-atexit'])
|
||||
conf.env.append_unique('LINKFLAGS_cshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all'])
|
||||
conf.env.append_unique('LINKFLAGS_cxxshlib', ['-nostdlib', '-Wl,--unresolved-symbols=ignore-all'])
|
||||
# check if we need to use irix linkflags
|
||||
elif conf.env.DEST_OS == 'irix' and conf.env.COMPILER_CC == 'gcc':
|
||||
linkflags.remove('-Wl,--no-undefined')
|
||||
linkflags.append('-Wl,--unresolved-symbols=ignore-all')
|
||||
# check if we're in a sgug environment
|
||||
if 'sgug' in os.environ['LD_LIBRARYN32_PATH']:
|
||||
linkflags.append('-lc')
|
||||
|
||||
conf.check_cc(cflags=cflags, linkflags=linkflags, msg='Checking for required C flags')
|
||||
conf.check_cxx(cxxflags=cxxflags, linkflags=linkflags, msg='Checking for required C++ flags')
|
||||
|
||||
conf.env.append_unique('CFLAGS', cflags)
|
||||
conf.env.append_unique('CXXFLAGS', cxxflags)
|
||||
conf.env.append_unique('LINKFLAGS', linkflags)
|
||||
|
||||
if conf.env.COMPILER_CC != 'msvc' and not conf.options.DISABLE_WERROR:
|
||||
opt_flags = [
|
||||
# '-Wall', '-Wextra', '-Wpedantic',
|
||||
'-fdiagnostics-color=always',
|
||||
|
||||
# stable diagnostics, forced to error, sorted
|
||||
'-Werror=bool-compare',
|
||||
'-Werror=bool-operation',
|
||||
'-Werror=cast-align=strict',
|
||||
'-Werror=duplicated-cond',
|
||||
# '-Werror=format=2',
|
||||
'-Werror=implicit-fallthrough=2',
|
||||
# '-Werror=logical-op',
|
||||
'-Werror=packed',
|
||||
'-Werror=packed-not-aligned',
|
||||
'-Werror=parentheses',
|
||||
'-Werror=return-type',
|
||||
'-Werror=sequence-point',
|
||||
'-Werror=sizeof-pointer-memaccess',
|
||||
'-Werror=sizeof-array-div',
|
||||
'-Werror=sizeof-pointer-div',
|
||||
# '-Werror=strict-aliasing',
|
||||
'-Werror=string-compare',
|
||||
'-Werror=tautological-compare',
|
||||
'-Werror=use-after-free=3',
|
||||
'-Werror=vla',
|
||||
'-Werror=write-strings',
|
||||
|
||||
# unstable diagnostics, may cause false positives
|
||||
'-Winit-self',
|
||||
'-Wmisleading-indentation',
|
||||
'-Wunintialized',
|
||||
|
||||
# disabled, flood
|
||||
# '-Wdouble-promotion',
|
||||
]
|
||||
|
||||
opt_cflags = [
|
||||
'-Werror=declaration-after-statement',
|
||||
'-Werror=enum-conversion',
|
||||
'-Werror=implicit-int',
|
||||
'-Werror=implicit-function-declaration',
|
||||
'-Werror=incompatible-pointer-types',
|
||||
'-Werror=int-conversion',
|
||||
'-Werror=jump-misses-init',
|
||||
# '-Werror=old-style-declaration',
|
||||
# '-Werror=old-style-definition',
|
||||
# '-Werror=strict-prototypes',
|
||||
'-fnonconst-initializers' # owcc
|
||||
]
|
||||
|
||||
opt_cxxflags = [] # TODO:
|
||||
|
||||
cflags = conf.filter_cflags(opt_flags + opt_cflags, cflags)
|
||||
cxxflags = conf.filter_cxxflags(opt_flags + opt_cxxflags, cxxflags)
|
||||
|
||||
conf.env.append_unique('CFLAGS', cflags)
|
||||
conf.env.append_unique('CXXFLAGS', cxxflags)
|
||||
|
||||
if conf.env.DEST_OS == 'android':
|
||||
# LIB_M added in xcompile!
|
||||
pass
|
||||
elif conf.env.DEST_OS == 'win32':
|
||||
a = [ 'user32', 'winmm' ]
|
||||
if conf.env.COMPILER_CC == 'msvc':
|
||||
for i in a:
|
||||
conf.start_msg('Checking for MSVC library')
|
||||
conf.check_lib_msvc(i)
|
||||
conf.end_msg(i)
|
||||
else:
|
||||
for i in a:
|
||||
conf.check_cc(lib = i)
|
||||
else:
|
||||
if conf.env.GOLDSOURCE_SUPPORT:
|
||||
conf.check_cc(lib='dl')
|
||||
conf.check_cc(lib='m')
|
||||
|
||||
# check if we can use C99 tgmath
|
||||
if conf.check_cc(header_name='tgmath.h', mandatory=False):
|
||||
if conf.env.COMPILER_CC == 'msvc':
|
||||
conf.define('_CRT_SILENCE_NONCONFORMING_TGMATH_H', 1)
|
||||
tgmath_usable = conf.check_cc(fragment='''#include<tgmath.h>
|
||||
const float val = 2, val2 = 3;
|
||||
int main(void){ return (int)(-asin(val) + cos(val2)); }''',
|
||||
msg='Checking if tgmath.h is usable', mandatory=False, use='M')
|
||||
conf.define_cond('HAVE_TGMATH_H', tgmath_usable)
|
||||
else:
|
||||
conf.undefine('HAVE_TGMATH_H')
|
||||
cmath_usable = conf.check_cxx(fragment='''#include<cmath>
|
||||
int main(void){ return (int)sqrt(2.0f); }''',
|
||||
msg='Checking if cmath is usable', mandatory = False)
|
||||
conf.define_cond('HAVE_CMATH', cmath_usable)
|
||||
|
||||
if conf.env.COMPILER_CC == 'msvc':
|
||||
conf.define('_CRT_SECURE_NO_WARNINGS', True)
|
||||
conf.define('_CRT_NONSTDC_NO_DEPRECATE', True)
|
||||
elif conf.env.COMPILER_CC == 'owcc':
|
||||
pass
|
||||
else:
|
||||
conf.env.append_unique('CXXFLAGS', ['-Wno-invalid-offsetof', '-fno-exceptions'])
|
||||
conf.define('stricmp', 'strcasecmp', quote=False)
|
||||
conf.define('strnicmp', 'strncasecmp', quote=False)
|
||||
conf.define('_snprintf', 'snprintf', quote=False)
|
||||
conf.define('_vsnprintf', 'vsnprintf', quote=False)
|
||||
conf.define('_LINUX', True)
|
||||
conf.define('LINUX', True)
|
||||
|
||||
conf.msg(msg='-> processing mod options', result='...', color='BLUE')
|
||||
regex = re.compile('^([A-Za-z0-9_]+)=([A-Za-z0-9_]+)\ \#\ (.*)$')
|
||||
with open('mod_options.txt') as fd:
|
||||
lines = fd.readlines()
|
||||
for line in lines:
|
||||
m = regex.match(line.strip())
|
||||
if m:
|
||||
p = m.groups()
|
||||
conf.start_msg("* " + p[2])
|
||||
if p[1] == 'ON':
|
||||
conf.env[p[0]] = True
|
||||
conf.define(p[0], 1)
|
||||
elif p[1] == 'OFF':
|
||||
conf.env[p[0]] = False
|
||||
conf.undefine(p[0])
|
||||
else:
|
||||
conf.env[p[0]] = p[1]
|
||||
conf.end_msg(p[1])
|
||||
if conf.env.HLDEMO_BUILD and conf.env.OEM_BUILD:
|
||||
conf.fatal('Don\'t mix Demo and OEM builds!')
|
||||
|
||||
# strip lib from pattern
|
||||
if conf.env.DEST_OS not in ['android']:
|
||||
if conf.env.cxxshlib_PATTERN.startswith('lib'):
|
||||
conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:]
|
||||
|
||||
conf.load('library_naming')
|
||||
conf.add_subproject('dlls')
|
||||
conf.add_subproject('cl_dll')
|
||||
|
||||
def build(bld):
|
||||
if bld.is_install and not bld.options.destdir:
|
||||
bld.fatal('Set the install destination directory using --destdir option')
|
||||
|
||||
# don't clean QtCreator files and reconfigure saved options
|
||||
bld.clean_files = bld.bldnode.ant_glob('**',
|
||||
excl='*.user configuration.py .lock* *conf_check_*/** config.log %s/*' % Build.CACHE_DIR,
|
||||
quiet=True, generator=True)
|
||||
|
||||
bld.add_subproject('dlls')
|
||||
bld.add_subproject('cl_dll')
|
Loading…
Reference in New Issue
Block a user