Skip to content

Commit

Permalink
Rework the build system a bit
Browse files Browse the repository at this point in the history
Key changes:
* Always build as if BIN_DIST is 1. BIN_DIST is thus removed.
* Libraries are configured with prefix set to $$topdir rather than $(prefix)
  • Loading branch information
igfoo committed May 31, 2007
1 parent ad9d754 commit 430453c
Show file tree
Hide file tree
Showing 24 changed files with 249 additions and 447 deletions.
5 changes: 1 addition & 4 deletions Makefile
Expand Up @@ -135,6 +135,7 @@ endif

# Same as default rule, but we pass $(INSTALL_STAGE) to $(MAKE) too
install :: check-packages
$(INSTALL_DIR) $(bindir)
@case '${MFLAGS}' in *-[ik]*) x_on_err=0;; *-r*[ik]*) x_on_err=0;; *) x_on_err=1;; esac; \
for i in $(SUBDIRS); do \
echo "------------------------------------------------------------------------"; \
Expand Down Expand Up @@ -248,10 +249,6 @@ BINARY_DIST_PRE_RULES=$(foreach d,$(BinDistDirs),binary-dist-pre-$d)
binary-dist:: binary-dist-pre $(BINARY_DIST_PRE_RULES)

binary-dist-pre::
ifeq "$(BIN_DIST)" ""
@echo "WARNING: To run the binary-dist target, you need to set BIN_DIST=1 in mk/build.mk"
@false
endif
-rm -rf $(BIN_DIST_DIR)
-$(RM) $(BIN_DIST_DIR).tar.gz
$(MKDIRHIER) $(BIN_DIST_DIR)/bin/$(TARGETPLATFORM)
Expand Down
1 change: 0 additions & 1 deletion distrib/prep-bin-dist-mingw
Expand Up @@ -6,7 +6,6 @@
#
# To use:
#
# - make sure you set BIN_DIST=1 in your mk/build.mk before you built GHC.
# $ cd <top of GHC build tree>
# $ make binary-dist
#
Expand Down
27 changes: 11 additions & 16 deletions driver/ghc/Makefile
Expand Up @@ -8,23 +8,18 @@ include $(TOP)/mk/boilerplate.mk
# -----------------------------------------------------------------------------
# ghc script

