Log in
common.mk 96 lines · 4.4 KB · blame Source
Y cd6106b9b2cf Build system: split legacy into legacy/Makefile, 13 days ago
1
# Shared build configuration for Spinel.
2
#
3
# Included by both ./Makefile (the C compiler + test/bench harness) and
4
# legacy/Makefile (the legacy Ruby compiler bootstrap / self-host oracle).
5
# Keep only toolchain-level knobs here; target rules live in the two
6
# Makefiles that include this file.
7
8
# Machine-local overrides (gitignored). Lets a developer point the
9
# bootstrap at an alternative Ruby and set OPT/CC/etc. without editing
10
# committed defaults. A command-line `make VAR=...` still wins.
11
-include $(dir $(lastword $(MAKEFILE_LIST)))local.mk
12
13
CC       ?= cc
14
# Auto-wrap CC with sccache or ccache when present. Skip when CC is
15
# already wrapped β€” the substring guard catches both "ccache" and
16
# "sccache" since "ccache" is a substring of "sccache", so CI's
17
# `CC=sccache <cc>` env stays untouched. NO_CCACHE=1 opts out.
18
# `override` is required so that a command-line `make CC=gcc` is also
19
# wrapped β€” without it the wrap would be silently ignored.
20
ifeq (,$(findstring ccache,$(CC)))
21
ifeq (,$(NO_CCACHE))
22
  CCACHE_BIN := $(shell command -v sccache 2>/dev/null || command -v ccache 2>/dev/null)
23
  ifneq (,$(CCACHE_BIN))
24
    override CC := $(CCACHE_BIN) $(CC)
25
  endif
26
endif
27
endif
28
29
# Optimization level for the C compiles driven by the test/bench harness
30
# (each .rb gets parsed β†’ codegen β†’ cc'd β†’ run). CI overrides this to -O0
31
# to cut cc time; locally -O2 keeps the test binaries reasonable-speed.
32
# `-Wno-alloc-size-larger-than` silences a gcc 13+ paranoia warning on the
33
# inlined `h->cap *= 2` in sp_*Hash_grow; `-Wno-unknown-warning-option`
34
# keeps clang (which lacks that flag) from turning it into a -Werror fail.
Y 003c30228b13 build: silence gcc -Wformat-truncation on benign 7 days ago
35
# `-Wno-format-truncation` silences gcc's FORTIFY-driven paranoia on benign
36
# `snprintf(buf, sizeof buf, "@%s", name)` ivar/path builds (the buffers are
37
# sized for real identifiers; the warning fires independently of -Wall under
38
# _FORTIFY_SOURCE, so -Wno-all does not cover it). clang lacks the flag and
39
# ignores it via -Wno-unknown-warning-option above.
Y cd6106b9b2cf Build system: split legacy into legacy/Makefile, 13 days ago
40
OPT     ?= -O2
Y 003c30228b13 build: silence gcc -Wformat-truncation on benign 7 days ago
41
CFLAGS   = $(OPT) -Wno-all -Wno-unknown-warning-option -Wno-alloc-size-larger-than -Wno-format-truncation
Y cd6106b9b2cf Build system: split legacy into legacy/Makefile, 13 days ago
42
43
# Bootstrap-only flags: the legacy compiler runs on the developer's
44
# machine only, so -O3 -flto buys ~5-10% wall-clock without constraining
45
# users (whose generated C is built with plain CFLAGS). Override with
46
# LTO=0 on toolchains without LTO, or for a faster debug relink.
47
LTO     ?= 1
48
ifeq ($(LTO),1)
49
  BOOTSTRAP_CFLAGS = -O3 -flto=auto -Wno-all
50
else
51
  BOOTSTRAP_CFLAGS = $(CFLAGS)
52
endif
53
54
# Per-function sections let the linker strip unused bigint/regexp code.
55
SEC_FLAGS = -ffunction-sections -fdata-sections
56
# Apple ld64 spells dead-code stripping --dead_strip; GNU ld --gc-sections.
57
ifeq ($(shell uname -s),Darwin)
58
  GC_FLAGS = -Wl,-dead_strip
59
else
60
  GC_FLAGS = -Wl,--gc-sections
61
endif
62
63
# `timeout` is GNU coreutils β€” present on Linux, named `gtimeout` on macOS
64
# (brew coreutils). Detect both; if neither is found run without limits.
65
TIMEOUT_BIN := $(shell command -v timeout 2>/dev/null || command -v gtimeout 2>/dev/null)
66
TIMEOUT10 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 10,)
67
TIMEOUT60 := $(if $(TIMEOUT_BIN),$(TIMEOUT_BIN) 60,)
68
Y 0418fa9c2d50 Fix '-j forced in makefile' jobserver warning on 13 days ago
69
# Default to a parallel build at the logical CPU count, unless the
70
# invocation already asked for a job count. Applied ONLY at the top level
71
# (MAKELEVEL 0): a sub-make inherits the parent's jobserver, and forcing
72
# -j again in a sub-make's MAKEFLAGS triggers GNU Make's "-j forced in
73
# makefile: resetting jobserver mode" warning (the --jobserver-auth flag
74
# isn't visible in MAKEFLAGS at sub-make parse time, so a plain -j guard
75
# can't see it β€” MAKELEVEL is the reliable discriminator). A command-line
76
# -jN still wins by precedence; the env form `MAKEFLAGS=-jN` is honored
77
# by the inner guard.
78
ifeq ($(MAKELEVEL),0)
79
ifeq (,$(filter -j%,$(MAKEFLAGS))$(findstring j,$(firstword -$(MAKEFLAGS))))
Y cd6106b9b2cf Build system: split legacy into legacy/Makefile, 13 days ago
80
  MAKEFLAGS += -j$(shell getconf _NPROCESSORS_ONLN 2>/dev/null || echo 4)
81
endif
Y 0418fa9c2d50 Fix '-j forced in makefile' jobserver warning on 13 days ago
82
endif
Y cd6106b9b2cf Build system: split legacy into legacy/Makefile, 13 days ago
83
84
# Reference Ruby for test/bench output comparison. Override on the command
85
# line to use a freshly-built interpreter, e.g. `REF_RUBY=miniruby make test`.
86
REF_RUBY ?= ruby
87
88
# Ruby used to run the legacy bootstrap compiler. Long-running hot loops,
89
# so `YJIT=1 make` adds --yjit here (opt-in; needs a YJIT-enabled Ruby).
90
BOOTSTRAP_RUBY ?= ruby
91
ifeq ($(YJIT),1)
92
  BOOTSTRAP_RUBY := $(BOOTSTRAP_RUBY) --yjit
93
endif
94
Y 28cb212936b1 Isolate the legacy compiler under build/legacy, 13 days ago
95
# Content stamps are a legacy-bootstrap concern only; the rule lives in
96
# legacy/Makefile now. The normal C build depends on its sources directly.