-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenv.mk
More file actions
executable file
·99 lines (85 loc) · 4.08 KB
/
Copy pathenv.mk
File metadata and controls
executable file
·99 lines (85 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# env.mk — GNU make equivalent of scripts/env.sh for Context (ctx).
#
# Usage: make -f env.mk -f Makefile <target>
# or: -include env.mk (additive, in the repo Makefile)
#
# Everything is self-located: REPO_ROOT from this file's own path.
# Variables are set with ?= so they remain overridable from the
# command line or the including Makefile.
#
# Contract: docs/BUILD-SYSTEMS.md pattern — hosts (gcc/musl/-system × libc),
# the four rust targets, and LAYOUT_ROOT/DESTDIR semantics.
# ── Self-location ────────────────────────────────────────────────────
REPO_ROOT := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
# ── Host profile (auto-detect unless overridden) ─────────────────────
HOST ?= auto
ifeq ($(HOST),auto)
HOST := $(if $(wildcard /lib/ld-musl-*.so.1),musl,gcc)
endif
# .cargo/config.toml [build]/[target] rustflags carry the pyo3 abi3 cfg and
# per-target -C target-cpu / +crt-static entries; those are preserved as long
# as RUSTFLAGS is not forced here (RUSTFLAGS would override config.toml's).
# HOST_LIBC = musl or gcc, independent of layout suffix.
ifeq ($(findstring musl,$(HOST)),musl)
HOST_LIBC := musl
else
HOST_LIBC := gcc
endif
# LAYOUT_ROOT = /usr (normal) or /system (-system hosts).
ifeq ($(findstring system,$(HOST)),system)
LAYOUT_ROOT := /system
else
LAYOUT_ROOT := /usr
endif
# ── Host architecture (auto-detected, orthogonal to the host profile) ─
HOST_ARCH_RAW := $(shell uname -m)
ifneq ($(filter x86_64 aarch64,$(HOST_ARCH_RAW)),)
HOST_ARCH := $(HOST_ARCH_RAW)
ifeq ($(HOST_ARCH_RAW),x86_64)
HOST_ARCH_SHORT := amd64
else
HOST_ARCH_SHORT := arm64
endif
else
$(error Unsupported architecture: $(HOST_ARCH_RAW). Supported: x86_64, aarch64)
endif
# ── Cross-compilation sysroot (aarch64 targets) ──────────────────────
CROSS_INCLUDE_DIR ?= $(LAYOUT_ROOT)/aarch64-linux-gnu/include
CROSS_GCC_DIR ?= $(LAYOUT_ROOT)/lib/gcc-cross/aarch64-linux-gnu
# ── Per-target CC / CXX / AR defaults ────────────────────────────────
# musl targets: clang family
CC_x86_64_unknown_linux_musl ?= clang -target x86_64-linux-musl
CXX_x86_64_unknown_linux_musl ?= clang++ -target x86_64-linux-musl
AR_x86_64_unknown_linux_musl ?= llvm-ar-21
CC_aarch64_unknown_linux_musl ?= clang -target aarch64-linux-musl
CXX_aarch64_unknown_linux_musl ?= clang++ -target aarch64-linux-musl
AR_aarch64_unknown_linux_musl ?= llvm-ar-21
# gnu targets: gcc family
CC_x86_64_unknown_linux_gnu ?= gcc
CXX_x86_64_unknown_linux_gnu ?= g++
AR_x86_64_unknown_linux_gnu ?= ar
CC_aarch64_unknown_linux_gnu ?= aarch64-linux-gnu-gcc
CXX_aarch64_unknown_linux_gnu ?= aarch64-linux-gnu-g++
AR_aarch64_unknown_linux_gnu ?= aarch64-linux-gnu-ar
# ── pkg-config (host sysroot; layout-aware) ──────────────────────────
PKG_CONFIG_SYSROOT_DIR ?= /
PKG_CONFIG_LIBDIR ?= $(LAYOUT_ROOT)/lib/pkgconfig:$(LAYOUT_ROOT)/share/pkgconfig
PKG_CONFIG_PATH ?=
PKG_CONFIG_ALLOW_CROSS ?= 1
PKG_CONFIG_ALLOW_SYSTEM_LIBS ?= 1
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS ?= 1
PKG_CONFIG_ALLOW_SYSTEM_STATIC ?= 1
PKG_CONFIG_ALLOW_STATIC ?= 1
# ── DESTDIR defaults (per host) ──────────────────────────────────────
# Default install prefix: /usr for /usr hosts, /system for -system hosts.
DESTDIR ?=
ifeq ($(strip $(DESTDIR)),)
DESTDIR := $(LAYOUT_ROOT)
endif
# ── Man pages ────────────────────────────────────────────────────────
INSTALL_MAN ?= yes
MAN_SRC_DIR := docs
MAN_MAN1 := $(sort $(wildcard $(REPO_ROOT)/$(MAN_SRC_DIR)/ctx.1))
MANPAGES := $(MAN_MAN1)
# ── RUSTFLAGS for static musl links (opt-in, not exported globally) ──
RUSTFLAGS_TARGET_MUSL ?= -C target-feature=+crt-static