Permalink
Browse files

BUILD: Add partial option for statically linking system libraries

Eventually this should probably also use -static or -Wl,-Bstatic
for non-Darwin platforms. For now, it only does these things:

1. Switches to use --static-libs/--static when getting dependencies
   from the third-party libraries with configuration scripts, since
   this is needed to get the correct -framework flags from SDL2 and
   extra dependencies from FreeType2;
2. Rewrites linker flags from -lfoo to $staticlibpath/lib/libfoo.a,
   since this is required in order to get the Apple linker to do
   static linking whenever there is a shared library available.

This commit changes the recently added --enable-static flag name
since that flag DOES NOT actually generate static builds, it only
changes which dependencies are requested from third party
library configuration scripts.
  • Loading branch information...
csnover authored and ccawley2011 committed Jan 30, 2018
1 parent 103453a commit 2985c5dd1891f7eb503ce0e5c14f725451359bd1
Showing with 28 additions and 4 deletions.
  1. +28 −4 configure
@@ -981,7 +981,6 @@ Game engines:
The values of <engine name> for these options are as follows:
$engines_help
Optional Features:
--enable-static build a static binary instead of using shared objects
--enable-c++11 build as C++11 if the compiler allows that
--disable-debug disable building with debugging symbols
--enable-Werror treat warnings as errors
@@ -991,6 +990,8 @@ Optional Features:
--enable-optimizations enable optimizations
--enable-profiling enable profiling
--enable-plugins enable the support for dynamic plugins
--enable-static-libs use static linking information from system library
configuration scripts
--default-dynamic make plugins dynamic by default
--disable-mt32emu don't enable the integrated MT-32 emulator
--disable-nuked-opl don't build Nuked OPL driver
@@ -1139,7 +1140,8 @@ EOF

for ac_option in $@; do
case "$ac_option" in
--enable-static) _static_build=yes ;;
--enable-static-libs) _static_libs=yes ;;
--disable-static-libs) _static_libs=no ;;
--disable-16bit) _16bit=no ;;
--enable-highres) _highres=yes ;;
--disable-highres) _highres=no ;;
@@ -1376,6 +1378,7 @@ for ac_option in $@; do
_nasmpath="$arg:$arg/bin"
;;
--with-staticlib-prefix=*)
_static_libs=yes
_staticlibpath=`echo $ac_option | cut -d '=' -f 2`
;;
--with-xcodetools-path=*)
@@ -3589,7 +3592,7 @@ case $_backend in
androidsdl | dingux | gph | linuxmoto | maemo | openpandora | samsungtv | sdl)
find_sdlconfig
append_var INCLUDES "`$_sdlconfig --prefix="$_sdlpath" --cflags`"
if test "$_static_build" = yes ; then
if test "$_static_libs" = yes; then
append_var LIBS "`$_sdlconfig --prefix="$_sdlpath" --static-libs`"
else
append_var LIBS "`$_sdlconfig --prefix="$_sdlpath" --libs`"
@@ -4490,7 +4493,7 @@ if test "$_libcurl" != "no"; then
if test -z "$_libcurlconfig"; then
_libcurl=no
else
if test -n "$_staticlibpath"; then
if test "$_static_libs" = yes; then
LIBCURL_LIBS=`$_libcurlconfig --static-libs`
else
LIBCURL_LIBS=`$_libcurlconfig --libs`
@@ -4790,6 +4793,10 @@ if test "$_freetype2" != "no"; then
if test $_freetype_found != true; then
_freetype2=no
else
if test "$_static_libs" = yes; then
FREETYPE2_LIBS="$FREETYPE2_STATIC_LIBS"
fi

if test "$_freetype2" = "auto"; then
_freetype2=no

@@ -5249,6 +5256,23 @@ case $_backend in
;;
esac

# The Apple linker intentionally refuses to know about -Bstatic or -static, so
# instead it is necessary to give full paths to the static libraries to generate
# a static build in this environment
case $_host_os in darwin*)
if test "$_static_libs" = yes; then
newlibs=
for lib in $LIBS; do
newlib=`echo $lib | sed "s@-l\(.*\)@$_staticlibpath/lib/lib\\1.a@"`
if test -f "$newlib"; then
newlibs="$newlibs $newlib"
else
newlibs="$newlibs $lib"
fi
done
LIBS=$newlibs
fi
esac

#
# Engine selection

0 comments on commit 2985c5d

Please sign in to comment.