diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..12a6f92 --- /dev/null +++ b/Makefile | |||
| @@ -0,0 +1,60 @@ | |||
| 1 | # libhl2hake.so — 32-bit Source Engine plugin. | ||
| 2 | # | ||
| 3 | # make release build (build/release, -O2) | ||
| 4 | # make debug build/debug with -O0 -g (symbolise crash addresses) | ||
| 5 | # make clean | ||
| 6 | # | ||
| 7 | # Needs a 32-bit multilib toolchain (g++-multilib on Debian/Ubuntu). | ||
| 8 | |||
| 9 | CXX ?= g++ | ||
| 10 | OUT := libhl2hake.so | ||
| 11 | SRC := $(wildcard src/*.cpp) | ||
| 12 | ODIR ?= build/release | ||
| 13 | OPT ?= -O2 | ||
| 14 | |||
| 15 | CXXFLAGS := -m32 -std=c++17 -Wall -Wextra -Werror -fPIC \ | ||
| 16 | -fvisibility=hidden -fno-omit-frame-pointer -pthread \ | ||
| 17 | -MMD -MP $(OPT) | ||
| 18 | LDFLAGS := -m32 -shared -pthread -Wl,--no-undefined | ||
| 19 | LDLIBS := -ldl | ||
| 20 | |||
| 21 | OBJ := $(patsubst src/%.cpp,$(ODIR)/%.o,$(SRC)) | ||
| 22 | DEP := $(OBJ:.o=.d) | ||
| 23 | |||
| 24 | all: check $(OUT) | ||
| 25 | @file $(OUT) | ||
| 26 | @test -f assets/LiberationSans-Regular.ttf || \ | ||
| 27 | echo "warning: assets/ is missing next to the .so; the overlay falls back to system fonts" >&2 | ||
| 28 | |||
| 29 | # Objects, dependency files and headers are handled by make itself; this only | ||
| 30 | # keeps the debug build in its own directory. | ||
| 31 | debug: | ||
| 32 | @$(MAKE) --no-print-directory ODIR=build/debug OPT="-O0 -g" | ||
| 33 | |||
| 34 | # Always relink. Both configs write the same output file, so without this a | ||
| 35 | # plain `make` after `make debug` would keep the debug binary (the .so is newer | ||
| 36 | # than the release objects). Linking is sub-second. | ||
| 37 | .PHONY: FORCE | ||
| 38 | FORCE: | ||
| 39 | |||
| 40 | $(OUT): $(OBJ) FORCE | ||
| 41 | $(CXX) $(LDFLAGS) -o $@ $(OBJ) $(LDLIBS) | ||
| 42 | |||
| 43 | $(ODIR)/%.o: src/%.cpp | $(ODIR) | ||
| 44 | $(CXX) $(CXXFLAGS) -c $< -o $@ | ||
| 45 | |||
| 46 | $(ODIR): | ||
| 47 | @mkdir -p $@ | ||
| 48 | |||
| 49 | # Fail once with a usable message instead of a wall of compiler errors. | ||
| 50 | .PHONY: check | ||
| 51 | check: | ||
| 52 | @printf 'int main(){return 0;}\n' | \ | ||
| 53 | $(CXX) -m32 -x c++ - -o /dev/null 2>/dev/null || \ | ||
| 54 | { echo "error: $(CXX) cannot build 32-bit binaries; install g++-multilib" >&2; exit 1; } | ||
| 55 | |||
| 56 | .PHONY: all debug clean | ||
| 57 | clean: | ||
| 58 | rm -rf build $(OUT) | ||
| 59 | |||
| 60 | -include $(DEP) | ||
