diff --git a/configure b/configure index 289378fc0fe..11248c84368 100755 --- a/configure +++ b/configure @@ -770,6 +770,7 @@ with_mccs with_0install_solver with_libacl with_private_runtime +enable_static enable_cold_check with_dune with_vendored_deps @@ -1410,6 +1411,10 @@ Optional Features: --enable-developer-mode Enable developer features + --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-cold-check Fail on some check necessary for make cold --disable-certificate-check Do not check the certificate of opam's dependency @@ -4037,6 +4042,15 @@ else $as_nop fi +# Check whether --enable-static was given. +if test ${enable_static+y} +then : + enableval=$enable_static; +else $as_nop + enable_static=auto +fi + + # Check whether --enable-cold_check was given. if test ${enable_cold_check+y} then : @@ -4191,6 +4205,11 @@ SYSTEM=`$OCAML shell/print_config.ml system 2>/dev/null | grep -F -v "Cannot fin { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $SYSTEM" >&5 printf "%s\n" "$SYSTEM" >&6; } +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for compiler target" >&5 +printf %s "checking for compiler target... " >&6; } +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"` +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: $TARGET" >&5 +printf "%s\n" "$TARGET" >&6; } LIB_PREPEND= INC_PREPEND= @@ -6152,6 +6171,51 @@ else $as_nop fi +# Handle --enable-static +{ printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for linking method" >&5 +printf %s "checking for linking method... " >&6; } +support_static=no +default_static=no +case $TARGET in #( + *-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" + ;; #( + *) : + ;; +esac +case ${support_static},${enable_static} in #( + no,yes) : + as_fn_error $? "--enable-static is not available on this platform (${TARGET})." "$LINENO" 5 ;; #( + *,auto) : + enable_static=${default_static} ;; #( + *) : + ;; +esac +if test "${enable_static}" = yes +then : + + echo "(-noautolink -cclib -lunix -cclib -lmccs_stubs -cclib -lmccs_glpk_stubs -cclib -lsha_stubs ${platform_dependant_stuff})" > src/client/linking.sexp + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: static" >&5 +printf "%s\n" "static" >&6; } + +else $as_nop + + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: result: shared" >&5 +printf "%s\n" "shared" >&6; } + +fi + echo # Dependencies diff --git a/configure.ac b/configure.ac index 219605e4d5b..dd0b48cc84f 100644 --- a/configure.ac +++ b/configure.ac @@ -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],[] ) @@ -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= @@ -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 diff --git a/master_changes.md b/master_changes.md index d767b6773ef..60322818c0b 100644 --- a/master_changes.md +++ b/master_changes.md @@ -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]