This repository has been archived on 2021-10-25. You can view files and clone it, but cannot push or open issues/pull-requests.
rusty-bever/Makefile

86 lines
2.3 KiB
Makefile
Raw Normal View History

2021-08-28 14:20:51 +02:00
PQ_VER ?= 11.12
2021-08-28 12:41:43 +02:00
SSL_VER ?= 1.1.1k
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
# Generated variables for ease of use
2021-08-28 14:20:51 +02:00
# This is such a lovely oneliner
# NOTE: $(dir PATH) outputs a trailing slash
OUT_DIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))out
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 13:53:13 +02:00
CORES != nproc
2021-08-28 14:20:51 +02:00
2021-08-28 13:53:13 +02:00
export CC=musl-gcc -fPIC -pie -static
export LD_LIBRARY_PATH=$(PREFIX)
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig
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
.PHONY: all
2021-08-28 14:20:51 +02:00
all: build
# libpq builds openssl as a dependency
.PHONY: build
build: libpq
2021-08-28 12:41:43 +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" | \
tar -C "$(OUT_DIR)" -xz
2021-08-28 13:53:13 +02:00
cd "$(OPENSSL_DIR)" && \
CC="$$CC -idirafter /usr/include" ./Configure \
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
C_INCLUDE_PATH="$(PREFIX)/include" $(MAKE) -C "$(OPENSSL_DIR)" depend
$(MAKE) -C "$(OPENSSL_DIR)" -j$(CORES)
$(MAKE) -C "$(OPENSSL_DIR)" install_sw
# =====LIBPQ=====
# 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" | \
tar -C "$(OUT_DIR)" -xz
cd "$(PQ_DIR)" && \
LDFLAGS="-L$(PREFIX)/lib" CFLAGS="-I$(PREFIX)/include" ./configure \
--without-readline \
--without-zlib \
--with-openssl \
--prefix="$(PREFIX)" \
--host=x86_64-unknown-linux-musl
2021-08-28 14:20:51 +02:00
.PHONY: libpq
libpq: openssl $(PQ_DIR)/configure
2021-08-28 13:53:13 +02:00
make -C "$(PQ_DIR)/src/interfaces/libpq" -j$(CORES) all-static-lib
make -C "$(PQ_DIR)/src/interfaces/libpq" install install-lib-static
make -C "$(PQ_DIR)/src/bin/pg_config" -j $(CORES)
make -C "$(PQ_DIR)/src/bin/pg_config" install
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
dumb-init: $(DI_DIR)/Makefile
make -C "$(DI_DIR)" build