summaryrefslogtreecommitdiff
path: root/utils/ghc-pkg
diff options
context:
space:
mode:
Diffstat (limited to 'utils/ghc-pkg')
-rw-r--r--utils/ghc-pkg/Main.hs55
-rw-r--r--utils/ghc-pkg/Makefile24
-rw-r--r--utils/ghc-pkg/ghc.mk69
3 files changed, 101 insertions, 47 deletions
diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs
index 3d1c8059c7..b1aaaba7b0 100644
--- a/utils/ghc-pkg/Main.hs
+++ b/utils/ghc-pkg/Main.hs
@@ -378,19 +378,14 @@ getPkgDatabases modify my_flags = do
let err_msg = "missing --global-conf option, location of global package.conf unknown\n"
global_conf <-
case [ f | FlagGlobalConfig f <- my_flags ] of
- [] -> do mb_dir <- getExecDir "/bin/ghc-pkg.exe"
+ [] -> do mb_dir <- getLibDir
case mb_dir of
Nothing -> die err_msg
Just dir ->
- do let path1 = dir </> "package.conf"
- path2 = dir </> ".." </> ".." </> ".."
- </> "inplace-datadir"
- </> "package.conf"
- exists1 <- doesFileExist path1
- exists2 <- doesFileExist path2
- if exists1 then return path1
- else if exists2 then return path2
- else die "Can't find package.conf"
+ do let path = dir </> "package.conf"
+ exists <- doesFileExist path
+ unless exists $ die "Can't find package.conf"
+ return path
fs -> return (last fs)
let global_conf_dir = global_conf ++ ".d"
@@ -1053,7 +1048,7 @@ checkGHCiLib dirs batch_lib_dir batch_lib_file lib auto_build
| auto_build = autoBuildGHCiLib batch_lib_dir batch_lib_file ghci_lib_file
| otherwise = do
m <- doesFileExistOnPath ghci_lib_file dirs
- when (isNothing m) $
+ when (isNothing m && ghci_lib_file /= "HSrts.o") $
hPutStrLn stderr ("warning: can't find GHCi lib " ++ ghci_lib_file)
where
ghci_lib_file = lib <.> "o"
@@ -1069,7 +1064,7 @@ autoBuildGHCiLib dir batch_file ghci_file = do
#if defined(darwin_HOST_OS)
r <- rawSystem "ld" ["-r","-x","-o",ghci_lib_file,"-all_load",batch_lib_file]
#elif defined(mingw32_HOST_OS)
- execDir <- getExecDir "/bin/ghc-pkg.exe"
+ execDir <- getLibDir
r <- rawSystem (maybe "" (++"/gcc-lib/") execDir++"ld") ["-r","-x","-o",ghci_lib_file,"--whole-archive",batch_lib_file]
#else
r <- rawSystem "ld" ["-r","-x","-o",ghci_lib_file,"--whole-archive",batch_lib_file]
@@ -1184,26 +1179,34 @@ subst a b ls = map (\ x -> if x == a then b else x) ls
unDosifyPath :: FilePath -> FilePath
unDosifyPath xs = subst '\\' '/' xs
-getExecDir :: String -> IO (Maybe String)
+getLibDir :: IO (Maybe String)
+getLibDir = fmap (fmap (</> "lib")) $ getExecDir "/bin/ghc-pkg.exe"
+
-- (getExecDir cmd) returns the directory in which the current
-- executable, which should be called 'cmd', is running
-- So if the full path is /a/b/c/d/e, and you pass "d/e" as cmd,
-- you'll get "/a/b/c" back as the result
-getExecDir cmd
- = allocaArray len $ \buf -> do
- ret <- getModuleFileName nullPtr buf len
- if ret == 0 then return Nothing
- else do s <- peekCString buf
- return (Just (reverse (drop (length cmd)
- (reverse (unDosifyPath s)))))
- where
- len = 2048::Int -- Plenty, PATH_MAX is 512 under Win32.
+getExecDir :: String -> IO (Maybe String)
+getExecDir cmd =
+ getExecPath >>= maybe (return Nothing) removeCmdSuffix
+ where unDosifyPath = subst '\\' '/'
+ initN n = reverse . drop n . reverse
+ removeCmdSuffix = return . Just . initN (length cmd) . unDosifyPath
+
+getExecPath :: IO (Maybe String)
+getExecPath =
+ allocaArray len $ \buf -> do
+ ret <- getModuleFileName nullPtr buf len
+ if ret == 0 then return Nothing
+ else liftM Just $ peekCString buf
+ where len = 2048 -- Plenty, PATH_MAX is 512 under Win32.
+
+foreign import stdcall unsafe "GetModuleFileNameA"
+ getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
-foreign import stdcall unsafe "GetModuleFileNameA"
- getModuleFileName :: Ptr () -> CString -> Int -> IO Int32
#else
-getExecDir :: String -> IO (Maybe String)
-getExecDir _ = return Nothing
+getLibDir :: IO (Maybe String)
+getLibDir = return Nothing
#endif
-----------------------------------------
diff --git a/utils/ghc-pkg/Makefile b/utils/ghc-pkg/Makefile
index 632e02c1d5..c45176561c 100644
--- a/utils/ghc-pkg/Makefile
+++ b/utils/ghc-pkg/Makefile
@@ -1,21 +1,3 @@
-
-TOP=../..
-ENABLE_SHELL_WRAPPERS = YES
-EXTRA_CLEAN = Version.hs
-EXTRA_INPLACE_CONFIGURE_FLAGS = $(INPLACE_GHC_DATADIR_CONFIGURE_FLAGS)
-EXTRA_STAGE2_CONFIGURE_FLAGS = --datasubdir=.
-
-include $(TOP)/mk/boilerplate.mk
-include $(TOP)/mk/cabal.mk
-
-with-bootstrapping-compiler: Version.hs
-with-stage-2: Version.hs
-
-Version.hs: Makefile $(TOP)/mk/config.mk
- $(RM) -f Version.hs
- echo "module Version where" >> Version.hs
- echo "version, targetOS, targetARCH :: String" >> Version.hs
- echo "version = \"$(ProjectVersion)\"" >> Version.hs
- echo "targetOS = \"$(TargetOS_CPP)\"" >> Version.hs
- echo "targetARCH = \"$(TargetArch_CPP)\"" >> Version.hs
-
+dir = utils/ghc-pkg
+TOP = ../..
+include $(TOP)/mk/sub-makefile.mk
diff --git a/utils/ghc-pkg/ghc.mk b/utils/ghc-pkg/ghc.mk
new file mode 100644
index 0000000000..388af0d5b9
--- /dev/null
+++ b/utils/ghc-pkg/ghc.mk
@@ -0,0 +1,69 @@
+# -----------------------------------------------------------------------------
+# Bootstrapping ghc-pkg
+
+utils/ghc-pkg_dist_PROG = ghc-pkg
+
+$(GHC_PKG_INPLACE) : utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext) $(MKDIRHIER)
+ $(MKDIRHIER) $(dir $(INPLACE_PACKAGE_CONF))
+ echo "[]" > $(INPLACE_PACKAGE_CONF)
+ifeq "$(Windows)" "YES"
+ cp $< $@
+else
+ $(RM) $@
+ echo "#!/bin/sh" >>$@
+ echo "PKGCONF=$(TOP)/$(INPLACE_PACKAGE_CONF)" >>$@
+ echo '$(TOP)/utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG) --global-conf $$PKGCONF $${1+"$$@"}' >> $@
+ chmod +x $@
+endif
+
+# depend on ghc-cabal, otherwise we build Cabal twice when building in parallel
+utils/ghc-pkg/dist/build/$(utils/ghc-pkg_dist_PROG)$(exeext): utils/ghc-pkg/Main.hs utils/ghc-pkg/Version.hs $(GHC_CABAL_INPLACE) $(MKDIRHIER)
+ $(MKDIRHIER) bootstrapping
+ $(MKDIRHIER) utils/ghc-pkg/dist/build
+ $(GHC) --make utils/ghc-pkg/Main.hs -o $@ \
+ -Wall \
+ -DCABAL_VERSION=$(CABAL_VERSION) \
+ -odir bootstrapping \
+ -hidir bootstrapping \
+ -iutils/ghc-pkg \
+ -XCPP -XExistentialQuantification -XDeriveDataTypeable \
+ -ilibraries/Cabal \
+ -ilibraries/filepath \
+ -ilibraries/extensible-exceptions \
+ -ilibraries/hpc
+
+utils/ghc-pkg/Version.hs: mk/config.mk
+ $(RM) -f $@
+ echo "module Version where" >> $@
+ echo "version, targetOS, targetARCH :: String" >> $@
+ echo "version = \"$(ProjectVersion)\"" >> $@
+ echo "targetOS = \"$(TargetOS_CPP)\"" >> $@
+ echo "targetARCH = \"$(TargetArch_CPP)\"" >> $@
+
+$(eval $(call clean-target,utils/ghc-pkg,dist,\
+ utils/ghc-pkg/dist \
+ utils/ghc-pkg/Version.hs))
+
+# -----------------------------------------------------------------------------
+# Building ghc-pkg with stage 1
+
+utils/ghc-pkg_dist-install_PROG = ghc-pkg
+utils/ghc-pkg_dist-install_MODULES = Main Version
+utils/ghc-pkg_dist-install_DEPS = Cabal
+utils/ghc-pkg_dist-install_SHELL_WRAPPER = YES
+utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER = YES
+utils/ghc-pkg_dist-install_INSTALL_SHELL_WRAPPER_NAME = ghc-pkg-$(ProjectVersion)
+utils/ghc-pkg_dist-install_INSTALL_INPLACE = NO
+
+$(eval $(call build-prog,utils/ghc-pkg,dist-install,1))
+
+ifeq "$(Windows)" "NO"
+install: install_utils/ghc-pkg_link
+
+.PNONY: install_utils/ghc-pkg_link
+install_utils/ghc-pkg_link:
+ $(MKDIRHIER) $(DESTDIR)$(bindir)
+ $(RM) -f $(DESTDIR)$(bindir)/ghc-pkg
+ $(LN_S) ghc-pkg-$(ProjectVersion) $(DESTDIR)$(bindir)/ghc-pkg
+endif
+