Skip to content

Commit

Permalink
release: add rules for local host building
Browse files Browse the repository at this point in the history
we don't have all targets containerised yet.
  • Loading branch information
AltGr committed Aug 23, 2017
1 parent 2de7cd1 commit 26c2454
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 36 deletions.
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,17 @@ src_ext/jbuilder.stamp:
$(MAKE) -C src_ext jbuilder.stamp

jbuilder: $(JBUILDER_DEP)
@$(JBUILDER) build @install
@$(JBUILDER) build $(JBUILDER_ARGS) @install

opam: $(JBUILDER_DEP) opam.install
ln -sf _build/default/src/client/opamMain.exe $@

opam-installer: $(JBUILDER_DEP)
$(JBUILDER) build src/tools/opam_installer.exe
$(JBUILDER) build $(JBUILDER_ARGS) src/tools/opam_installer.exe
ln -sf _build/default/src/tools/opam_installer.exe $@

opam-admin.top: $(JBUILDER_DEP)
$(JBUILDER) build src/tools/opam_admin_top.bc
$(JBUILDER) build $(JBUILDER_ARGS) src/tools/opam_admin_top.bc
ln -sf _build/default/src/tools/opam_admin_top.bc $@

lib-ext:
Expand Down Expand Up @@ -78,14 +78,14 @@ ifneq ($(LIBINSTALL_DIR),)
endif

opam-devel.install: $(JBUILDER_DEP)
$(JBUILDER) build -p opam opam.install
$(JBUILDER) build $(JBUILDER_ARGS) -p opam opam.install
sed -e "s/bin:/libexec:/" opam.install > $@

opam-%.install: $(JBUILDER_DEP)
$(JBUILDER) build -p opam-$* $@
$(JBUILDER) build $(JBUILDER_ARGS) -p opam-$* $@

opam.install: $(JBUILDER_DEP)
$(JBUILDER) build $@
$(JBUILDER) build $(JBUILDER_ARGS) $@

opam-actual.install: opam.install
@sed -n -e "/^bin: /,/^]/p" $< > $@
Expand All @@ -102,35 +102,35 @@ opam-actual.install: opam.install
OPAMLIBS = core format solver repository state client

opam-%: $(JBUILDER_DEP)
$(JBUILDER) build opam-$*.install
$(JBUILDER) build $(JBUILDER_ARGS) opam-$*.install

opam-lib: $(JBUILDER_DEP)
$(JBUILDER) build $(patsubst %,opam-%.install,$(OPAMLIBS))
$(JBUILDER) build $(JBUILDER_ARGS) $(patsubst %,opam-%.install,$(OPAMLIBS))

