Skip to content

Multi target support #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: wip/make-build-pre-zig
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
190 changes: 185 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,41 @@ GHC0 ?= ghc-9.8.4
PYTHON ?= python3
CABAL ?= cabal

EMCC ?= emcc
EMCXX ?= em++
EMAR ?= emar
EMRANLIB ?= emranlib

EXTRA_LIB_DIRS ?=
EXTRA_INCLUDE_DIRS ?=

MUSL_EXTRA_LIB_DIRS ?=
MUSL_EXTRA_INCLUDE_DIRS ?=

JS_EXTRA_LIB_DIRS ?=
JS_EXTRA_INCLUDE_DIRS ?=

# :exploding-head: It turns out override doesn't override the command-line
# value but it overrides Make's normal behavior of ignoring assignments to
# command-line variables. This allows the += operations to append to whatever
# was passed from the command line.

override CABAL_ARGS += \
--remote-repo-cache _build/packages \
--store-dir=_build/$(STAGE)/store \
--store-dir=_build/$(STAGE)/$(TARGET)/store \
--logs-dir=_build/$(STAGE)/logs

override CABAL_BUILD_ARGS += \
-j -v -w $(GHC) --with-gcc=$(CC) \
--project-file=cabal.project.$(STAGE) \
--builddir=_build/$(STAGE)
--project-file=cabal.project.$(STAGE)$(if $(TARGET),".$(TARGET)",) \
$(foreach lib,$(EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
--builddir=_build/$(STAGE)/$(TARGET)

# just some defaults
STAGE ?= stage1
GHC ?= $(GHC0)
TARGET ?=

CABAL_BUILD = $(CABAL) $(CABAL_ARGS) build $(CABAL_BUILD_ARGS)

Expand Down Expand Up @@ -62,7 +79,7 @@ endef

define run_and_log
@set -e; \
LOGDIR=$(@D)/../logs; \
LOGDIR=_build/$(STAGE)/logs; \
mkdir -p "$$LOGDIR"; \
STDOUT_LOG="$$LOGDIR/$(notdir $@).stdout.log"; \
STDERR_LOG="$$LOGDIR/$(notdir $@).stderr.log"; \
Expand Down Expand Up @@ -176,6 +193,34 @@ STAGE2_UTIL_EXECUTABLES := \
runghc \
unlit

STAGE3_LIBS := \
Cabal \
Cabal-syntax \
array \
base \
binary \
bytestring \
containers \
deepseq \
directory \
exceptions \
file-io \
filepath \
ghc-bignum \
hpc \
integer-gmp \
mtl \
os-string \
parsec \
pretty \
process \
stm \
template-haskell \
text \
time \
transformers \
xhtml

# export CABAL := $(shell cabal update 2>&1 >/dev/null && cabal build cabal-install -v0 --disable-tests --project-dir libraries/Cabal && cabal list-bin -v0 --project-dir libraries/Cabal cabal-install:exe:cabal)
$(abspath _build/stage0/bin/cabal): _build/stage0/bin/cabal

Expand Down Expand Up @@ -225,6 +270,9 @@ _build/stage2/%: private GHC=$(realpath _build/stage1/bin/ghc)
$(addprefix _build/stage2/bin/,$(STAGE2_EXECUTABLES)) &: $(CABAL) stage1
# Force cabal to replan
rm -rf _build/stage2/cache
$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
$(CABAL_BUILD) --ghc-options="-ghcversion-file=$(abspath ./rts/include/ghcversion.h)" -W $(GHC0) rts:nonthreaded-nodebug )
Comment on lines +273 to +275
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This really feels like a bug, why do we need to build this explicitly here, why is this not brought into scope automatically?

$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage1/bin:$(PATH) \
$(CABAL_BUILD) --ghc-options="-ghcversion-file=$(abspath ./rts/include/ghcversion.h)" -W $(GHC0) $(STAGE2_TARGETS) )
Expand Down Expand Up @@ -286,6 +334,132 @@ _build/stage2/lib/template-hsc.h: utils/hsc2hs/data/template-hsc.h
.PHONY: stage2
stage2: $(addprefix _build/stage2/bin/,$(STAGE2_EXECUTABLES)) _build/stage2/lib/settings _build/stage2/lib/package.conf.d/package.cache _build/stage2/lib/template-hsc.h

