From 41cbaf44a6ab5eb9fa676d65d32df8377898dc89 Mon Sep 17 00:00:00 2001 From: Matthew Pickering <matthewtpickering@gmail.com> Date: Thu, 13 Jul 2023 17:27:54 +0100 Subject: [PATCH] packaging: Fix installation scripts on windows/RelocatableBuild case This includes quite a lot of small fixes which fix the installation makefile to work on windows properly. This also required fixing the RelocatableBuild variable which seemed to have been broken for a long while. Sam helped me a lot writing this patch by providing a windows machine to test the changes. Without him it would have taken ages to tweak everything. Co-authored-by: sheaf <sam.derbyshire@gmail.com> --- distrib/configure.ac.in | 12 ++++++ hadrian/bindist/Makefile | 17 +++++++-- hadrian/bindist/config.mk.in | 15 ++++---- hadrian/src/Rules/BinaryDist.hs | 68 +++++++++++++-------------------- 4 files changed, 59 insertions(+), 53 deletions(-) diff --git a/distrib/configure.ac.in b/distrib/configure.ac.in index 777c5259c52c..5095af3ac2ff 100644 --- a/distrib/configure.ac.in +++ b/distrib/configure.ac.in @@ -103,6 +103,17 @@ AC_ARG_ENABLE(distro-toolchain, [EnableDistroToolchain=@SettingsUseDistroMINGW@] ) +if test "$HostOS" = "mingw32" -a "$EnableDistroToolchain" = "NO"; then + FP_SETUP_WINDOWS_TOOLCHAIN([$hardtop/mingw/], [\$\$topdir/../mingw/]) +fi + +if test "$HostOS" = "mingw32"; then + WindresCmd="$Windres" + AC_SUBST([WindresCmd]) + AC_SUBST([GenlibCmd]) + AC_SUBST([HAVE_GENLIB]) +fi + dnl ** Which gcc to use? dnl -------------------------------------------------------------- AC_PROG_CC([gcc clang]) @@ -288,6 +299,7 @@ if test "x$UseLibdw" = "xYES" ; then fi AC_SUBST(UseLibdw) + FP_SETTINGS AC_CONFIG_FILES([config.mk]) diff --git a/hadrian/bindist/Makefile b/hadrian/bindist/Makefile index 32fa695d649e..fb34637fc6a0 100644 --- a/hadrian/bindist/Makefile +++ b/hadrian/bindist/Makefile @@ -62,20 +62,29 @@ show: .PHONY: install -ifeq "$(TargetOS_CPP)" "mingw32" -install_bin: install_mingw install_bin_direct +ifeq "$(EnableDistroToolchain)" "NO" +install_extra: install_mingw +else +install_extra: +endif + +ifeq "$(RelocatableBuild)" "YES" +install_bin: install_bin_direct else install_bin: install_bin_libdir install_wrappers endif -install: install_bin install_lib + + +install: install_bin install_lib install_extra install: install_man install_docs update_package_db -ActualBinsDir=${ghclibdir}/bin ifeq "$(RelocatableBuild)" "YES" ActualLibsDir=${ghclibdir} +ActualBinsDir=${bindir} else ActualLibsDir=${ghclibdir}/lib +ActualBinsDir=${ghclibdir}/bin endif WrapperBinsDir=${bindir} diff --git a/hadrian/bindist/config.mk.in b/hadrian/bindist/config.mk.in index ab4ae7a90579..4a21d7d0e437 100644 --- a/hadrian/bindist/config.mk.in +++ b/hadrian/bindist/config.mk.in @@ -67,6 +67,13 @@ $(eval $(call set_default,dvidir,$${docdir})) $(eval $(call set_default,pdfdir,$${docdir})) $(eval $(call set_default,psdir,$${docdir})) +# On Windows we can only make a relocatable bindist because the normal install +# script creates wrapper scripts which do not work on windows. Therefore we force +# RelocatableBuild = YES here until/if that is ever fixed. +ifeq "$(Windows_Host)" "YES" +RelocatableBuild = YES +endif + ifeq "$(RelocatableBuild)" "YES" # Hack: our directory layouts tend to be different on Windows, so @@ -153,14 +160,6 @@ else GhcWithInterpreter=$(if $(findstring YES,$(DYNAMIC_GHC_PROGRAMS)),YES,NO) endif -# On Windows we normally want to make a relocatable bindist, to we -# ignore flags like libdir -ifeq "$(Windows_Host)" "YES" -RelocatableBuild = YES -else -RelocatableBuild = NO -endif - ifneq "$(DESTDIR)" "" diff --git a/hadrian/src/Rules/BinaryDist.hs b/hadrian/src/Rules/BinaryDist.hs index 3b39ad1453a4..8cb7e9063cb9 100644 --- a/hadrian/src/Rules/BinaryDist.hs +++ b/hadrian/src/Rules/BinaryDist.hs @@ -229,16 +229,6 @@ bindistRules = do cmd_ (bindistFilesDir -/- "bin" -/- ghcPkgName) ["recache"] - -- The settings file must be regenerated by the bindist installation - -- logic to account for the environment discovered by the bindist - -- configure script on the host. Not on Windows, however, where - -- we do not ship a configure script with the bindist. See #20254. - -- - -- N.B. we must do this after ghc-pkg has been run as it will go - -- looking for the settings files. - unless windowsHost $ - removeFile (bindistFilesDir -/- "lib" -/- "settings") - unless cross $ need ["docs"] -- TODO: we should only embed the docs that have been generated @@ -272,37 +262,33 @@ bindistRules = do whenM (liftIO (IO.doesDirectoryExist (root -/- "manpage"))) $ do copyDirectory (root -/- "manpage") bindistFilesDir - -- These scripts are only necessary in the configure/install - -- workflow which is not supported on windows. - -- TODO: Instead of guarding against windows, we could offer the - -- option to make a relocatable, but not installable bindist on any - -- platform. - unless windowsHost $ do - -- We then 'need' all the files necessary to configure and install - -- (as in, './configure [...] && make install') this build on some - -- other machine. - need $ map (bindistFilesDir -/-) - (["configure", "Makefile"] ++ bindistInstallFiles) - copyFile ("hadrian" -/- "bindist" -/- "config.mk.in") (bindistFilesDir -/- "config.mk.in") - generateBuildMk >>= writeFile' (bindistFilesDir -/- "build.mk") - copyFile ("hadrian" -/- "cfg" -/- "default.target.in") (bindistFilesDir -/- "default.target.in") - copyFile ("hadrian" -/- "cfg" -/- "default.host.target.in") (bindistFilesDir -/- "default.host.target.in") - forM_ bin_targets $ \(pkg, _) -> do - needed_wrappers <- pkgToWrappers pkg - forM_ needed_wrappers $ \wrapper_name -> do - let suffix = if useGhcPrefix pkg - then "ghc-" ++ version - else version - wrapper_content <- wrapper wrapper_name - let unversioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- wrapper_name - versioned_wrapper = wrapper_name ++ "-" ++ suffix - versioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- versioned_wrapper - -- Write the wrapper to the versioned path - writeFile' versioned_wrapper_path wrapper_content - -- Create a symlink from the non-versioned to the versioned. - liftIO $ do - IO.removeFile unversioned_wrapper_path <|> return () - IO.createFileLink versioned_wrapper unversioned_wrapper_path + -- We then 'need' all the files necessary to configure and install + -- (as in, './configure [...] && make install') this build on some + -- other machine. + need $ map (bindistFilesDir -/-) + (["configure", "Makefile"] ++ bindistInstallFiles) + copyFile ("hadrian" -/- "bindist" -/- "config.mk.in") (bindistFilesDir -/- "config.mk.in") + generateBuildMk >>= writeFile' (bindistFilesDir -/- "build.mk") + copyFile ("hadrian" -/- "cfg" -/- "default.target.in") (bindistFilesDir -/- "default.target.in") + copyFile ("hadrian" -/- "cfg" -/- "default.host.target.in") (bindistFilesDir -/- "default.host.target.in") + + -- todo: do we need these wrappers on windows + forM_ bin_targets $ \(pkg, _) -> do + needed_wrappers <- pkgToWrappers pkg + forM_ needed_wrappers $ \wrapper_name -> do + let suffix = if useGhcPrefix pkg + then "ghc-" ++ version + else version + wrapper_content <- wrapper wrapper_name + let unversioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- wrapper_name + versioned_wrapper = wrapper_name ++ "-" ++ suffix + versioned_wrapper_path = bindistFilesDir -/- "wrappers" -/- versioned_wrapper + -- Write the wrapper to the versioned path + writeFile' versioned_wrapper_path wrapper_content + -- Create a symlink from the non-versioned to the versioned. + liftIO $ do + IO.removeFile unversioned_wrapper_path <|> return () + IO.createFileLink versioned_wrapper unversioned_wrapper_path let buildBinDist = buildBinDistX "binary-dist-dir" "bindist" buildBinDistReloc = buildBinDistX "reloc-binary-dist-dir" "reloc-bindist" -- GitLab