installlib-%: $(JBUILDER_DEP) opam-installer opam-%.install
$(if $(wildcard src_ext/lib/*),\
$(error Installing the opam libraries is incompatible with embedding \
the dependencies. Run 'make clean-ext' and try again))
$(JBUILDER) exec -- opam-installer $(OPAMINSTALLER_FLAGS) opam-$*.install
$(JBUILDER) exec $(JBUILDER_ARGS) -- opam-installer $(OPAMINSTALLER_FLAGS) opam-$*.install

uninstalllib-%: $(JBUILDER_DEP) opam-installer opam-%.install
$(JBUILDER) exec -- opam-installer -u $(OPAMINSTALLER_FLAGS) opam-$*.install
$(JBUILDER) exec $(JBUILDER_ARGS) -- opam-installer -u $(OPAMINSTALLER_FLAGS) opam-$*.install

libinstall: $(JBUILDER_DEP) opam-admin.top $(OPAMLIBS:%=installlib-%)
@

install: opam-actual.install $(JBUILDER_DEP)
$(JBUILDER) exec -- opam-installer $(OPAMINSTALLER_FLAGS) $<
$(JBUILDER) exec $(JBUILDER_ARGS) -- opam-installer $(OPAMINSTALLER_FLAGS) $<

libuninstall: $(OPAMLIBS:%=uninstalllib-%)
@

uninstall: opam-actual.install $(JBUILDER_DEP)
$(JBUILDER) exec -- opam-installer -u $(OPAMINSTALLER_FLAGS) $<
$(JBUILDER) exec $(JBUILDER_ARGS) -- opam-installer -u $(OPAMINSTALLER_FLAGS) $<

.PHONY: tests tests-local tests-git
tests: $(JBUILDER_DEP)
$(JBUILDER) runtest
$(JBUILDER) runtest $(JBUILDER_ARGS)

# tests-local, tests-git
tests-%:
Expand Down
94 changes: 71 additions & 23 deletions release/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,70 +2,118 @@ TAG = master
VERSION = $(shell git describe $(TAG) | sed 's/-/~/')
GIT_URL = ..

FULL_ARCHIVE_URL = https://github.com/ocaml/opam/releases/download/$(VERSION)/opam-full-$(VERSION).tar.gz

TARGETS = x86_64-linux i686-linux armhf-linux arm64-linux
# todo: x86_64-darwin

OCAMLV = 4.04.2
# currently hardcoded in Dockerfile.in
OCAML_URL = https://caml.inria.fr/pub/distrib/ocaml-$(basename $(OCAMLV))/ocaml-$(OCAMLV).tar.gz

HOST_OS = $(shell uname -s | tr A-Z a-z)
HOST = $(shell uname -m)-$(HOST_OS)

all: $(patsubst %,out/opam-$(VERSION)-%,$(TARGETS))

out/opam-full-$(VERSION).tar.gz:
mkdir -p out
git clone $(GIT_URL) -b $(TAG) --depth 1 opam-full-$(VERSION)
sed -i 's/^AC_INIT(opam,.*)/AC_INIT(opam,'"$(VERSION)"')/' \
opam-full-$(VERSION)/configure.ac
cd opam-full-$(VERSION) && $(MAKE) configure download-ext
tar cz --exclude-vcs opam-full-$(VERSION) -f $@
rm -rf opam-full-$(VERSION)
cd out && curl -OL $(FULL_ARCHIVE_URL) || { \
git clone $(GIT_URL) -b $(TAG) --depth 1 opam-full-$(VERSION); \
sed -i 's/^AC_INIT(opam,.*)/AC_INIT(opam,$(VERSION))/' \
opam-full-$(VERSION)/configure.ac; \
cd opam-full-$(VERSION) && $(MAKE) configure download-ext; \
tar cz --exclude-vcs opam-full-$(VERSION) -f $@; \
rm -rf opam-full-$(VERSION); \
}

build/Dockerfile.x86_64-linux: Dockerfile.in
mkdir -p build && sed 's/%TARGET_TAG%/amd64-jessie/g' $^ | sed 's/%CONF%//' >$@
mkdir -p build && sed 's/%TARGET_TAG%/amd64-jessie/g' $^ | sed 's/%CONF%//g' >$@
build/Dockerfile.i686-linux: Dockerfile.in
mkdir -p build && sed 's/%TARGET_TAG%/i386-jessie/g' $^ | sed 's/%CONF%/-host i686-linux/' >$@
mkdir -p build && sed 's/%TARGET_TAG%/i386-jessie/g' $^ | sed 's/%CONF%/-host i686-linux/g' >$@
build/Dockerfile.armhf-linux: Dockerfile.in
mkdir -p build && sed 's/%TARGET_TAG%/armhf-jessie/g' $^ | sed 's/%CONF%//' >$@
mkdir -p build && sed 's/%TARGET_TAG%/armhf-jessie/g' $^ | sed 's/%CONF%//g' >$@
build/Dockerfile.arm64-linux: Dockerfile.in
mkdir -p build && sed 's/%TARGET_TAG%/arm64-jessie/g' $^ | sed 's/%CONF%//' >$@
mkdir -p build && sed 's/%TARGET_TAG%/arm64-jessie/g' $^ | sed 's/%CONF%//g' >$@


build/%.image: build/Dockerfile.%
docker build -t opam-build-$* -f $^ build
touch $@

CLINKING_jessie = \
# Actually, this is for debian 8 jessie, and varies wildly
CLINKING_linux = \
-Wl,-Bstatic \
-lunix -lbigarray -lmccs_stubs \
-lglpk -lstdc++ -lz -lamd -lcolamd -lltdl \
-Wl,-Bdynamic \
-static-libgcc
LINKING_jessie = -noautolink $(patsubst %,-cclib %,$(CLINKING_jessie))

CLINKING_darwin = \
-lunix -lbigarray -lmccs_stubs \
/usr/local/lib/libglpk.a -lz -lstdc++
LINKING_darwin = -noautolink $(patsubst %,-cclib %,$(CLINKING_darwin))

CLINKING_openbsd = $(CLINKING_darwin)

EXPORTS_openbsd = \
CPATH=/usr/local/include: \
LIBRARY_PATH=/usr/local/lib: \


%: opam-$(VERSION)-%

opam-$(VERSION)-%: out/opam-$(VERSION)-%
ln -sf $^ $@

host: opam-$(VERSION)-$(HOST)

# Build for the local host. Containerised builds, below, are preferred, but not always available
build/$(HOST).env:
mkdir -p build/$(HOST)
cd build/$(HOST) && curl -OL $(OCAML_URL)
cd build/$(HOST) && tar xzf ocaml-$(OCAMLV).tar.gz
cd build/$(HOST)/ocaml-$(OCAMLV) && \
./configure -prefix $(shell pwd)/build/$(HOST) && \
$(MAKE) world opt.opt && \
$(MAKE) install
rm -rf build/$(HOST)/ocaml-$(OCAMLV) build/$(HOST)/ocaml-$(OCAMLV).tar.gz
touch $@

out/opam-$(VERSION)-$(HOST): out/opam-full-$(VERSION).tar.gz build/$(HOST).env
cd build && tar xzf ../$<
( export \
PATH=$(shell pwd)/build/$(HOST)/bin:$$PATH \
MAKE=$(MAKE) \
$(EXPORTS_$(HOST_OS)); \
cd build/opam-full-$(VERSION) && \
./configure --with-glpk && \
echo "(-noautolink $(patsubst %,-cclib %,$(CLINKING_$(HOST_OS))))" \
>src/client/linking.sexp && \
$(MAKE) lib-ext opam JBUILDER_ARGS="--root=`pwd`"; \
)
strip build/opam-full-$(VERSION)/opam
cp build/opam-full-$(VERSION)/opam out/opam-$(VERSION)-$(HOST)
rm -rf build/opam-full-$(VERSION)

# Containerised builds
out/opam-$(VERSION)-%-linux: build/%-linux.image out/opam-full-$(VERSION).tar.gz
docker run --rm -v `pwd`/out:/src \
-e "VERSION=$(VERSION)" \
-e "TARGET=$*-linux" \
-e "LINKING=$(LINKING_jessie)" \
opam-build-$*-linux

out/opam-$(VERSION)-%-darwin: opam-full-$(VERSION).tar.gz
@error todo generate appropriate reproducible build env with ocaml 4.04, and fail if not available
tar xzf $^
cd opam-full-$(VERSION) && \
./configure --with-mccs && \
echo "($(LINKING_darwin))" > src/client/linking.sexp && \
make lib-ext opam
cp opam-full-$(VERSION)/opam opam-$(VERSION)-$*-darwin
rm -rf opam-full-$(VERSION)

clean:
rm -rf build

distclean: clean
rm -rf out

REMOTE_DIR = /tmp/opam-release
REMOTE_MAKE = gmake
remote: out/opam-full-$(VERSION).tar.gz
ssh "$(REMOTE)" "mkdir -p $(REMOTE_DIR)/out"
scp Makefile "$(REMOTE):$(REMOTE_DIR)/"
scp "$^" "$(REMOTE):$(REMOTE_DIR)/$^"
ssh "$(REMOTE)" 'sh -c "cd $(REMOTE_DIR) && $(REMOTE_MAKE) host TAG=$(TAG) VERSION=$(VERSION) OCAMLV=$(OCAMLV)"'
scp "$(REMOTE):$(REMOTE_DIR)/out/opam-$(VERSION)*" out/

0 comments on commit 26c2454

Please sign in to comment.