rusty-bever/Makefile

141 lines
3.5 KiB
Makefile
Raw Normal View History

2021-08-28 16:37:32 +02:00
# =====CONFIGURATION=====
# Version of postgresql to compile libpq from
2021-08-28 14:20:51 +02:00
PQ_VER ?= 11.12
2021-08-28 16:37:32 +02:00
# OpenSSL version
2021-08-28 12:41:43 +02:00
SSL_VER ?= 1.1.1k
2021-08-28 16:37:32 +02:00
# Dumb-init version
2021-08-28 14:20:51 +02:00
DI_VER ?= 1.2.5
2021-08-28 12:41:43 +02:00
2021-08-28 13:53:13 +02:00
2021-08-28 16:37:32 +02:00
# =====AUTO-GENERATED VARIABLES=====
2021-08-28 14:20:51 +02:00
# This is such a lovely oneliner
# NOTE: $(dir PATH) outputs a trailing slash
2021-08-28 16:37:32 +02:00
OUT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))out
2021-08-28 14:20:51 +02:00
PREFIX := $(OUT_DIR)/prefix
2021-08-28 13:53:13 +02:00
OPENSSL_DIR := $(OUT_DIR)/openssl-$(SSL_VER)
2021-08-28 14:20:51 +02:00
PQ_DIR := $(OUT_DIR)/postgresql-$(PQ_VER)
DI_DIR := $(OUT_DIR)/dumb-init-$(DI_VER)
2021-08-28 16:37:32 +02:00
# Used in various make calls to specify parallel recipes
CORES != nproc
2021-08-28 13:53:13 +02:00
2021-08-28 14:20:51 +02:00
2021-08-28 16:37:32 +02:00
# =====ENVIRONMENT VARIABLES=====
2021-09-05 11:19:18 +02:00
export CC := musl-gcc -fPIC -pie -static
export LD_LIBRARY_PATH := $(PREFIX)
export PKG_CONFIG_PATH := /usr/local/lib/pkgconfig
2021-09-05 09:59:16 +02:00
export PATH := /usr/local/bin:/root/.cargo/bin:$(PATH)
2021-08-28 12:41:43 +02:00
# TODO check for header files (openssl-dev, libpq-dev) both for Arch & Ubuntu
2021-08-28 13:53:13 +02:00
# Create the out dir
$(shell mkdir -p "$(PREFIX)")
2021-08-28 12:41:43 +02:00
2021-08-28 16:37:32 +02:00
2021-09-05 11:19:18 +02:00
# =====BUILDING THE STATIC BINARY=====
2021-08-28 12:41:43 +02:00
.PHONY: all
2021-08-28 14:20:51 +02:00
all: build
2021-09-05 11:19:18 +02:00
.PHONY: builder
builder:
docker build \
-t rusty-builder:latest - < docker/Dockerfile.builder
2021-09-05 09:59:16 +02:00
.PHONY: docker
2021-09-05 11:19:18 +02:00
docker: builder
2021-09-05 09:59:16 +02:00
docker run \
--rm \
-v "$$PWD:/usr/src" \
--workdir "/usr/src" \
-it \
2021-09-05 11:19:18 +02:00
rusty-builder:latest \
2021-09-05 09:59:16 +02:00
bash build.sh
2021-08-28 14:20:51 +02:00
# libpq builds openssl as a dependency
.PHONY: build
build: libpq
2021-08-28 12:41:43 +02:00
2021-08-28 16:37:32 +02:00
.PHONY: clean
2021-09-05 11:19:18 +02:00
clean: clean-openssl clean-libpq clean-di
2021-08-28 16:37:32 +02:00
@ echo "Note: this only cleans the C dependencies, not the Cargo cache."
2021-09-05 11:19:18 +02:00
rm -rf "$(PREFIX)"
2021-08-28 16:37:32 +02:00
2021-09-05 09:59:16 +02:00
# This is used inside the Dockerfile
.PHONY: pathfile
pathfile:
echo "$(PREFIX)/lib" >> /etc/ld-musl-x86_64.path
2021-08-28 12:41:43 +02:00
2021-09-05 11:19:18 +02:00
## =====OPENSSL=====
2021-08-28 13:53:13 +02:00
# Download the source code & configure the project
$(OPENSSL_DIR)/Configure:
2021-08-28 12:41:43 +02:00
curl -sSL "https://www.openssl.org/source/openssl-$(SSL_VER).tar.gz" | \
2021-09-05 11:19:18 +02:00
tar -xzC "$(OUT_DIR)"
2021-08-28 13:53:13 +02:00
cd "$(OPENSSL_DIR)" && \
2021-09-05 11:19:18 +02:00
CC="$(CC) -idirafter /usr/include -idirafter /usr/include/x86_64-linux-gnu/" ./Configure \
2021-08-28 13:53:13 +02:00
no-zlib \
no-shared \
--prefix="$(PREFIX)" \
--openssldir="$(PREFIX)/ssl" \
linux-x86_64
2021-08-28 12:41:43 +02:00
# Build OpenSSL
2021-08-28 14:20:51 +02:00
.PHONY: openssl
2021-08-28 13:53:13 +02:00
openssl: $(OPENSSL_DIR)/Configure
2021-09-05 11:19:18 +02:00
cd "$(OPENSSL_DIR)" && env C_INCLUDE_PATH="$(PREFIX)/include" $(MAKE) depend 2> /dev/null
cd "$(OPENSSL_DIR)" && $(MAKE) -j$(CORES)
cd "$(OPENSSL_DIR)" && $(MAKE) install_sw
2021-08-28 13:53:13 +02:00
2021-09-05 11:19:18 +02:00
.PHONY: clean-openssl
clean-openssl:
rm -rf "$(OPENSSL_DIR)"
2021-08-28 13:53:13 +02:00
2021-09-05 11:19:18 +02:00
## =====LIBPQ=====
2021-08-28 13:53:13 +02:00
# Download the source code & configure the project
$(PQ_DIR)/configure:
curl -sSL "https://ftp.postgresql.org/pub/source/v$(PQ_VER)/postgresql-$(PQ_VER).tar.gz" | \
2021-09-05 11:19:18 +02:00
tar -xzC "$(OUT_DIR)"
2021-08-28 13:53:13 +02:00
cd "$(PQ_DIR)" && \
LDFLAGS="-L$(PREFIX)/lib" CFLAGS="-I$(PREFIX)/include" ./configure \
--without-readline \
--with-openssl \
2021-08-28 16:37:32 +02:00
--without-zlib \
2021-08-28 13:53:13 +02:00
--prefix="$(PREFIX)" \
--host=x86_64-unknown-linux-musl
2021-08-28 14:20:51 +02:00
.PHONY: libpq
libpq: openssl $(PQ_DIR)/configure
2021-09-05 11:19:18 +02:00
cd "$(PQ_DIR)/src/interfaces/libpq" && $(MAKE) -j$(CORES) all-static-lib
cd "$(PQ_DIR)/src/interfaces/libpq" && $(MAKE) install install-lib-static
cd "$(PQ_DIR)/src/bin/pg_config" && $(MAKE) -j$(CORES)
cd "$(PQ_DIR)/src/bin/pg_config" && $(MAKE) install
.PHONY: clean-libpq
clean-libpq:
rm -rf "$(PQ_DIR)"
2021-08-28 14:20:51 +02:00
# =====DUMB-INIT=====
# NOTE: this is only used inside the Docker image, but it's here for completeness.
$(DI_DIR)/Makefile:
curl -sSL "https://github.com/Yelp/dumb-init/archive/refs/tags/v$(DI_VER).tar.gz" | \
tar -C "$(OUT_DIR)" -xz
2021-09-05 11:19:18 +02:00
.PHONY: di
di: $(DI_DIR)/Makefile
2021-08-28 14:20:51 +02:00
make -C "$(DI_DIR)" build
2021-09-05 11:19:18 +02:00
.PHONY: clean-di
clean-di:
rm -rf "$(DI_DIR)"
# ====UTILITIES FOR DEVELOPMENT=====
## The tests require a database, so we run them like this
test:
docker-compose -f docker-compose.test.yml -p rb_test up