# --- Stage 3 javascript build ---

.PHONY: stage3-javascript-unknown-ghcjs
stage3-javascript-unknown-ghcjs: javascript-unknown-ghcjs-libs _build/stage3/lib/targets/javascript-unknown-ghcjs/lib/package.conf.d/package.cache

_build/stage3/lib/targets/javascript-unknown-ghcjs/lib:
@mkdir -p $@
@mkdir -p _build/stage2/lib/targets/
@ln -sf ../../../stage3/lib/targets/javascript-unknown-ghcjs _build/stage2/lib/targets/javascript-unknown-ghcjs

_build/stage3/lib/targets/javascript-unknown-ghcjs/lib/settings: _build/stage3/lib/targets/javascript-unknown-ghcjs/lib _build/stage1/bin/ghc-toolchain-bin
@mkdir -p $(@D)
$(call run_and_log, _build/stage1/bin/ghc-toolchain-bin --triple javascript-unknown-ghcjs --output-settings -o $@ --cc $(EMCC) --cxx $(EMCXX) --ar $(EMAR) --ranlib $(EMRANLIB))

_build/stage3/bin/javascript-unknown-ghcjs-ghc-pkg: _build/stage2/bin/ghc-pkg
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/ghc-pkg $@

_build/stage3/bin/javascript-unknown-ghcjs-ghc: _build/stage2/bin/ghc
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/ghc $@

_build/stage3/bin/javascript-unknown-ghcjs-hsc2hs: _build/stage2/bin/hsc2hs
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/hsc2hs $@

_build/stage3/lib/targets/javascript-unknown-ghcjs/lib/package.conf.d: _build/stage3/lib/targets/javascript-unknown-ghcjs/lib
@mkdir -p $@

_build/stage3/lib/targets/javascript-unknown-ghcjs/lib/package.conf.d/package.cache: _build/stage3/bin/javascript-unknown-ghcjs-ghc-pkg _build/stage3/lib/targets/javascript-unknown-ghcjs/lib/settings javascript-unknown-ghcjs-libs
@mkdir -p $(@D)
@rm -rf $(@D)/*
cp -rfp _build/stage3/javascript-unknown-ghcjs/packagedb/host/*/* $(@D)
_build/stage3/bin/javascript-unknown-ghcjs-ghc-pkg recache

# ghc-toolchain borks unlit
_build/stage3/lib/targets/javascript-unknown-ghcjs/bin/unlit: _build/stage2/bin/unlit
@mkdir -p $(@D)
cp -rfp $< $@

