Makefile: Add cross-compilation targets

This commit is contained in:
Samantaz Fox 2023-09-16 23:33:40 +02:00
parent cc03610325
commit c9fae2816d
No known key found for this signature in database
GPG Key ID: F42821059186176E

101
Makefile
View File

@ -9,6 +9,7 @@ NO_DBG_SYMBOLS := 0
FLAGS ?= FLAGS ?=
LDFLAGS ?=
ifeq ($(RELEASE), 1) ifeq ($(RELEASE), 1)
@ -17,6 +18,7 @@ endif
ifeq ($(STATIC), 1) ifeq ($(STATIC), 1)
FLAGS += --static FLAGS += --static
LDFLAGS += -static
endif endif
@ -31,6 +33,13 @@ ifeq ($(API_ONLY), 1)
endif endif
#FLAGS += --progress --stats --error-trace
LIBS_SSL = $(shell command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libssl || printf %s '-lssl -lcrypto')
LIBS_CRYPTO = $(shell command -v pkg-config > /dev/null && pkg-config --libs --silence-errors libcrypto || printf %s '-lcrypto')
# ----------------------- # -----------------------
# Main # Main
# ----------------------- # -----------------------
@ -40,19 +49,80 @@ all: invidious
get-libs: get-libs:
shards install --production shards install --production
# TODO: add support for ARM64 via cross-compilation
invidious: get-libs invidious: get-libs
crystal build src/invidious.cr $(FLAGS) --progress --stats --error-trace crystal build src/invidious.cr $(FLAGS)
run: invidious run: invidious
./invidious ./invidious
# ----------------------- # -----------------------
# Development # Cross-compilation (Host)
# ----------------------- # -----------------------
# Supported cross-sompilation targets:
# - amd64-glibc (x86_64-linux-gnu)
# - amd64-musl (x86_64-linux-musl)
# - arm64-glibc (aarch64-linux-gnu)
# - arm64-musl (aarch64-linux-musl)
# - armhf (arm-linux-gnueabihf)
invidious-cross-amd64-glibc:
crystal build src/invidious.cr $(FLAGS) -Dskip_videojs_download \
--cross-compile --target='x86_64-linux-gnu' -o invidious-amd64-glibc
invidious-cross-amd64-musl:
crystal build src/invidious.cr $(FLAGS) -Dskip_videojs_download \
--cross-compile --target='x86_64-linux-musl' -o invidious-amd64-musl
invidious-cross-arm64-glibc:
crystal build src/invidious.cr $(FLAGS) -Dskip_videojs_download \
--cross-compile --target='aarch64-linux-gnu' -o invidious-arm64-glibc
invidious-cross-arm64-musl:
crystal build src/invidious.cr $(FLAGS) -Dskip_videojs_download \
--cross-compile --target='aarch64-linux-musl' -o invidious-arm64-musl
invidious-cross-armhf:
crystal build src/invidious.cr $(FLAGS) -Dskip_videojs_download \
--cross-compile --target='arm-linux-gnueabihf' -o invidious-armhf
# Build everything at once
invidious-cross-all: invidious-cross-amd64-glibc
invidious-cross-all: invidious-cross-amd64-musl
invidious-cross-all: invidious-cross-arm64-glibc
invidious-cross-all: invidious-cross-arm64-musl
invidious-cross-all: invidious-cross-armhf
# -----------------------
# Cross-compilation (Target)
# -----------------------
invidious-amd64-glibc:
invidious-arm64-glibc:
cc "$@.o" -o "$@" -rdynamic $(LDFLAGS) \
-lyaml -lxml2 -lsqlite3 -lz -llzma $(LIBS_SSL) $(LIBS_CRYPTO) \
-lpcre -lm -lgc -lpthread -levent -lrt -lpthread -ldl
invidious-amd64-musl:
invidious-arm64-musl:
cc "$@.o" -o "$@" -rdynamic $(LDFLAGS) \
-lyaml -lxml2 -lsqlite3 -lz -llzma $(LIBS_SSL) $(LIBS_CRYPTO) \
-lpcre -lgc -levent
invidious-armhf:
cc "$@.o" -o "$@" -rdynamic $(LDFLAGS) \
-lyaml -lxml2 -lsqlite3 -lz -llzma $(LIBS_SSL) $(LIBS_CRYPTO) \
-lpcre -lm -lgc -lpthread -levent -lpthread -ldl
# -----------------------
# Development
# -----------------------
format: format:
crystal tool format crystal tool format
@ -77,7 +147,7 @@ verify:
# ----------------------- # -----------------------
clean: clean:
rm invidious rm -f invidious invidious-*
distclean: clean distclean: clean
rm -rf libs rm -rf libs
@ -111,9 +181,28 @@ help:
@echo "" @echo ""
@echo " API_ONLY Build invidious without a GUI (Default: 0)" @echo " API_ONLY Build invidious without a GUI (Default: 0)"
@echo " NO_DBG_SYMBOLS Strip debug symbols (Default: 0)" @echo " NO_DBG_SYMBOLS Strip debug symbols (Default: 0)"
@echo ""
@echo ""
@echo "Cross-compiling"
@echo ""
@echo "To cross compile, run 'make invidious-cross-{arch}' on the build host,"
@echo "then move the .o file to the target host and run 'make invidious-{arch}'"
@echo "on there (requires crystal and all the dependencies to be installed)"
@echo ""
@echo "Note: If 'STATIC=1' was used on the build host, then it MUST be used on"
@echo " 'the target host too!"
@echo ""
@echo "Supported cross-sompilation archs:"
@echo " - amd64-glibc (x86_64-linux-gnu)"
@echo " - amd64-musl (x86_64-linux-musl)"
@echo " - arm64-glibc (aarch64-linux-gnu)"
@echo " - arm64-musl (aarch64-linux-musl)"
@echo " - armhf (arm-linux-gnueabihf)"
# No targets generates an output named after themselves # No targets generates an output named after themselves
.PHONY: all get-libs build amd64 run .PHONY: all get-libs build amd64 run
.PHONY: format test verify clean distclean help .PHONY: format test verify clean distclean help
.PHONY: invidious-cross-amd64-glibc invidious-cross-amd64-musl
.PHONY: invidious-cross-arm64-glibc invidious-cross-arm64-musl
.PHONY: invidious-cross-armhf