Browse Source

Merge branch 'master' into bshift

bshift
Andrey Akhmichin 5 years ago
parent
commit
e94226157b
  1. 5
      CMakeLists.txt
  2. 2
      cl_dll/ammo.cpp
  3. 4
      cl_dll/death.cpp
  4. 4
      cl_dll/hud_spectator.cpp
  5. 2
      cl_dll/input.cpp
  6. 2
      cl_dll/wscript
  7. 2
      dlls/animation.cpp
  8. 2
      dlls/bmodels.cpp
  9. 2
      dlls/buttons.cpp
  10. 6
      dlls/doors.cpp
  11. 15
      dlls/h_battery.cpp
  12. 15
      dlls/multiplay_gamerules.cpp
  13. 8
      dlls/nihilanth.cpp
  14. 3
      dlls/plats.cpp
  15. 4
      dlls/player.cpp
  16. 5
      dlls/scripted.cpp
  17. 10
      dlls/sound.cpp
  18. 7
      dlls/subs.cpp
  19. 4
      dlls/teamplay_gamerules.cpp
  20. 6
      dlls/triggers.cpp
  21. 4
      dlls/util.cpp
  22. 2
      dlls/wscript
  23. 49
      scripts/waifulib/strip_on_install.py
  24. 308
      scripts/waifulib/xcompile.py
  25. 17
      waf
  26. 135
      wscript

5
CMakeLists.txt

@ -86,6 +86,11 @@ if(${CMAKE_VERSION} VERSION_LESS "3.0.2")
endmacro() endmacro()
endif() endif()
if(NOT MSVC)
add_compile_options(-Wempty-body) # GCC/Clang flag
add_compile_options(-Wreturn-type) # GCC/Clang flag
endif()
if(BUILD_CLIENT) if(BUILD_CLIENT)
add_subdirectory(cl_dll) add_subdirectory(cl_dll)
endif() endif()

2
cl_dll/ammo.cpp

@ -77,7 +77,7 @@ void WeaponsResource::LoadWeaponSprites( WEAPON *pWeapon )
else else
iRes = 640; iRes = 640;
char sz[128]; char sz[256];
if( !pWeapon ) if( !pWeapon )
return; return;

4
cl_dll/death.cpp