.PHONY: javascript-unknown-ghcjs-libs
javascript-unknown-ghcjs-libs: private TARGET=javascript-unknown-ghcjs
javascript-unknown-ghcjs-libs: private GHC=$(abspath _build/stage3/bin/javascript-unknown-ghcjs-ghc)
javascript-unknown-ghcjs-libs: private GHC2=$(abspath _build/stage2/bin/ghc)
javascript-unknown-ghcjs-libs: private STAGE=stage3
javascript-unknown-ghcjs-libs: private CC=emcc
javascript-unknown-ghcjs-libs: _build/stage3/bin/javascript-unknown-ghcjs-ghc-pkg _build/stage3/bin/javascript-unknown-ghcjs-ghc _build/stage3/bin/javascript-unknown-ghcjs-hsc2hs _build/stage3/lib/targets/javascript-unknown-ghcjs/lib/settings _build/stage3/lib/targets/javascript-unknown-ghcjs/bin/unlit _build/stage3/lib/targets/javascript-unknown-ghcjs/lib/package.conf.d
# Force cabal to replan
rm -rf _build/stage3/javascript-unknown-ghcjs/cache
$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
$(CABAL_BUILD) -W $(GHC2) --happy-options="--template=$(abspath _build/stage2/src/happy-lib-2.1.5/data/)" --with-hsc2hs=javascript-unknown-ghcjs-hsc2hs --hsc2hs-options='-x' --configure-option='--host=javascript-unknown-ghcjs' \
$(foreach lib,$(JS_EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(JS_EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
rts:nonthreaded-nodebug )
$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
$(CABAL_BUILD) -W $(GHC2) --happy-options="--template=$(abspath _build/stage2/src/happy-lib-2.1.5/data/)" --with-hsc2hs=javascript-unknown-ghcjs-hsc2hs --hsc2hs-options='-x' --configure-option='--host=javascript-unknown-ghcjs' \
$(foreach lib,$(JS_EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(JS_EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
$(STAGE3_LIBS) )

# --- Stage 3 musl build ---

.PHONY: stage3-x86_64-unknown-linux-musl
stage3-x86_64-unknown-linux-musl: x86_64-unknown-linux-musl-libs _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/package.conf.d/package.cache

_build/stage3/lib/targets/x86_64-unknown-linux-musl/lib:
@mkdir -p $@
@mkdir -p _build/stage2/lib/targets/
@ln -sf ../../../stage3/lib/targets/x86_64-unknown-linux-musl _build/stage2/lib/targets/x86_64-unknown-linux-musl

_build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/settings: _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib _build/stage1/bin/ghc-toolchain-bin
@mkdir -p $(@D)
$(call run_and_log, _build/stage1/bin/ghc-toolchain-bin --triple x86_64-unknown-linux-musl --output-settings -o $@ --cc x86_64-unknown-linux-musl-cc --cxx x86_64-unknown-linux-musl-c++ --ar x86_64-unknown-linux-musl-ar --ranlib x86_64-unknown-linux-musl-ranlib --ld x86_64-unknown-linux-musl-ld)

_build/stage3/bin/x86_64-unknown-linux-musl-ghc-pkg: _build/stage2/bin/ghc-pkg
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/ghc-pkg $@

_build/stage3/bin/x86_64-unknown-linux-musl-ghc: _build/stage2/bin/ghc
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/ghc $@

_build/stage3/bin/x86_64-unknown-linux-musl-hsc2hs: _build/stage2/bin/hsc2hs
@mkdir -p $(@D)
@ln -sf ../../stage2/bin/hsc2hs $@

_build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/package.conf.d: _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib
@mkdir -p $@

_build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/package.conf.d/package.cache: _build/stage3/bin/x86_64-unknown-linux-musl-ghc-pkg _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/settings x86_64-unknown-linux-musl-libs
@mkdir -p $(@D)
@rm -rf $(@D)/*
cp -rfp _build/stage3/x86_64-unknown-linux-musl/packagedb/host/*/* $(@D)
_build/stage3/bin/x86_64-unknown-linux-musl-ghc-pkg recache

# ghc-toolchain borks unlit
_build/stage3/lib/targets/x86_64-unknown-linux-musl/bin/unlit: _build/stage2/bin/unlit
@mkdir -p $(@D)
cp -rfp $< $@

.PHONY: x86_64-unknown-linux-musl-libs
x86_64-unknown-linux-musl-libs: private TARGET=x86_64-unknown-linux-musl
x86_64-unknown-linux-musl-libs: private GHC=$(abspath _build/stage3/bin/x86_64-unknown-linux-musl-ghc)
x86_64-unknown-linux-musl-libs: private GHC2=$(abspath _build/stage2/bin/ghc)
x86_64-unknown-linux-musl-libs: private STAGE=stage3
x86_64-unknown-linux-musl-libs: private CC=x86_64-unknown-linux-musl-cc
x86_64-unknown-linux-musl-libs: _build/stage3/bin/x86_64-unknown-linux-musl-ghc-pkg _build/stage3/bin/x86_64-unknown-linux-musl-ghc _build/stage3/bin/x86_64-unknown-linux-musl-hsc2hs _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/settings _build/stage3/lib/targets/x86_64-unknown-linux-musl/bin/unlit _build/stage3/lib/targets/x86_64-unknown-linux-musl/lib/package.conf.d
# Force cabal to replan
rm -rf _build/stage3/x86_64-unknown-linux-musl/cache
$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
$(CABAL_BUILD) -W $(GHC2) --happy-options="--template=$(abspath _build/stage2/src/happy-lib-2.1.5/data/)" --with-hsc2hs=x86_64-unknown-linux-musl-hsc2hs --hsc2hs-options='-x' --with-ld=x86_64-unknown-linux-musl-ld --configure-option='--host=x86_64-unknown-linux-musl' \
$(foreach lib,$(MUSL_EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(MUSL_EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
rts:nonthreaded-nodebug )
$(call run_and_log, HADRIAN_SETTINGS='$(HADRIAN_SETTINGS)' \
PATH=$(PWD)/_build/stage2/bin:$(PWD)/_build/stage3/bin:$(PATH) \
$(CABAL_BUILD) -W $(GHC2) --happy-options="--template=$(abspath _build/stage2/src/happy-lib-2.1.5/data/)" --with-hsc2hs=x86_64-unknown-linux-musl-hsc2hs --hsc2hs-options='-x' --with-ld=x86_64-unknown-linux-musl-ld --configure-option='--host=x86_64-unknown-linux-musl' \
$(foreach lib,$(MUSL_EXTRA_LIB_DIRS),--extra-lib-dirs=$(lib)) \
$(foreach include,$(MUSL_EXTRA_INCLUDE_DIRS),--extra-include-dirs=$(include)) \
$(STAGE3_LIBS) )

# --- Bindist ---

# Target for creating the final binary distribution directory
_build/bindist: stage2 driver/ghc-usage.txt driver/ghci-usage.txt
@echo "Creating binary distribution in _build/bindist"
Expand Down Expand Up @@ -335,6 +509,12 @@ clean-stage2:
rm -rf _build/stage2
@echo ">>> Stage2 build artifacts cleaned."

clean-stage3:
@echo ">>> Cleaning stage3 build artifacts..."
rm -rf _build/stage3
rm -rf _build/stage2/lib/targets
@echo ">>> Stage3 build artifacts cleaned."

distclean: clean
@echo ">>> Cleaning all generated files (distclean)..."
rm -rf autom4te.cache
Expand All @@ -357,4 +537,4 @@ test: _build/bindist
make -C testsuite/tests test THREADS=${THREADS}

# Inform Make that these are not actual files if they get deleted by other means
.PHONY: clean distclean test all configure
.PHONY: clean clean-stage1 clean-stage2 clean-stage3 distclean test all configure
17 changes: 9 additions & 8 deletions cabal.project.stage2
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ packages:
libraries/ghc-experimental
libraries/base
compiler
ghc
libraries/ghc-platform
libraries/ghc-compact
libraries/ghc-bignum
Expand All @@ -22,13 +23,6 @@ packages:
libraries/template-haskell
libraries/hpc
libraries/system-cxx-std-lib
ghc
utils/ghc-pkg
utils/hsc2hs
utils/unlit
utils/genprimopcode
utils/deriveConstants
utils/ghc-toolchain
libraries/array
libraries/binary
libraries/bytestring
Expand All @@ -50,12 +44,20 @@ packages:
libraries/unix
libraries/xhtml
libraries/Win32

libraries/Cabal/Cabal-syntax
libraries/Cabal/Cabal
https://hackage.haskell.org/package/alex-3.5.2.0/alex-3.5.2.0.tar.gz
https://hackage.haskell.org/package/happy-2.1.5/happy-2.1.5.tar.gz
https://hackage.haskell.org/package/happy-lib-2.1.5/happy-lib-2.1.5.tar.gz

utils/genprimopcode
utils/deriveConstants
utils/ghc-pkg
utils/hsc2hs
utils/unlit
utils/ghc-toolchain

libraries/haskeline
libraries/terminfo
utils/hp2ps
Expand All @@ -64,7 +66,6 @@ packages:
utils/genapply
utils/runghc


-- project-rts
benchmarks: False
tests: False
Expand Down
Loading
Loading