ifeq "$(BIN_DIST)" "1"
GHCBIN=$$\"\"libexecdir/ghc-$(ProjectVersion)
GHCLIB=$$\"\"libdir
else
GHCBIN=$(libexecdir)/ghc-$(ProjectVersion)
GHCLIB=$(libdir)
endif # BIN_DIST

ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
SCRIPT_PROG = ghc-$(ProjectVersion)
LINK = ghc
ifneq "$(HOSTPLATFORM)" "i386-unknown-mingw32"
LINK = ghc
LINK_TARGET = $(LINK)-$(ProjectVersion)
INSTALLED_SCRIPT=$(bindir)/$(LINK_TARGET)
install::
$(RM) -f $(INSTALLED_SCRIPT)
echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
echo "GHCBIN=$(libexecdir)/ghc-$(ProjectVersion)" >> $(INSTALLED_SCRIPT)
echo "TOPDIROPT=-B$(libdir)" >> $(INSTALLED_SCRIPT)
echo 'exec $$GHCBIN $$TOPDIROPT $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
$(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
endif
SCRIPT_OBJS = ghc.sh
INTERP = $(SHELL)
TOPDIROPT = -B$(GHCLIB)
SCRIPT_SUBST_VARS = GHCBIN TOPDIROPT
INSTALL_SCRIPTS += $(SCRIPT_PROG)

# -----------------------------------------------------------------------------

Expand Down
2 changes: 0 additions & 2 deletions driver/ghc/ghc.sh

This file was deleted.

57 changes: 26 additions & 31 deletions driver/ghci/Makefile
Expand Up @@ -11,54 +11,49 @@ INSTALLING=1
# -----------------------------------------------------------------------------
# ghci script

ifeq "$(INSTALLING)" "1"
ifeq "$(BIN_DIST)" "1"
GHCBIN=$$\"\"libexecdir/ghc-$(ProjectVersion)
GHCLIB=$$\"\"libdir
else
GHCBIN=$(libexecdir)/ghc-$(ProjectVersion)
GHCLIB=$(libdir)
endif # BIN_DIST
else
GHCBIN=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/ghc-$(ProjectVersion)
GHCLIB=$(FPTOOLS_TOP_ABS)
endif

INSTALLED_SCRIPT_PROG = ghci-$(ProjectVersion)
INPLACE_SCRIPT_PROG = ghci-inplace

ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
C_PROG = ghci
C_OBJS += ghci.res
else
C_SRCS=
endif

SCRIPT_OBJS = ghci.sh
INTERP = $(SHELL)
SCRIPT_SUBST_VARS = GHCBIN TOPDIROPT
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
INSTALL_SCRIPTS += $(SCRIPT_PROG)
else
INSTALL_SCRIPTS += ghcii.sh
ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
INSTALL_PROGS += $(C_PROG)
GHCII_SCRIPT=$(bindir)/ghcii.sh
install::
$(RM) -f $(GHCII_SCRIPT)
echo "#!$(SHELL)" >> $(GHCII_SCRIPT)
echo 'exec "$0"/../ghc --interactive $${1+"$$@"}' >> $(GHCII_SCRIPT)
else
LINK = ghci
LINK_TARGET = $(LINK)-$(ProjectVersion)
INSTALLED_SCRIPT=$(bindir)/$(LINK_TARGET)
install::
$(RM) -f $(INSTALLED_SCRIPT)
echo "#!$(SHELL)" >> $(INSTALLED_SCRIPT)
echo "GHCBIN=$(libexecdir)/ghc-$(ProjectVersion)" >> $(INSTALLED_SCRIPT)
echo "TOPDIROPT=-B$(libdir)" >> $(INSTALLED_SCRIPT)
echo 'exec $$GHCBIN $$TOPDIROPT --interactive $${1+"$$@"}' >> $(INSTALLED_SCRIPT)
$(EXECUTABLE_FILE) $(INSTALLED_SCRIPT)
endif
TOPDIROPT = -B$(GHCLIB)

ifeq "$(INSTALLING)" "1"
SCRIPT_PROG = $(INSTALLED_SCRIPT_PROG)
ifneq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
LINK = ghci
endif
else
SCRIPT_PROG = $(INPLACE_SCRIPT_PROG)
INPLACE_SCRIPT=ghc-pkg-inplace
all::
$(RM) -f $(INPLACE_SCRIPT)
echo "#!$(SHELL)" >> $(INPLACE_SCRIPT)
echo "GHCBIN=$(FPTOOLS_TOP_ABS)/$(GHC_COMPILER_DIR_REL)/ghc-$(ProjectVersion)" >> $(INPLACE_SCRIPT)
echo "TOPDIROPT=$(FPTOOLS_TOP_ABS)" >> $(INPLACE_SCRIPT)
echo 'exec $$GHCPKGBIN --global-conf $$PKGCONF $${1+"$$@"}' >> $(INPLACE_SCRIPT)
$(EXECUTABLE_FILE) $(INPLACE_SCRIPT)
endif

# don't recurse on 'make install'
#
ifeq "$(INSTALLING)" "1"
all clean distclean maintainer-clean ::
$(MAKE) INSTALLING=0 BIN_DIST=0 $(MFLAGS) $@
$(MAKE) INSTALLING=0 $(MFLAGS) $@
endif

ifeq "$(TARGETPLATFORM)" "i386-unknown-mingw32"
Expand Down
19 changes: 10 additions & 9 deletions driver/mangler/Makefile
Expand Up @@ -4,15 +4,16 @@
TOP=../..
include $(TOP)/mk/boilerplate.mk

SCRIPT_PROG = ghc-asm

INTERP=perl

SCRIPT_SUBST_VARS := TARGETPLATFORM

INSTALL_LIBEXEC_SCRIPTS += $(SCRIPT_PROG)

CLEAN_FILES += $(SCRIPT_OBJS)
PROG = ghc-asm
all:: $(PROG).prl
$(RM) -f $(PROG)
echo '#!$(PERL)' >> $(PROG)
echo '$$TARGETPLATFORM = "$(TARGETPLATFORM)";' >> $(PROG)
cat $< >> $(PROG)
$(EXECUTABLE_FILE) $(PROG)

INSTALL_LIBEXEC_SCRIPTS += $(PROG)
CLEAN_FILES += $(PROG) $(PROG).prl

# needed for bootstrapping with HC files
ifeq "$(BootingFromHc)" "YES"
Expand Down
17 changes: 9 additions & 8 deletions driver/split/Makefile
Expand Up @@ -4,14 +4,15 @@
TOP=../..
include $(TOP)/mk/boilerplate.mk

SCRIPT_PROG = ghc-split
PROG = ghc-split
all:: $(PROG).prl
$(RM) -f $(PROG)
echo '#!$(PERL)' >> $(PROG)
echo '$$TARGETPLATFORM = "$(TARGETPLATFORM)";' >> $(PROG)
cat $< >> $(PROG)
$(EXECUTABLE_FILE) $(PROG)

INTERP=perl

SCRIPT_SUBST_VARS := TARGETPLATFORM

INSTALL_LIBEXEC_SCRIPTS += $(SCRIPT_PROG)

CLEAN_FILES += $(SCRIPT_OBJS)
INSTALL_LIBEXEC_SCRIPTS += $(PROG)
CLEAN_FILES += $(PROG) $(PROG).prl

include $(TOP)/mk/target.mk
18 changes: 10 additions & 8 deletions libraries/Makefile
Expand Up @@ -183,7 +183,8 @@ stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).%: %/setup/Setup
-$(RM) -f stamp/configure.library.*.$* $*/unbuildable
( cd $* && setup/Setup configure \
$(CONFIGURE_OPTS) \
--prefix=$(prefix) \
--prefix='$$topdir' \
--libsubdir='$$compiler/lib/$$pkgid' \
--with-compiler=../../compiler/ghc-inplace$(dot_bat) \
--with-hc-pkg=../../utils/ghc-pkg/ghc-pkg-inplace$(dot_bat) \
--with-hsc2hs=../../utils/hsc2hs/hsc2hs-inplace$(dot_bat) \
Expand Down Expand Up @@ -227,16 +228,17 @@ doc.library.%: stamp/configure.library.build$(CONFIGURE_STAMP_EXTRAS).% \

.PHONY: install install-docs install.library.%

INSTALL_DIR=$(prefix)/share/ghc/doc/html/
ROOT=$(prefix)/share/ghc/doc/html/

install: $(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR))
ifneq "$(NO_HADDOCK_DOCS)" "YES"
$(INSTALL_DATA) index.html doc-index.html $(INSTALL_DIR)
$(INSTALL_SCRIPT) gen_contents_index $(INSTALL_DIR)
$(INSTALL_DIR) $(ROOT)
$(INSTALL_DATA) index.html doc-index.html $(ROOT)
$(INSTALL_SCRIPT) gen_contents_index $(ROOT)
# Hacks:
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.css $(INSTALL_DIR)
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.js $(INSTALL_DIR)
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.gif $(INSTALL_DIR)
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.css $(ROOT)
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.js $(ROOT)
$(INSTALL_DATA) $(prefix)/share/ghc/doc/html/base/*.gif $(ROOT)
endif

# Cabal doesn't let us ask to install docs only, so do nothing here
Expand All @@ -248,7 +250,7 @@ install-docs:
# Thus if you install without building then it will just break.
$(foreach SUBDIR,$(SUBDIRS),install.library.$(SUBDIR)): \
install.library.%: installPackage/installPackage ifBuildable/ifBuildable
ifBuildable/ifBuildable $* ../installPackage/installPackage
ifBuildable/ifBuildable $* ../installPackage/installPackage $(prefix) $(bindir)/ghc-pkg

.PHONY: binary-dist binary-dist.library.%

Expand Down
60 changes: 33 additions & 27 deletions libraries/installPackage.hs
Expand Up @@ -6,23 +6,39 @@ import Distribution.Simple.Configure
import Distribution.Simple.LocalBuildInfo
import Distribution.Simple.Utils
import Distribution.Verbosity
import System.Cmd
import System.Environment

main :: IO ()
main = do args <- getArgs
let verbosity = case args of
case args of
pref : ghcpkg : args' ->
let verbosity = case args' of
[] -> normal
['-':'v':v] ->
let m = case v of
"" -> Nothing
_ -> Just v
in flagToVerbosity m
_ -> error ("Bad arguments: " ++ show args)
userHooks = simpleUserHooks
installFlags = InstallFlags {
installUserFlags = MaybeUserGlobal,
installVerbose = verbosity
}
in doit pref ghcpkg verbosity
_ ->
error "Missing arguments"

doit :: FilePath -> FilePath -> Verbosity -> IO ()
doit pref ghcpkg verbosity =
do let userHooks = simpleUserHooks
copyFlags = CopyFlags {
copyDest = NoCopyDest,
copyVerbose = verbosity
}
registerFlags = RegisterFlags {
regUser = MaybeUserGlobal,
regGenScript = False,
regInPlace = False,
regWithHcPkg = Just ghcpkg,
regVerbose = verbosity
}
pdFile <- defaultPackageDesc verbosity
pd <- readPackageDescription verbosity pdFile
lbi <- getPersistBuildConfig
Expand All @@ -36,25 +52,15 @@ main = do args <- getArgs
Nothing ->
error "Expected a library, but none found"
pd' = pd { library = Just lib' }
-- When installing we need to use the non-inplace ghc-pkg.
-- We also set the compiler to be non-inplace, but that
-- probably doesn't matter.
c = compiler lbi
c' = c { compilerPath = dropInPlace (compilerPath c),
compilerPkgTool = dropInPlace (compilerPkgTool c)
}
lbi' = lbi { compiler = c' }
(instHook simpleUserHooks) pd' lbi' userHooks installFlags

dropInPlace :: FilePath -> FilePath
dropInPlace "" = ""
dropInPlace xs@(x:xs') = case dropPrefix "-inplace" xs of
Nothing -> x : dropInPlace xs'
Just xs'' -> dropInPlace xs''

dropPrefix :: Eq a => [a] -> [a] -> Maybe [a]
dropPrefix [] ys = Just ys
dropPrefix (x:xs) (y:ys)
| x == y = dropPrefix xs ys
dropPrefix _ _ = Nothing
-- When coying, we need to actually give a concrete
-- directory to copy to rather than "$topdir"
lbi_copy = lbi { prefix = pref }
-- When we run GHC we give it a $topdir that includes the
-- $compiler/lib/ part of libsubdir, so we only want the
-- $pkgid part in the package.conf file. This is a bit of
-- a hack, really.
lbi_register = lbi { libsubdir = "$pkgid" }
(copyHook simpleUserHooks) pd' lbi_copy userHooks copyFlags
(regHook simpleUserHooks) pd' lbi_register userHooks registerFlags
return ()

1 change: 1 addition & 0 deletions mk/config.mk.in
Expand Up @@ -786,6 +786,7 @@ LNDIR = $(GHC_LNDIR_DIR)/$(GHC_LNDIR_PGM)
RUNTEST = $(GHC_RUNTEST_DIR)/$(GHC_RUNTEST_PGM)

GENERATED_FILE = chmod a-w
EXECUTABLE_FILE = chmod +x

#-----------------------------------------------------------------------------
# Haskell compilers and mkdependHS
Expand Down
6 changes: 0 additions & 6 deletions mk/package.mk
Expand Up @@ -22,13 +22,8 @@ PKG_DATADIR = $$topdir

else

ifeq "$(BIN_DIST)" ""
PKG_LIBDIR = $(libdir)
PKG_DATADIR = $(datadir)
else
PKG_LIBDIR = $$libdir
PKG_DATADIR = $$datadir
endif

endif # Unix

Expand Down Expand Up @@ -373,7 +368,6 @@ CLEAN_FILES += $(PACKAGE).haddock
$(HC) $(HC_OPTS) -D__HADDOCK__ -E $< -o $@

HTML_INSTALL_DIR = $(datadir)/html/libraries/$(PACKAGE)
# NOT the same as HTML_DIR_INSTALLED when BIN_DIST is on

install-docs :: $(HTML_DOC)
@$(INSTALL_DIR) $(HTML_INSTALL_DIR)
Expand Down
2 changes: 1 addition & 1 deletion mk/paths.mk
Expand Up @@ -233,7 +233,7 @@ TAGS_C_SRCS=$(C_SRCS)
# Specifically glafp-utils/mkdependC/mkdependC.prl and others in driver/ and
# possibly others elsewhere in the tree. ToDo: fix this properly.
MOSTLY_CLEAN_FILES += $(HS_OBJS) $(C_OBJS) $(HSC_C_OBJS) $(GC_C_OBJS)
CLEAN_FILES += $(HS_PROG) $(C_PROG) $(SCRIPT_PROG) $(SCRIPT_LINK) \
CLEAN_FILES += $(HS_PROG) $(C_PROG) $(SCRIPT_LINK) \
$(PROG) $(LIBRARY) a.out \
$(DERIVED_HSC_SRCS) \
$(DERIVED_GC_SRCS) \
Expand Down

0 comments on commit 430453c

Please sign in to comment.