@ -204,7 +204,7 @@ int CHudDeathNotice::MsgFunc_DeathMsg( const char *pszName, int iSize, void *pbu
// Get the Victim's name // Get the Victim's name
const char *victim_name = ""; const char *victim_name = "";
// If victim is -1, the killer killed a specific, non-player object (like a sentrygun) // If victim is -1, the killer killed a specific, non-player object (like a sentrygun)
if( ( (char)victim ) != -1 ) if( ( (signed char)victim ) != -1 )
victim_name = g_PlayerInfoList[victim].name; victim_name = g_PlayerInfoList[victim].name;
if( !victim_name ) if( !victim_name )
{ {
@ -219,7 +219,7 @@ int CHudDeathNotice::MsgFunc_DeathMsg( const char *pszName, int iSize, void *pbu
} }
// Is it a non-player object kill? // Is it a non-player object kill?
if( ( (char)victim ) == -1 ) if( ( (signed char)victim ) == -1 )
{ {
rgDeathNoticeList[i].iNonPlayerKill = TRUE; rgDeathNoticeList[i].iNonPlayerKill = TRUE;

4
cl_dll/hud_spectator.cpp

@ -820,7 +820,7 @@ bool CHudSpectator::IsActivePlayer( cl_entity_t *ent )
bool CHudSpectator::ParseOverviewFile() bool CHudSpectator::ParseOverviewFile()
{ {
char filename[255] = { 0 }; char filename[512] = { 0 };
char levelname[255] = { 0 }; char levelname[255] = { 0 };
char token[1024] = { 0 }; char token[1024] = { 0 };
float height; float height;
@ -842,7 +842,7 @@ bool CHudSpectator::ParseOverviewFile()
m_OverviewData.layersHeights[0] = 0.0f; m_OverviewData.layersHeights[0] = 0.0f;
strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() ); strcpy( m_OverviewData.map, gEngfuncs.pfnGetLevelName() );
if( strlen( m_OverviewData.map ) == 0 ) if( m_OverviewData.map[0] == '\0' )
return false; // not active yet return false; // not active yet
strcpy( levelname, m_OverviewData.map + 5 ); strcpy( levelname, m_OverviewData.map + 5 );

2
cl_dll/input.cpp

@ -169,7 +169,7 @@ int KB_ConvertString( char *in, char **ppout )
*pEnd = '\0'; *pEnd = '\0';
pBinding = NULL; pBinding = NULL;
if( strlen( binding + 1 ) > 0 ) if( binding[1] != '\0' )
{ {
// See if there is a binding for binding? // See if there is a binding for binding?
pBinding = gEngfuncs.Key_LookupBinding( binding + 1 ); pBinding = gEngfuncs.Key_LookupBinding( binding + 1 );

2
cl_dll/wscript

@ -48,7 +48,7 @@ def build(bld):
if bld.env.GOLDSRC: if bld.env.GOLDSRC:
libs += ['DL'] libs += ['DL']
if bld.env.DEST_OS2 not in ['android']: if bld.env.DEST_OS not in ['android']:
install_path = os.path.join(bld.env.GAMEDIR, bld.env.CLIENT_DIR) install_path = os.path.join(bld.env.GAMEDIR, bld.env.CLIENT_DIR)
else: else:
install_path = bld.env.PREFIX install_path = bld.env.PREFIX

2
dlls/animation.cpp

@ -203,7 +203,7 @@ void SequencePrecache( void *pmodel, const char *pSequenceName )
// of it's name if it is. // of it's name if it is.
if( IsSoundEvent( pevent[i].event ) ) if( IsSoundEvent( pevent[i].event ) )
{ {
if( !strlen( pevent[i].options ) ) if( pevent[i].options[0] == '\0' )
{ {
ALERT( at_error, "Bad sound event %d in sequence %s :: %s (sound is \"%s\")\n", pevent[i].event, pstudiohdr->name, pSequenceName, pevent[i].options ); ALERT( at_error, "Bad sound event %d in sequence %s :: %s (sound is \"%s\")\n", pevent[i].event, pstudiohdr->name, pSequenceName, pevent[i].options );
} }

2
dlls/bmodels.cpp

@ -434,7 +434,7 @@ void CFuncRotating::Precache( void )
BOOL NullSound = FALSE; BOOL NullSound = FALSE;
// set up fan sounds // set up fan sounds
if( !FStringNull( pev->message ) && strlen( szSoundFile ) > 0 ) if( !FStringNull( pev->message ) && szSoundFile[0] != '\0' )
{ {
// if a path is set for a wave, use it // if a path is set for a wave, use it
} }

2
dlls/buttons.cpp

@ -694,7 +694,7 @@ CBaseButton::BUTTON_CODE CBaseButton::ButtonResponseToTouch( void )
void CBaseButton::ButtonTouch( CBaseEntity *pOther ) void CBaseButton::ButtonTouch( CBaseEntity *pOther )
{ {
// Ignore touches by anything but players // Ignore touches by anything but players
if( !FClassnameIs( pOther->pev, "player" ) ) if( !pOther->IsPlayer() )
return; return;
m_hActivator = pOther; m_hActivator = pOther;

6
dlls/doors.cpp

@ -520,10 +520,8 @@ void CBaseDoor::Precache( void )
// //
void CBaseDoor::DoorTouch( CBaseEntity *pOther ) void CBaseDoor::DoorTouch( CBaseEntity *pOther )
{ {
entvars_t *pevToucher = pOther->pev;
// Ignore touches by anything but players // Ignore touches by anything but players
if( !FClassnameIs( pevToucher, "player" ) ) if( !pOther->IsPlayer() )
return; return;
// If door has master, and it's not ready to trigger, // If door has master, and it's not ready to trigger,
@ -542,7 +540,7 @@ void CBaseDoor::DoorTouch( CBaseEntity *pOther )
m_hActivator = pOther;// remember who activated the door m_hActivator = pOther;// remember who activated the door
if( DoorActivate()) if( DoorActivate() )
SetTouch( NULL ); // Temporarily disable the touch function, until movement is finished. SetTouch( NULL ); // Temporarily disable the touch function, until movement is finished.
} }

15
dlls/h_battery.cpp

@ -106,8 +106,12 @@ void CRecharge::Precache()
void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value ) void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE useType, float value )
{ {
// Make sure that we have a caller
if( !pActivator )
return;
// if it's not a player, ignore // if it's not a player, ignore
if( !FClassnameIs( pActivator->pev, "player" ) ) if( !pActivator->IsPlayer() )
return; return;
// if there is no juice left, turn it off // if there is no juice left, turn it off
@ -135,16 +139,8 @@ void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use
if( m_flNextCharge >= gpGlobals->time ) if( m_flNextCharge >= gpGlobals->time )
return; return;
// Make sure that we have a caller
if( !pActivator )
return;
m_hActivator = pActivator; m_hActivator = pActivator;
//only recharge the player
if( !m_hActivator->IsPlayer() )
return;
// Play the on sound or the looping charging sound // Play the on sound or the looping charging sound
if( !m_iOn ) if( !m_iOn )
{ {
@ -152,6 +148,7 @@ void CRecharge::Use( CBaseEntity *pActivator, CBaseEntity *pCaller, USE_TYPE use
EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM ); EMIT_SOUND( ENT( pev ), CHAN_ITEM, "items/suitchargeok1.wav", 0.85, ATTN_NORM );
m_flSoundTime = 0.56 + gpGlobals->time; m_flSoundTime = 0.56 + gpGlobals->time;
} }
if( ( m_iOn == 1 ) && ( m_flSoundTime <= gpGlobals->time ) ) if( ( m_iOn == 1 ) && ( m_flSoundTime <= gpGlobals->time ) )
{ {
m_iOn++; m_iOn++;

15
dlls/multiplay_gamerules.cpp

@ -1331,7 +1331,8 @@ int ReloadMapCycleFile( const char *filename, mapcycle_t *cycle )
hasbuffer = 0; hasbuffer = 0;
pFileList = COM_Parse( pFileList ); pFileList = COM_Parse( pFileList );
if( strlen( com_token ) <= 0 )
if( com_token[0] == '\0' )
break; break;
strcpy( szMap, com_token ); strcpy( szMap, com_token );
@ -1340,7 +1341,8 @@ int ReloadMapCycleFile( const char *filename, mapcycle_t *cycle )
if( COM_TokenWaiting( pFileList ) ) if( COM_TokenWaiting( pFileList ) )
{ {
pFileList = COM_Parse( pFileList ); pFileList = COM_Parse( pFileList );
if( strlen( com_token ) > 0 )
if( com_token[0] != '\0' )
{ {
hasbuffer = 1; hasbuffer = 1;
strcpy( szBuffer, com_token ); strcpy( szBuffer, com_token );
@ -1496,7 +1498,8 @@ void ExtractCommandString( char *s, char *szCommand )
*o = 0; *o = 0;
strcat( szCommand, pkey ); strcat( szCommand, pkey );
if( strlen( value ) > 0 )
if( value[0] != '\0' )
{ {
strcat( szCommand, " " ); strcat( szCommand, " " );
strcat( szCommand, value ); strcat( szCommand, value );
@ -1631,13 +1634,15 @@ void CHalfLifeMultiplay::ChangeLevel( void )
{ {
ALERT( at_console, "PLAYER COUNT: min %i max %i current %i\n", minplayers, maxplayers, curplayers ); ALERT( at_console, "PLAYER COUNT: min %i max %i current %i\n", minplayers, maxplayers, curplayers );
} }
if( strlen( szRules ) > 0 )
if( szRules[0] != '\0' )
{ {
ALERT( at_console, "RULES: %s\n", szRules ); ALERT( at_console, "RULES: %s\n", szRules );
} }
CHANGE_LEVEL( szNextMap, NULL ); CHANGE_LEVEL( szNextMap, NULL );
if( strlen( szCommands ) > 0 )
if( szCommands[0] != '\0' )
{ {
SERVER_COMMAND( szCommands ); SERVER_COMMAND( szCommands );
} }

8
dlls/nihilanth.cpp

@ -724,7 +724,7 @@ void CNihilanth::NextActivity()
if( ( pev->health < gSkillData.nihilanthHealth / 2 || m_iActiveSpheres < N_SPHERES / 2 ) && m_hRecharger == 0 && m_iLevel <= 9 ) if( ( pev->health < gSkillData.nihilanthHealth / 2 || m_iActiveSpheres < N_SPHERES / 2 ) && m_hRecharger == 0 && m_iLevel <= 9 )
{ {
char szName[64]; char szName[128];
CBaseEntity *pEnt = NULL; CBaseEntity *pEnt = NULL;
CBaseEntity *pRecharger = NULL; CBaseEntity *pRecharger = NULL;
@ -772,7 +772,7 @@ void CNihilanth::NextActivity()
if( iseq != pev->sequence ) if( iseq != pev->sequence )
{ {
char szText[64]; char szText[128];
sprintf( szText, "%s%d", m_szDrawUse, m_iLevel ); sprintf( szText, "%s%d", m_szDrawUse, m_iLevel );
FireTargets( szText, this, this, USE_ON, 1.0 ); FireTargets( szText, this, this, USE_ON, 1.0 );
@ -820,7 +820,7 @@ void CNihilanth::NextActivity()
} }
else else
{ {
char szText[64]; char szText[128];
sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport ); sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport );
CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText ); CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText );
@ -1100,7 +1100,7 @@ void CNihilanth::HandleAnimEvent( MonsterEvent_t *pEvent )
// prayer // prayer
if( m_hEnemy != 0 ) if( m_hEnemy != 0 )
{ {
char szText[32]; char szText[128];
sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport ); sprintf( szText, "%s%d", m_szTeleportTouch, m_iTeleport );
CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText ); CBaseEntity *pTouch = UTIL_FindEntityByTargetname( NULL, szText );

3
dlls/plats.cpp

@ -358,8 +358,7 @@ void CPlatTrigger::SpawnInsideTrigger( CFuncPlat *pPlatform )
void CPlatTrigger::Touch( CBaseEntity *pOther ) void CPlatTrigger::Touch( CBaseEntity *pOther )
{ {
// Ignore touches by non-players // Ignore touches by non-players
entvars_t *pevToucher = pOther->pev; if( !pOther->IsPlayer() )
if( !FClassnameIs( pevToucher, "player" ) )
return; return;
CFuncPlat *pPlatform = (CFuncPlat*)(CBaseEntity*)m_hPlatform; CFuncPlat *pPlatform = (CFuncPlat*)(CBaseEntity*)m_hPlatform;

4
dlls/player.cpp

@ -2762,7 +2762,7 @@ edict_t *EntSelectSpawnPoint( CBaseEntity *pPlayer )
} }
// If startspot is set, (re)spawn there. // If startspot is set, (re)spawn there.
if( FStringNull( gpGlobals->startspot ) || !strlen(STRING( gpGlobals->startspot ) ) ) if( FStringNull( gpGlobals->startspot ) || (STRING( gpGlobals->startspot ) )[0] == '\0')
{ {
pSpot = UTIL_FindEntityByClassname( NULL, "info_player_start" ); pSpot = UTIL_FindEntityByClassname( NULL, "info_player_start" );
if( !FNullEnt( pSpot ) ) if( !FNullEnt( pSpot ) )
@ -4434,7 +4434,7 @@ void CBasePlayer::DropPlayerItem( char *pszItemName )
return; return;
} }
if( !strlen( pszItemName ) ) if( pszItemName[0] == '\0' )
{ {
// if this string has no length, the client didn't type a name! // if this string has no length, the client didn't type a name!
// assume player wants to drop the active item. // assume player wants to drop the active item.

5
dlls/scripted.cpp

@ -1068,14 +1068,17 @@ BOOL CScriptedSentence::AcceptableSpeaker( CBaseMonster *pMonster )
{ {
if( pev->spawnflags & SF_SENTENCE_FOLLOWERS ) if( pev->spawnflags & SF_SENTENCE_FOLLOWERS )
{ {
if( pMonster->m_hTargetEnt == 0 || !FClassnameIs( pMonster->m_hTargetEnt->pev, "player" ) ) if( pMonster->m_hTargetEnt == 0 || !pMonster->m_hTargetEnt->IsPlayer() )
return FALSE; return FALSE;
} }
BOOL override; BOOL override;
if( pev->spawnflags & SF_SENTENCE_INTERRUPT ) if( pev->spawnflags & SF_SENTENCE_INTERRUPT )
override = TRUE; override = TRUE;
else else
override = FALSE; override = FALSE;
if( pMonster->CanPlaySentence( override ) ) if( pMonster->CanPlaySentence( override ) )
return TRUE; return TRUE;
} }

10
dlls/sound.cpp

@ -184,7 +184,7 @@ void CAmbientGeneric::Spawn( void )
const char *szSoundFile = STRING( pev->message ); const char *szSoundFile = STRING( pev->message );
if( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) if( FStringNull( pev->message ) || szSoundFile[0] == '\0' )
{ {
ALERT( at_error, "EMPTY AMBIENT AT: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z ); ALERT( at_error, "EMPTY AMBIENT AT: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z );
pev->nextthink = gpGlobals->time + 0.1; pev->nextthink = gpGlobals->time + 0.1;
@ -218,7 +218,7 @@ void CAmbientGeneric::Precache( void )
{ {
const char *szSoundFile = STRING( pev->message ); const char *szSoundFile = STRING( pev->message );
if( !FStringNull( pev->message ) && strlen( szSoundFile ) > 1 ) if( !FStringNull( pev->message ) && szSoundFile[0] != '\0' )
{ {
if( *szSoundFile != '!' ) if( *szSoundFile != '!' )
PRECACHE_SOUND( szSoundFile ); PRECACHE_SOUND( szSoundFile );
@ -1281,9 +1281,9 @@ void SENTENCEG_Init()
if( !buffer[j] ) if( !buffer[j] )
continue; continue;
if( gcallsentences > CVOXFILESENTENCEMAX ) if( gcallsentences >= CVOXFILESENTENCEMAX )
{ {
ALERT( at_error, "Too many sentences in sentences.txt!\n" ); ALERT( at_error, "Too many sentences in sentences.txt! >%d\n", gcallsentences );
break; break;
} }
@ -1732,7 +1732,7 @@ void CSpeaker::Spawn( void )
{ {
const char *szSoundFile = STRING( pev->message ); const char *szSoundFile = STRING( pev->message );
if( !m_preset && ( FStringNull( pev->message ) || strlen( szSoundFile ) < 1 ) ) if( !m_preset && ( FStringNull( pev->message ) || szSoundFile[0] == '\0' ) )
{ {
ALERT( at_error, "SPEAKER with no Level/Sentence! at: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z ); ALERT( at_error, "SPEAKER with no Level/Sentence! at: %f, %f, %f\n", pev->origin.x, pev->origin.y, pev->origin.z );
pev->nextthink = gpGlobals->time + 0.1; pev->nextthink = gpGlobals->time + 0.1;

7
dlls/subs.cpp

@ -107,13 +107,6 @@ void CBaseEntity::UpdateOnRemove( void )
if( pev->globalname ) if( pev->globalname )
gGlobalState.EntitySetState( pev->globalname, GLOBAL_DEAD ); gGlobalState.EntitySetState( pev->globalname, GLOBAL_DEAD );
// tell owner ( if any ) that we're dead.This is mostly for MonsterMaker functionality.
//Killtarget didn't do this before, so the counter broke. - Solokiller
if( CBaseEntity* pOwner = pev->owner ? Instance( pev->owner ) : 0 )
{
pOwner->DeathNotice( pev );
}
} }
// Convenient way to delay removing oneself // Convenient way to delay removing oneself

4
dlls/teamplay_gamerules.cpp

@ -52,14 +52,14 @@ CHalfLifeTeamplay::CHalfLifeTeamplay()
if( teamoverride.value ) if( teamoverride.value )
{ {
const char *pTeamList = STRING( pWorld->v.team ); const char *pTeamList = STRING( pWorld->v.team );
if( pTeamList && strlen( pTeamList ) ) if( pTeamList && pTeamList[0] != '\0' )
{ {
strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH ); strncpy( m_szTeamList, pTeamList, TEAMPLAY_TEAMLISTLENGTH );
} }
} }
} }
// Has the server set teams // Has the server set teams
if( strlen( m_szTeamList ) ) if( m_szTeamList[0] != '\0' )
m_teamLimit = TRUE; m_teamLimit = TRUE;
else else
m_teamLimit = FALSE; m_teamLimit = FALSE;

6
dlls/triggers.cpp

@ -1124,7 +1124,7 @@ void CBaseTrigger::ActivateMultiTrigger( CBaseEntity *pActivator )
if( pev->nextthink > gpGlobals->time ) if( pev->nextthink > gpGlobals->time )
return; // still waiting for reset time return; // still waiting for reset time
if( !UTIL_IsMasterTriggered( m_sMaster,pActivator ) ) if( !UTIL_IsMasterTriggered( m_sMaster, pActivator ) )
return; return;
if( FClassnameIs( pev, "trigger_secret" ) ) if( FClassnameIs( pev, "trigger_secret" ) )
@ -1191,7 +1191,7 @@ void CBaseTrigger::CounterUse( CBaseEntity *pActivator, CBaseEntity *pCaller, US
BOOL fTellActivator = BOOL fTellActivator =
( m_hActivator != 0 ) && ( m_hActivator != 0 ) &&
FClassnameIs( m_hActivator->pev, "player" ) && m_hActivator->IsPlayer() &&
!FBitSet( pev->spawnflags, SPAWNFLAG_NOMESSAGE ); !FBitSet( pev->spawnflags, SPAWNFLAG_NOMESSAGE );
if( m_cTriggersLeft != 0 ) if( m_cTriggersLeft != 0 )
{ {
@ -1499,7 +1499,7 @@ void CChangeLevel::ChangeLevelNow( CBaseEntity *pActivator )
// //
void CChangeLevel::TouchChangeLevel( CBaseEntity *pOther ) void CChangeLevel::TouchChangeLevel( CBaseEntity *pOther )
{ {
if( !FClassnameIs( pOther->pev, "player" ) ) if( !pOther->IsPlayer() )
return; return;
ChangeLevelNow( pOther ); ChangeLevelNow( pOther );

4
dlls/util.cpp

@ -2196,7 +2196,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou
pString++; pString++;
} }
pInputData = pString; pInputData = pString;
if( strlen( (char *)pInputData ) == 0 ) if( ( (char *)pInputData )[0] == '\0' )
*( (string_t *)pOutputData ) = 0; *( (string_t *)pOutputData ) = 0;
else else
{ {
@ -2291,7 +2291,7 @@ int CRestore::ReadField( void *pBaseData, TYPEDESCRIPTION *pFields, int fieldCou
*( (void**)pOutputData ) = *(void **)pInputData; *( (void**)pOutputData ) = *(void **)pInputData;
break; break;
case FIELD_FUNCTION: case FIELD_FUNCTION:
if( strlen( (char *)pInputData ) == 0 ) if( ( (char *)pInputData )[0] == '\0' )
*( (void**)pOutputData ) = 0; *( (void**)pOutputData ) = 0;
else else
*( (void**)pOutputData ) = (void*)FUNCTION_FROM_NAME( (char *)pInputData ); *( (void**)pOutputData ) = (void*)FUNCTION_FROM_NAME( (char *)pInputData );

2
dlls/wscript

@ -54,7 +54,7 @@ def build(bld):
libs = [] libs = []
if bld.env.DEST_OS2 not in ['android']: if bld.env.DEST_OS not in ['android']:
install_path = os.path.join(bld.env.GAMEDIR, bld.env.SERVER_DIR) install_path = os.path.join(bld.env.GAMEDIR, bld.env.SERVER_DIR)
else: else:
install_path = bld.env.PREFIX install_path = bld.env.PREFIX

49
scripts/waifulib/strip_on_install.py

@ -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

308
scripts/waifulib/xcompile.py

@ -13,27 +13,27 @@
try: from fwgslib import get_flags_by_compiler try: from fwgslib import get_flags_by_compiler
except: from waflib.extras.fwgslib import get_flags_by_compiler except: from waflib.extras.fwgslib import get_flags_by_compiler
from waflib import Logs from waflib import Logs, TaskGen
from waflib.Tools import c_config
from collections import OrderedDict
import os import os
import sys import sys
# Output: ANDROID_NDK_ENVVARS = ['ANDROID_NDK_HOME', 'ANDROID_NDK']
# CROSSCOMPILING -- set to true, if crosscompiling is enabled ANDROID_NDK_SUPPORTED = [10, 19, 20]
# DEST_OS2 -- as some operating systems is built on top of another, it's better to not change DEST_OS, ANDROID_NDK_HARDFP_MAX = 11 # latest version that supports hardfp
# instead of this DEST_OS2 is defined with target value ANDROID_NDK_GCC_MAX = 17 # latest NDK that ships with GCC
# For example: android is built on top of linux and have many things in common, ANDROID_NDK_UNIFIED_SYSROOT_MIN = 15
# but it can't be considered as default GNU/Linux. ANDROID_NDK_SYSROOT_FLAG_MAX = 19 # latest NDK that need --sysroot flag
# Possible values: ANDROID_NDK_API_MIN = { 10: 3, 19: 16, 20: 16 } # minimal API level ndk revision supports
# DEST_OS2 DEST_OS ANDROID_64BIT_API_MIN = 21 # minimal API level that supports 64-bit targets
# 'android' 'linux'
# This class does support ONLY r10e and r19c/r20 NDK
# This class does support ONLY r10e and r19c NDK
class Android: class Android:
ctx = None # waf context ctx = None # waf context
arch = None arch = None
toolchain = None toolchain = None
api = None api = None
toolchain_path = None
ndk_home = None ndk_home = None
ndk_rev = 0 ndk_rev = 0
is_hardfloat = False is_hardfloat = False
@ -41,13 +41,17 @@ class Android:
def __init__(self, ctx, arch, toolchain, api): def __init__(self, ctx, arch, toolchain, api):
self.ctx = ctx self.ctx = ctx
for i in ['ANDROID_NDK_HOME', 'ANDROID_NDK']: self.api = api
self.toolchain = toolchain
self.arch = arch
for i in ANDROID_NDK_ENVVARS:
self.ndk_home = os.getenv(i) self.ndk_home = os.getenv(i)
if self.ndk_home != None: if self.ndk_home != None:
break break
else:
if not self.ndk_home: ctx.fatal('Set %s environment variable pointing to the root of Android NDK!' %
conf.fatal('Set ANDROID_NDK_HOME environment variable pointing to the root of Android NDK!') ' or '.join(ANDROID_NDK_ENVVARS))
# TODO: this were added at some point of NDK development # TODO: this were added at some point of NDK development
# but I don't know at which version # but I don't know at which version
@ -61,37 +65,35 @@ class Android:
if 'Pkg.Revision' in trimed_tokens: if 'Pkg.Revision' in trimed_tokens:
self.ndk_rev = int(trimed_tokens[1].split('.')[0]) 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: else:
self.ndk_rev = 10 self.ndk_rev = ANDROID_NDK_SUPPORTED[0]
if self.ndk_rev not in [10, 19, 20]: if 'clang' in self.toolchain or self.ndk_rev > ANDROID_NDK_GCC_MAX:
ctx.fatal('Unknown NDK revision: {}'.format(self.ndk_rev)) self.clang = True
self.arch = arch
if self.arch == 'armeabi-v7a-hard': if self.arch == 'armeabi-v7a-hard':
if self.ndk_rev <= 10: if self.ndk_rev <= ANDROID_NDK_HARDFP_MAX:
self.arch = 'armeabi-v7a' # Only armeabi-v7a have hard float ABI self.arch = 'armeabi-v7a' # Only armeabi-v7a have hard float ABI
self.is_hardfloat = True self.is_hardfloat = True
else: else:
raise Exception('NDK does not support hardfloat ABI') ctx.fatal('NDK does not support hardfloat ABI')
self.toolchain = toolchain if self.api < ANDROID_NDK_API_MIN[self.ndk_rev]:
self.api = ANDROID_NDK_API_MIN[self.ndk_rev]
if self.ndk_rev >= 19 or 'clang' in self.toolchain: Logs.warn('API level automatically was set to %d due to NDK support' % self.api)
self.clang = True
if self.is_arm64() or self.is_amd64() and self.api < 21: if self.is_arm64() or self.is_amd64() and self.api < ANDROID_64BIT_API_MIN:
Logs.warn('API level for 64-bit target automatically was set to 21') self.api = ANDROID_64BIT_API_MIN
self.api = 21 Logs.warn('API level for 64-bit target automatically was set to %d' % self.api)
elif self.ndk_rev >= 19 and self.api < 16:
Logs.warn('API level automatically was set to 16 due to NDK support')
self.api = 16
else: self.api = api
self.toolchain_path = self.gen_toolchain_path()
# TODO: Crystax support? def is_host(self):
# TODO: Support for everything else than linux-x86_64? '''
# TODO: Determine if I actually need to implement listed above Checks if we using host compiler(implies clang)
'''
return self.toolchain == 'host'
def is_arm(self): def is_arm(self):
''' '''
@ -126,90 +128,146 @@ class Android:
def is_hardfp(self): def is_hardfp(self):
return self.is_hardfloat return self.is_hardfloat
def gen_toolchain_path(self): def ndk_triplet(self, llvm_toolchain = False, toolchain_folder = False):
path = 'toolchains' 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'
if sys.platform.startswith('linux'): def apk_arch(self):
toolchain_host = 'linux' if self.is_arm64():
elif sys.platform.startswith('darwin'): return 'arm64-v8a'
toolchain_host = 'darwin' return self.arch
elif sys.platform.startswith('win32') or sys.platform.startswith('cygwin'):
toolchain_host = 'windows' def gen_host_toolchain(self):
else: raise Exception('Unsupported by NDK host platform') # With host toolchain we don't care about OS
# so just download NDK for Linux x86_64
if self.is_host():
return 'linux-x86_64'
toolchain_host += '-' 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')
# Assuming we are building on x86
if sys.maxsize > 2**32: if sys.maxsize > 2**32:
toolchain_host += 'x86_64' arch = 'x86_64'
else: toolchain_host += 'x86' else: arch = 'x86'
if self.is_clang(): return '%s-%s' % (osname, arch)
if self.ndk_rev < 19:
raise Exception('Clang is not supported for this NDK')
toolchain_folder = 'llvm' def gen_gcc_toolchain_path(self):
path = 'toolchains'
toolchain_host = self.gen_host_toolchain()
if self.is_x86(): if self.is_clang():
triplet = 'i686-linux-android{}-'.format(self.api) toolchain_folder = 'llvm'
elif self.is_arm():
triplet = 'armv7a-linux-androideabi{}-'.format(self.api)
else:
triplet = self.arch + '-linux-android{}-'.format(self.api)
else: else:
if self.is_x86() or self.is_amd64(): if self.is_host():
toolchain_folder = self.arch + '-' + self.toolchain toolchain = '4.9'
elif self.is_arm():
toolchain_folder = 'arm-linux-androideabi-' + self.toolchain
else: else:
toolchain_folder = self.arch + '-linux-android-' + self.toolchain toolchain = self.toolchain
if self.is_x86(): toolchain_folder = '%s-%s' % (self.ndk_triplet(toolchain_folder = True), toolchain)
triplet = 'i686-linux-android-'
elif self.is_arm(): return os.path.abspath(os.path.join(self.ndk_home, path, toolchain_folder, 'prebuilt', toolchain_host))
triplet = 'arm-linux-androideabi-'
def gen_toolchain_path(self):
if self.is_clang():
triplet = '%s%d-' % (self.ndk_triplet(llvm_toolchain = True), self.api)
else: else:
triplet = self.arch + '-linux-android-' triplet = self.ndk_triplet() + '-'
return os.path.join(self.gen_gcc_toolchain_path(), 'bin', triplet)
return os.path.join(path, toolchain_folder, 'prebuilt', toolchain_host, 'bin', triplet) def gen_binutils_path(self):
return os.path.join(self.gen_gcc_toolchain_path(), self.ndk_triplet(), 'bin')
def cc(self): def cc(self):
return os.path.abspath(os.path.join(self.ndk_home, self.toolchain_path + ('clang' if self.is_clang() else 'gcc'))) if self.is_host():
return 'clang --target=%s%d' % (self.ndk_triplet(), self.api)
return self.gen_toolchain_path() + ('clang' if self.is_clang() else 'gcc')
def cxx(self): def cxx(self):
return os.path.abspath(os.path.join(self.ndk_home, self.toolchain_path + ('clang++' if self.is_clang() else 'g++'))) if self.is_host():
return 'clang++ --target=%s%d' % (self.ndk_triplet(), self.api)
return self.gen_toolchain_path() + ('clang++' if self.is_clang() else 'g++')
def strip(self):
if self.is_host():
return 'llvm-strip'
return os.path.join(self.gen_binutils_path(), 'strip')
def system_stl(self): def system_stl(self):
# TODO: proper STL support # TODO: proper STL support
return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include')) return os.path.abspath(os.path.join(self.ndk_home, 'sources', 'cxx-stl', 'system', 'include'))
def sysroot(self): def libsysroot(self):
if self.ndk_rev >= 19:
return os.path.abspath(os.path.join(self.ndk_home, 'sysroot'))
else:
arch = self.arch arch = self.arch
if self.is_arm(): if self.is_arm():
arch = 'arm' arch = 'arm'
elif self.is_arm64(): elif self.is_arm64():
arch = 'arm64' arch = 'arm64'
path = 'platforms/android-{}/arch-{}'.format(self.api, arch) path = 'platforms/android-%s/arch-%s' % (self.api, arch)
return os.path.abspath(os.path.join(self.ndk_home, path)) return os.path.abspath(os.path.join(self.ndk_home, path))
def cflags(self): 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 = [] cflags = []
if self.ndk_rev < 20:
cflags = ['--sysroot={0}'.format(self.sysroot())] if self.ndk_rev <= ANDROID_NDK_SYSROOT_FLAG_MAX:
cflags += ['-DANDROID', '-D__ANDROID__'] cflags += ['--sysroot=%s' % (self.sysroot())]
cflags += ['-I{0}'.format(self.system_stl())] 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()), '-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_arm(): if self.is_arm():
if self.arch == 'armeabi-v7a': if self.arch == 'armeabi-v7a':
# ARMv7 support # ARMv7 support
cflags += ['-mthumb', '-mfpu=neon', '-mcpu=cortex-a9', '-DHAVE_EFFICIENT_UNALIGNED_ACCESS', '-DVECTORIZE_SINCOS'] cflags += ['-mthumb', '-mfpu=neon', '-mcpu=cortex-a9', '-DHAVE_EFFICIENT_UNALIGNED_ACCESS', '-DVECTORIZE_SINCOS']
if not self.is_clang():
if not self.is_clang() and not self.is_host():
cflags += [ '-mvectorize-with-neon-quad' ] cflags += [ '-mvectorize-with-neon-quad' ]
if self.is_hardfloat:
cflags += ['-D_NDK_MATH_NO_SOFTFP=1', '-mhard-float', '-mfloat-abi=hard', '-DLOAD_HARDFP', '-DSOFTFP_LINK'] 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: else:
cflags += ['-mfloat-abi=softfp'] cflags += ['-mfloat-abi=softfp']
else: else:
@ -222,16 +280,32 @@ class Android:
# they go before object list # they go before object list
def linkflags(self): def linkflags(self):
linkflags = [] linkflags = []
if self.ndk_rev < 20: if self.is_host():
linkflags = ['--sysroot={0}'.format(self.sysroot())] 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']
linkflags += ['-Wl,--hash-style=both','-Wl,--no-undefined']
return linkflags return linkflags
def ldflags(self): def ldflags(self):
ldflags = ['-lgcc', '-no-canonical-prefixes'] ldflags = ['-lgcc', '-no-canonical-prefixes']
if self.is_clang() or self.is_host():
ldflags += ['-stdlib=libstdc++']
if self.is_arm(): if self.is_arm():
if self.arch == 'armeabi-v7a': if self.arch == 'armeabi-v7a':
ldflags += ['-march=armv7-a', '-Wl,--fix-cortex-a8', '-mthumb'] ldflags += ['-march=armv7-a', '-mthumb']
if self.is_hardfloat:
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'] ldflags += ['-Wl,--no-warn-mismatch', '-lm_hard']
else: else:
ldflags += ['-march=armv5te'] ldflags += ['-march=armv5te']
@ -248,17 +322,17 @@ def configure(conf):
if len(values) != 3: if len(values) != 3:
conf.fatal('Invalid --android paramater value!') conf.fatal('Invalid --android paramater value!')
valid_archs = ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'aarch64', 'mipsel', 'mips64el'] valid_archs = ['x86', 'x86_64', 'armeabi', 'armeabi-v7a', 'armeabi-v7a-hard', 'aarch64']
if values[0] not in valid_archs: if values[0] not in valid_archs:
conf.fatal('Unknown arch: {}. Supported: {}'.format(values[0], ', '.join(valid_archs))) conf.fatal('Unknown arch: %s. Supported: %r' % (values[0], ', '.join(valid_archs)))
android = Android(conf, values[0], values[1], int(values[2])) conf.android = android = Android(conf, values[0], values[1], int(values[2]))
setattr(conf, 'android', android)
conf.environ['CC'] = android.cc() conf.environ['CC'] = android.cc()
conf.environ['CXX'] = android.cxx() conf.environ['CXX'] = android.cxx()
conf.environ['STRIP'] = android.strip()
conf.env.CFLAGS += android.cflags() conf.env.CFLAGS += android.cflags()
conf.env.CXXFLAGS += android.cflags() conf.env.CXXFLAGS += android.cflags(True)
conf.env.LINKFLAGS += android.linkflags() conf.env.LINKFLAGS += android.linkflags()
conf.env.LDFLAGS += android.ldflags() conf.env.LDFLAGS += android.ldflags()
@ -267,20 +341,27 @@ def configure(conf):
conf.env.LIB_M = ['m_hard'] conf.env.LIB_M = ['m_hard']
else: conf.env.LIB_M = ['m'] else: conf.env.LIB_M = ['m']
conf.env.PREFIX = '/lib/{}'.format(android.arch) conf.env.PREFIX = '/lib/%s' % android.apk_arch()
conf.msg('Selected Android NDK', '{}, version: {}'.format(android.ndk_home, android.ndk_rev)) 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 # 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('... 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('... link flags', ' '.join(android.linkflags()).replace(android.ndk_home, '$NDK/'))
conf.msg('... ld flags', ' '.join(android.ldflags()).replace(android.ndk_home, '$NDK')) conf.msg('... ld flags', ' '.join(android.ldflags()).replace(android.ndk_home, '$NDK/'))
# conf.env.ANDROID_OPTS = android # conf.env.ANDROID_OPTS = android
conf.env.DEST_OS2 = 'android' conf.env.DEST_OS2 = 'android'
# else:
# conf.load('compiler_c compiler_cxx') # Use host compiler :) MACRO_TO_DESTOS = OrderedDict({ '__ANDROID__' : 'android' })
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): 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.options.ANDROID_OPTS:
if conf.android.ndk_rev == 19: if conf.android.ndk_rev == 19:
conf.env.CXXFLAGS_cxxshlib += ['-static-libstdc++'] conf.env.CXXFLAGS_cxxshlib += ['-static-libstdc++']
@ -288,6 +369,10 @@ def post_compiler_cxx_configure(conf):
return return
def post_compiler_c_configure(conf): 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 return
from waflib.Tools import compiler_cxx, compiler_c from waflib.Tools import compiler_cxx, compiler_c
@ -305,3 +390,20 @@ def patch_compiler_c_configure(conf):
setattr(compiler_cxx, 'configure', patch_compiler_cxx_configure) setattr(compiler_cxx, 'configure', patch_compiler_cxx_configure)
setattr(compiler_c, 'configure', patch_compiler_c_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())

17
waf vendored

File diff suppressed because one or more lines are too long

135
wscript

@ -3,15 +3,16 @@
# a1batross, mittorn, 2018 # a1batross, mittorn, 2018
from __future__ import print_function from __future__ import print_function
from waflib import Logs from waflib import Logs, Context, Configure
import sys import sys
import os import os
sys.path.append(os.path.realpath('scripts/waflib'))
VERSION = '2.4' VERSION = '2.4'
APPNAME = 'hlsdk-xash3d' APPNAME = 'hlsdk-xash3d'
top = '.' top = '.'
Context.Context.line_just = 55 # should fit for everything on 80x26
def options(opt): def options(opt):
grp = opt.add_option_group('Common options') grp = opt.add_option_group('Common options')
@ -19,19 +20,26 @@ def options(opt):
help = 'build type: debug, release or none(custom flags)') help = 'build type: debug, release or none(custom flags)')
grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False, grp.add_option('-8', '--64bits', action = 'store_true', dest = 'ALLOW64', default = False,
help = 'allow targetting 64-bit game dlls') help = 'allow targetting 64-bit engine(Linux/Windows/OSX x86 only) [default: %default]')
grp.add_option('--enable-voicemgr', action = 'store_true', dest = 'VOICEMGR', default = False, grp.add_option('--enable-voicemgr', action = 'store_true', dest = 'VOICEMGR', default = False,
help = 'enable voice manager') help = 'enable voice manager [default: %default]')
grp.add_option('--enable-goldsrc-support', action = 'store_true', dest = 'GOLDSRC', default = False, grp.add_option('--enable-goldsrc-support', action = 'store_true', dest = 'GOLDSRC', default = False,
help = 'enable GoldSource engine support') help = 'enable GoldSource engine support [default: %default]')
grp.add_option('--enable-lto', action = 'store_true', dest = 'LTO', default = False,
help = 'enable Link Time Optimization [default: %default]')
grp.add_option('--enable-poly-opt', action = 'store_true', dest = 'POLLY', default = False,
help = 'enable polyhedral optimization if possible [default: %default]')
opt.recurse('cl_dll dlls') opt.recurse('cl_dll dlls')
opt.load('xcompile compiler_cxx compiler_c') opt.load('xcompile compiler_cxx compiler_c clang_compilation_database strip_on_install')
if sys.platform == 'win32': if sys.platform == 'win32':
opt.load('msvc msdev') opt.load('msvc msdev msvs')
opt.load('reconfigure') opt.load('reconfigure')
@ -43,7 +51,7 @@ def configure(conf):
conf.env.SERVER_NAME = 'hl' conf.env.SERVER_NAME = 'hl'
conf.env.PREFIX = '' conf.env.PREFIX = ''
conf.load('reconfigure') conf.load('fwgslib reconfigure')
conf.start_msg('Build type') conf.start_msg('Build type')
if conf.options.BUILD_TYPE == None: if conf.options.BUILD_TYPE == None:
@ -68,23 +76,22 @@ def configure(conf):
conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC conf.env.MSVC_TARGETS = ['x86'] # explicitly request x86 target for MSVC
if sys.platform == 'win32': if sys.platform == 'win32':
conf.load('msvc msdev') conf.load('msvc msdev')
conf.load('xcompile compiler_c compiler_cxx') conf.load('xcompile compiler_c compiler_cxx strip_on_install')
if conf.env.DEST_OS2 == 'android': if conf.env.DEST_OS == 'android':
conf.options.ALLOW64 = True
conf.options.GOLDSRC = False conf.options.GOLDSRC = False
conf.env.SERVER_NAME = 'server' # can't be any other name, until specified conf.env.SERVER_NAME = 'server' # can't be any other name, until specified
# print(conf.options.ALLOW64) # We restrict 64-bit builds ONLY for Win/Linux/OSX running on Intel architecture
# Because compatibility with original GoldSrc
conf.env.BIT32_MANDATORY = not conf.options.ALLOW64 if conf.env.DEST_OS in ['win32', 'linux', 'darwin'] and conf.env.DEST_CPU in ['x86_64']:
conf.env.BIT32_ALLOW64 = conf.options.ALLOW64 conf.env.BIT32_ALLOW64 = conf.options.ALLOW64
conf.load('force_32bit') if not conf.env.BIT32_ALLOW64:
Logs.info('WARNING: will build engine for 32-bit target')
if conf.env.DEST_SIZEOF_VOID_P == 4:
Logs.info('NOTE: will build game dlls for 32-bit target')
else: else:
Logs.warn('WARNING: 64-bit game dlls may be unstable') conf.env.BIT32_ALLOW64 = True
conf.env.BIT32_MANDATORY = not conf.env.BIT32_ALLOW64
conf.load('force_32bit')
linker_flags = { linker_flags = {
'common': { 'common': {
@ -92,19 +99,22 @@ def configure(conf):
'gcc': ['-Wl,--no-undefined'] 'gcc': ['-Wl,--no-undefined']
}, },
'sanitize': { 'sanitize': {
'clang': ['-fsanitize=undefined', '-fsanitize=address'],
'gcc': ['-fsanitize=undefined', '-fsanitize=address'], 'gcc': ['-fsanitize=undefined', '-fsanitize=address'],
} }
} }
compiler_c_cxx_flags = { compiler_c_cxx_flags = {
'common': { 'common': {
'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS'], # disable thread-safe local static initialization for C++11 code, as it cause crashes on Windows XP
'clang': ['-g', '-gdwarf-2'], 'msvc': ['/D_USING_V110_SDK71_', '/Zi', '/FS', '/Zc:threadSafeInit-', '/MT'],
'gcc': ['-g', '-Werror=implicit-function-declaration', '-fdiagnostics-color=always'] 'clang': ['-g', '-gdwarf-2', '-fvisibility=hidden'],
'gcc': ['-g', '-fvisibility=hidden']
}, },
'fast': { 'fast': {
'msvc': ['/O2', '/Oy'], #todo: check /GL /LTCG 'msvc': ['/O2', '/Oy'], #todo: check /GL /LTCG
'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'], 'gcc': ['-Ofast', '-march=native', '-funsafe-math-optimizations', '-funsafe-loop-optimizations', '-fomit-frame-pointer'],
'clang': ['-Ofast', '-march=native'],
'default': ['-O3'] 'default': ['-O3']
}, },
'release': { 'release': {
@ -119,7 +129,8 @@ def configure(conf):
'sanitize': { 'sanitize': {
'msvc': ['/Od', '/RTC1'], 'msvc': ['/Od', '/RTC1'],
'gcc': ['-Og', '-fsanitize=undefined', '-fsanitize=address'], 'gcc': ['-Og', '-fsanitize=undefined', '-fsanitize=address'],
'default': ['-O1'] 'clang': ['-O0', '-fsanitize=undefined', '-fsanitize=address'],
'default': ['-O0']
}, },
'nooptimize': { 'nooptimize': {
'msvc': ['/Od'], 'msvc': ['/Od'],
@ -127,29 +138,81 @@ def configure(conf):
} }
} }
conf.env.append_unique('CFLAGS', conf.get_flags_by_type( compiler_optional_flags = [
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)) '-fdiagnostics-color=always',
conf.env.append_unique('CXXFLAGS', conf.get_flags_by_type( '-Werror=implicit-function-declaration',
compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)) '-Werror=int-conversion',
conf.env.append_unique('LINKFLAGS', conf.get_flags_by_type( '-Werror=return-type',
linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)) '-Werror=parentheses',
'-Werror=vla',
'-Werror=tautological-compare',
'-Werror=duplicated-cond',
'-Werror=bool-compare',
'-Werror=bool-operation',
'-Wstrict-aliasing',
]
c_compiler_optional_flags = [
'-Werror=implicit-int',
'-Werror=declaration-after-statement'
]
linkflags = conf.get_flags_by_type(linker_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)
cflags = conf.get_flags_by_type(compiler_c_cxx_flags, conf.options.BUILD_TYPE, conf.env.COMPILER_CC)
# Here we don't differentiate C or C++ flags
if conf.options.LTO:
lto_cflags = {
'msvc': ['/GL'],
'gcc': ['-flto'],
'clang': ['-flto']
}
lto_linkflags = {
'msvc': ['/LTCG'],
'gcc': ['-flto'],
'clang': ['-flto']
}
cflags += conf.get_flags_by_compiler(lto_cflags, conf.env.COMPILER_CC)
linkflags += conf.get_flags_by_compiler(lto_linkflags, conf.env.COMPILER_CC)
if conf.options.POLLY:
polly_cflags = {
'gcc': ['-fgraphite-identity'],
'clang': ['-mllvm', '-polly']
# msvc sosat :(
}
cflags += conf.get_flags_by_compiler(polly_cflags, conf.env.COMPILER_CC)
# And here C++ flags starts to be treated separately
cxxflags = list(cflags)
if conf.env.COMPILER_CC != 'msvc':
conf.check_cc(cflags=cflags, msg= 'Checking for required C flags')
conf.check_cxx(cxxflags=cflags, msg= 'Checking for required C++ flags')
cflags += conf.filter_cflags(compiler_optional_flags + c_compiler_optional_flags, cflags)
cxxflags += conf.filter_cxxflags(compiler_optional_flags, cflags)
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cxxflags)
conf.env.append_unique('LINKFLAGS', linkflags)
if conf.env.COMPILER_CC == 'msvc': if conf.env.COMPILER_CC == 'msvc':
conf.env.append_unique('DEFINES', ['_CRT_SECURE_NO_WARNINGS','_CRT_NONSTDC_NO_DEPRECATE']) conf.define('_CRT_SECURE_NO_WARNINGS', 1)
conf.define('_CRT_NONSTDC_NO_DEPRECATE', 1)
else: else:
conf.env.append_unique('DEFINES', ['stricmp=strcasecmp','strnicmp=strncasecmp','_LINUX','LINUX','_snprintf=snprintf','_vsnprintf=vsnprintf']) conf.env.append_unique('DEFINES', ['stricmp=strcasecmp', 'strnicmp=strncasecmp', '_snprintf=snprintf', '_vsnprintf=vsnprintf', '_LINUX', 'LINUX'])
cflags = ['-fvisibility=hidden','-Wno-write-strings'] conf.env.append_unique('CXXFLAGS', ['-Wno-invalid-offsetof', '-fno-rtti', '-fno-exceptions'])
conf.env.append_unique('CFLAGS', cflags)
conf.env.append_unique('CXXFLAGS', cflags + ['-Wno-invalid-offsetof', '-fno-rtti', '-fno-exceptions'])
# strip lib from pattern # strip lib from pattern
if conf.env.DEST_OS in ['linux', 'darwin'] and conf.env.DEST_OS2 not in ['android']: if conf.env.DEST_OS in ['linux', 'darwin']:
if conf.env.cshlib_PATTERN.startswith('lib'): if conf.env.cshlib_PATTERN.startswith('lib'):
conf.env.cshlib_PATTERN = conf.env.cshlib_PATTERN[3:] conf.env.cshlib_PATTERN = conf.env.cshlib_PATTERN[3:]
if conf.env.cxxshlib_PATTERN.startswith('lib'): if conf.env.cxxshlib_PATTERN.startswith('lib'):
conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:] conf.env.cxxshlib_PATTERN = conf.env.cxxshlib_PATTERN[3:]
conf.env.append_unique('DEFINES', 'CLIENT_WEAPONS') conf.define('CLIENT_WEAPONS', '1')
conf.recurse('cl_dll dlls') conf.recurse('cl_dll dlls')

Loading…
Cancel
Save