Skip to content

Commit

Permalink
Add ./configure --enable-static to compile the opam binary statically…
Browse files Browse the repository at this point in the history
… (enabled by default with MinGW)
  • Loading branch information
kit-ty-kate committed Sep 20, 2023
1 parent b0cb137 commit fa388c1
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
64 changes: 64 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 36 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ AC_ARG_WITH([private_runtime],
AS_HELP_STRING([--with-private-runtime],[For a mingw-w64 build, manifest the runtime DLLs locally in Opam.Runtime.arch]),,[with_private_runtime=no]
)

AC_ARG_ENABLE([static],
AS_HELP_STRING([--enable-static],
[Compile the opam binary statically. Only Musl-based Linux distributions and Windows with MinGW is currently supported. This is the default on Windows with MinGW]),
[],
[enable_static=auto])

AC_ARG_ENABLE([cold_check],
AS_HELP_STRING([--enable-cold-check],[Fail on some check necessary for make cold]),[COLD_CHECK=yes],[]
)
Expand Down Expand Up @@ -113,6 +119,9 @@ AC_MSG_CHECKING([for compiler system])
SYSTEM=`$OCAML shell/print_config.ml system 2>/dev/null | grep -F -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/system: //p"`
AC_MSG_RESULT([$SYSTEM])
AC_SUBST(SYSTEM)
AC_MSG_CHECKING([for compiler target])
TARGET=`$OCAML shell/print_config.ml target 2>/dev/null | grep -F -v "Cannot find" || $OCAMLC -config | tr -d '\r' | sed -n -e "s/target: //p"`
AC_MSG_RESULT([$TARGET])

LIB_PREPEND=
INC_PREPEND=
Expand Down Expand Up @@ -325,6 +334,33 @@ AS_IF([test "x${with_private_runtime}" != "xno"],[
],[CONF_MANIFEST_O=])
AC_SUBST(CONF_MANIFEST_O)

# Handle --enable-static
AC_MSG_CHECKING([for linking method])
support_static=no
default_static=no
AS_CASE([$TARGET],
[*-linux-musl*],[
support_static=yes
platform_dependant_stuff="-cclib -lstdc++ -cclib -static-libgcc -cclib -static"
],
[*-*-mingw32*],[
support_static=yes
default_static=yes
# NOTE: On Windows, the Windows specific dlls should stay dynamic for security reasons
# NOTE: -l:libstdc++.a is necessary (vs. -lstdc++) as flexlink will use libstdc++.dll.a
# which still depends on the DLL at runtime instead of libstdc++.a (that looks like a bug in flexlink)
platform_dependant_stuff="-cclib -lopam_stubs_win32_stubs -cclib -l:libstdc++.a -cclib -l:libpthread.a -cclib -Wl,-static -cclib -ladvapi32 -cclib -lgdi32 -cclib -luser32 -cclib -lshell32"
])
AS_CASE([${support_static},${enable_static}],
[no,yes],[AC_MSG_ERROR([--enable-static is not available on this platform (${TARGET}).])],
[*,auto],[enable_static=${default_static}])
AS_IF([test "${enable_static}" = yes],[
echo "(-noautolink -cclib -lunix -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependant_stuff})" > src/client/linking.sexp
AC_MSG_RESULT([static])
],[
AC_MSG_RESULT([shared])
])

echo

# Dependencies
Expand Down
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ users)
* Remove `bigarray` dependency [#5612 @kit-ty-kate]
* Remove use of deprecated `Printf.kprintf" [#5612 @kit-ty-kate]
* Fix "make cold" on Windows when gcc is available [#5635 @kit-ty-kate - fixes #5600]
* Add ./configure --enable-static to compile the opam binary statically [#5680 @kit-ty-kate - fixes #5647]

## Infrastructure
* Test OCaml 5.0 and 5.1 in CI [#5672 @kit-ty-kate]
Expand Down

0 comments on commit fa388c1

Please sign in to comment.