For a project of mine I use the following Makefile code to create binaries for different platforms:
VERSION=$(shell cat VERSION)
TARGET ?= x86_64-linux
NICE_TARGET ?= ${TARGET}
VM ?= cs
# Both options are allowed for Posix and Windows.
TARGET_OPTS ?= --orig-exe --embed-dlls
# `raco exe` appends `.exe` for Windows automatically.
EXE_NAME := sudoku-solver-${VERSION}-${NICE_TARGET}
EXE_PATH := build/${NICE_TARGET}/${EXE_NAME}
# Build standalone binary.
.PHONY : build
build:
mkdir -p "build/${NICE_TARGET}"
# Ignore uninstalled package.
-raco cross --target "${TARGET}" --vm ${VM} pkg remove sudoku-solver
# Implicitly install dependencies.
raco cross --target "${TARGET}" --vm ${VM} -j 4 pkg install --deps search-auto
raco cross --target "${TARGET}" --vm ${VM} -j 4 exe ${TARGET_OPTS} \
-o "${EXE_PATH}" games/sudoku-solver.rkt
.PHONY : build-x86_64-linux
build-x86_64-linux: build
.PHONY : build-x86_64-win32
build-x86_64-win32:
TARGET=x86_64-win32 NICE_TARGET=x86_64-windows make build
.PHONY : build-x86_64-macosx
build-x86_64-macosx:
TARGET=x86_64-macosx make build
.PHONY : build-aarch64-macosx
build-aarch64-macosx:
TARGET=aarch64-macosx make build
# Create standalone binaries for different platforms.
.PHONY : build-all
build-all: build-x86_64-linux build-x86_64-win32 build-x86_64-macosx \
build-aarch64-macosx
I run make build-all
from the Git working directory root of my package.
I think it would make sense to make this more standalone, i.e. usable without Make, and of course independent of a specific hardcoded project and version. I could write a command line tool in Racket for this, but before I do it, I'd like to ask if you know of something like this that exists already. I'd like to avoid double work.
As for the packaging, I guess the above is too specialized to be a part of raco cross
or even a raco
subcommand. So probably this should be a raco pkg install
-able standalone script.
What do you think?