diff --git a/Documentation/library-naming.md b/Documentation/library-naming.md new file mode 100644 index 00000000..ee3dfa43 --- /dev/null +++ b/Documentation/library-naming.md @@ -0,0 +1,42 @@ +I propose a new library naming scheme, which will allow to distribute mods and games in single archive to different operating systems and CPUs: + +Legend: +* $os -- Q_buildos() return value, in lower case. +* $arch -- Q_buildarch() return value, in lower case. +* $ext -- OS-specific extension: dll, so, dylib, etc. + +The scheme will be: + +1. Client library: +* ```client.$ext``` for **Win/Lin/Mac** with **x86**. +* ```client_$arch.$ext``` for **Win/Lin/Mac** with **NON-x86**. +* ```client_$os_$arch.$ext``` for everything else. + +2. Menu library: +* ```menu.$ext``` for **Win/Lin/Mac** with **x86**. +* ```menu_$arch.$ext``` for **Win/Lin/Mac** with **NON-x86**. +* ```menu_$os_$arch.$ext``` for everything else. + +3. Server library: +* On **Win/Lin/Mac** with **x86**, it **MUST** use the raw gamedll name for corresponding OS field from `gameinfo.txt`. +* On **Win/Lin/Mac** with **NON-x86**, it **MUST** use the raw gamedll name for corresponding OS field from `gameinfo.txt`, but append ```_$arch``` before file extension. Like: ```hl_amd64.so``` or ```cs_e2k.so```. +* On everything else, it must use gamedll name from ```gamedll_linux``` field, but append ```_$os_$arch``` before file extension. Like: ```hl_haiku_amd64.so``` or ```cs_freebsd_armhf.so```. +Why ```gamedll_linux``` and not ```gamedll```? Because it looks more logic that way, most operating systems are *nix-like and share code with Linux, rather than Windows. + +4. Refresh library: not needed, as RefAPI is not stable and it's not intended to distribute with mods. + +For any libraries distributed **with** engine, naming scheme should be used more convenient for OS port. + +Issue #0. Inconsistency between ABI and Q_buildarch. +Resolution: Change Q_buildarch return value to use Debian-styled architectures list: https://www.debian.org/ports/, which includes a special naming for big/little-endian and hard/soft-float ARM. + +Issue #1: Build-system integration. +Resolution: extend MACRO_TO_DEST_CPU and MACRO_TO_DESTOS from Waf: https://gitlab.com/ita1024/waf/blob/master/waflib/Tools/c_config.py#L1002, if needed. + +Issue #2(related to #0): +Which ARM flavours we actually need to handle? +Resolution: Little-endian only, as there is no known big-endian ARM platforms in the wild. +Architecture is coded this way: +* ```armvxy```, where `x` is ARM instruction set level and `y` is hard-float ABI presence: `hf` where hard float ABI used, otherwise `l`. + +See discussion: https://github.com/FWGS/xash3d-fwgs/issues/39 diff --git a/engine/common/lib_common.c b/engine/common/lib_common.c index ed547641..7d953a8e 100644 --- a/engine/common/lib_common.c +++ b/engine/common/lib_common.c @@ -52,3 +52,137 @@ const char *COM_OffsetNameForFunction( void *function ) Con_Reportf( "COM_OffsetNameForFunction %s\n", sname ); return sname; } + +/* +============================================================================= + + LIBRARY NAMING(see Documentation/library-naming.md for more info) + +============================================================================= +*/ + +/* +============== +COM_GenerateClientLibraryName + +Generates platform-unique and compatible name for client libraries +============== +*/ +static void COM_GenerateClientLibraryName( const char *name, char *out, size_t size ) +{ +#ifdef XASH_INTERNAL_GAMELIBS // assuming library loader knows where to get libraries + + Q_strncpy( out, name, size ); + +#elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) && XASH_X86 + + Q_snprintf( out, size, "%s/%s." OS_LIB_EXT, + GI->dll_path, + name ); + +#elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) + + Q_snprintf( out, size, "%s/%s_%s." OS_LIB_EXT, + GI->dll_path, + name, + Q_buildarch() ); + +#else + + Q_snprintf( out, size, "%s/%s_%s_%s." OS_LIB_EXT, + GI->dll_path, + name, + Q_buildos(), + Q_buildarch() ); + +#endif +} + +/* +============== +COM_GenerateClientLibraryName + +Generates platform-unique and compatible name for server library +============== +*/ +static void COM_GenerateServerLibraryName( char *out, size_t size ) +{ +#ifdef XASH_INTERNAL_GAMELIBS // assuming library loader knows where to get libraries + + Q_strncpy( out, "server", size ); + +#elif ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) && XASH_X86 + +#if XASH_WIN32 + Q_strncpy( out, GI->game_dll, size ); +#elif XASH_APPLE + Q_strncpy( out, GI->game_dll_osx, size ); +#else // XASH_LINUX + Q_strncpy( out, GI->game_dll_linux, size ); +#endif + +#else + string dllpath; + char *ext; + +#if XASH_WIN32 + Q_strncpy( dllname, GI->game_dll, sizeof( dllname ) ); +#elif XASH_APPLE + Q_strncpy( dllname, GI->game_dll_osx, sizeof( dllname ) ); +#else // XASH_APPLE + Q_strncpy( dllname, GI->game_dll_linux, sizeof( dllname ) ); +#endif + + ext = COM_FileExtension( dllpath ); + COM_StripExtension( dllpath ); + +#if ( XASH_WIN32 || XASH_LINUX || XASH_APPLE ) + Q_snprintf( out, size, "%s_%s.%s", dllpath, Q_buildarch(), ext ); +#else + Q_snprintf( out, size, "%s_%s_%s.%s", dllpath, Q_buildos(), Q_buildarch(), ext ); +#endif + +#endif +} + + +/* +============== +COM_GetCommonLibraryName + +Generates platform-unique and compatible name for server library +============== +*/ +void COM_GetCommonLibraryName( ECommonLibraryType eLibType, char *out, size_t size ) +{ + switch( eLibType ) + { + case LIBRARY_GAMEUI: + COM_GenerateClientLibraryName( "menu", out, size ); + break; + case LIBRARY_CLIENT: + if( SI.clientlib[0] ) + { + Q_strncpy( out, SI.clientlib, size ); + } + else + { + COM_GenerateClientLibraryName( "client", out, size ); + } + break; + case LIBRARY_SERVER: + if( SI.gamedll[0] ) + { + Q_strncpy( out, SI.gamedll, size ); + } + else + { + COM_GenerateServerLibraryName( out, size ); + } + break; + default: + ASSERT( true ); + out[0] = 0; + break; + } +} diff --git a/engine/common/library.h b/engine/common/library.h index a029a06b..86effcc9 100644 --- a/engine/common/library.h +++ b/engine/common/library.h @@ -48,4 +48,14 @@ qboolean COM_CheckLibraryDirectDependency( const char *name, const char *depname void COM_ResetLibraryError( void ); void COM_PushLibraryError( const char *error ); const char *COM_OffsetNameForFunction( void *function ); + +typedef enum +{ + LIBRARY_CLIENT, + LIBRARY_SERVER, + LIBRARY_GAMEUI +} ECommonLibraryType; + +void COM_GetCommonLibraryName( ECommonLibraryType eLibType, char *out, size_t size ); + #endif//LIBRARY_H