-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
78 lines (64 loc) · 2.98 KB
/
Copy pathMakefile
File metadata and controls
78 lines (64 loc) · 2.98 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
#
# phpstan_turbo — a plain Zend extension, no framework dependencies.
#
# make builds phpstan_turbo.so
# make clean
#
PHP_CONFIG ?= php-config
CXX ?= c++
# CI overrides with stricter settings, e.g. WARN_FLAGS="-Wall -Wextra -Werror"
# (the Zend engine headers are exempted via the pragma guard in src/support.h)
WARN_FLAGS ?= -Wall
# ZEND_ENABLE_STATIC_TSRMLS_CACHE: on ZTS builds EG()/CG() go through the
# per-thread cache main.cpp defines instead of a ts_resource lookup per
# access; a no-op on NTS builds.
CXXFLAGS := $(WARN_FLAGS) -O2 -std=c++17 -fPIC \
-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1 \
`$(PHP_CONFIG) --includes`
# The extension version is the short SHA of the last commit touching
# turbo-ext/src/ (the same computation the CI version job enforces against
# TurboExtensionEnabler::EXPECTED_EXTENSION_VERSION),
# computed from git at build time and baked in via -D. Outside the monorepo
# (the phpstan/turbo-ext subsplit, a release tarball) git yields nothing —
# and the subsplit's replayed commits have different SHAs anyway — so
# VERSION.txt carries the monorepo SHA instead: subsplit-turbo-ext.yml
# generates and commits it per replayed commit, and it must never exist in
# the monorepo (the .txt suffix is load-bearing — C++ stdlibs #include
# <version>, and with the extension root on the include path a file named
# VERSION satisfies that include on case-insensitive filesystems). With
# neither source it degrades to "dev", which the enabler rejects — the
# extension then simply stays inactive. version.stamp makes a SHA change
# rebuild main.o.
PHPSTANTURBO_VERSION := $(shell git -C .. log -1 --format=%H -- turbo-ext/src 2>/dev/null | cut -c1-7)
ifeq ($(PHPSTANTURBO_VERSION),)
PHPSTANTURBO_VERSION := $(strip $(shell cat VERSION.txt 2>/dev/null))
endif
ifeq ($(PHPSTANTURBO_VERSION),)
PHPSTANTURBO_VERSION := dev
endif
CXXFLAGS += -DPHPSTANTURBO_VERSION='"$(PHPSTANTURBO_VERSION)"'
# Undefined PHP engine symbols are resolved by the php binary at load time;
# GNU ld allows them in shared objects by default, Darwin needs the flag.
# On Linux, fold libstdc++/libgcc into the .so statically so a distributed
# binary does not depend on the build host's GLIBCXX_*/GCC_* symbol versions.
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
LINK_FLAGS := -undefined dynamic_lookup
else
LINK_FLAGS := -static-libstdc++ -static-libgcc
endif
SOURCES := $(wildcard src/*.cpp) $(wildcard src/parser/*.cpp)
OBJECTS := $(SOURCES:.cpp=.o)
phpstan_turbo.so: $(OBJECTS)
$(CXX) `$(PHP_CONFIG) --ldflags` -shared $(LINK_FLAGS) -o $@ $(OBJECTS)
src/%.o: src/%.cpp src/support.h src/zv.h src/reg.h
$(CXX) $(CXXFLAGS) -c -o $@ $<
src/main.o: version.stamp
version.stamp: FORCE
@echo '$(PHPSTANTURBO_VERSION)' | cmp -s - $@ 2>/dev/null || echo '$(PHPSTANTURBO_VERSION)' > $@
FORCE:
$(filter src/parser/%.o,$(OBJECTS)): src/parser/ParserEngine.h src/zv.h
src/parser/ParserRunner.o: src/parser/ParserRunnerActionsSplit.h
clean:
rm -f $(OBJECTS) phpstan_turbo.so version.stamp
.PHONY: clean FORCE