Android: move the shell to dm/android and the Vulkan backend to dm/gfx/vulkan

Mirror the iOS layout instead of nesting Android inside dm/host:
- dm/android/app       GameActivity app (manifest, java, res, build_apk.sh)
- dm/android/Sources   front_app.c, touch_app.c, front_headless.c
- dm/android/Makefile  entry point (apk / lib / install / headless / tests);
                       rules in build.mk (was dm/host/Makefile.android),
                       run with dm/host as cwd; outputs in dm/android/build/
- dm/android/tests     t_vk_perf
- dm/gfx/vulkan        nvn_vk.c and friends, next to the Metal backend

Only include paths, build paths and docs change; no code changes.
The Mac / iOS source lists do not pick up gfx/vulkan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
shenlei
2026-10-14 16:59:36 +09:00
co-authored by Claude Opus 5.5
parent 3429c6c0a4
commit 3c25cd89fc
26 changed files with 135 additions and 72 deletions
+69
View File
@@ -0,0 +1,69 @@
# Android(arm64,仅 Adreno 机型)构建规则。由 dm/android/Makefile 以 dm/host 为当前目录调用(宿主共用源码按 host 的相对路径列),产物放 dm/android/build/
# 缺省:无头宿主 dmhost(adb shell 直接跑);APP=1:libd2r.so 给 GameActivity 加载
# Android (arm64, Adreno devices only) build rules. Invoked by dm/android/Makefile with dm/host as the current directory (the shared host sources are listed relative to host); outputs go to dm/android/build/
# Default: the headless host dmhost (run directly from adb shell); APP=1: libd2r.so for GameActivity to load
ANDROID_DIR := $(abspath ../android)
NDK ?= $(or $(ANDROID_NDK_HOME),$(lastword $(sort $(wildcard $(HOME)/Library/Android/sdk/ndk/*))))
API ?= 33
CC := $(wildcard $(NDK)/toolchains/llvm/prebuilt/*/bin)/aarch64-linux-android$(API)-clang
OUT ?= $(ANDROID_DIR)/build
# 表头:没有游戏文件时可用 DM_GENH_DIR 指向现成的表头目录 | generated headers: without game files, DM_GENH_DIR can point at a directory of ready-made headers
GENH_DIR ?= $(or $(DM_GENH_DIR),.)
# -ffixed-x18:x18 是客体的平台寄存器,宿主代码不许碰;16K 页对齐(Android 15+ 16K 页设备);保留 __start_/__stop_ 段登记表
# -ffixed-x18: x18 is the guest's platform register, host code must not touch it; 16K page alignment (Android 15+ 16K-page devices); keep the __start_/__stop_ section registration tables
CFLAGS = -O1 -g -Wall -Wno-unused-function -Wno-format -ffixed-x18 -fPIE \
-include compat/linux/compat_linux.h -Icompat/linux/include -I. -I$(GENH_DIR) -I../gfx/nvn/include -I../gfx/nvn
LDFLAGS = -pie -Wl,-z,max-page-size=16384 -Wl,-z,nostart-stop-gc -Wl,--export-dynamic
# APP=1:同一份源编成 libd2r.so 给 GameActivity 加载(dm/android/app/),前端换成 Sources/front_app.c;APK 由 app/build_apk.sh 打
# APP=1: build the same sources into libd2r.so for GameActivity to load (dm/android/app/), with Sources/front_app.c as the front end; the APK is packed by app/build_apk.sh
ifeq ($(APP),1)
OUT := $(ANDROID_DIR)/build/app
CFLAGS := $(subst -fPIE,-fPIC,$(CFLAGS))
LDFLAGS := -shared -Wl,-soname,libd2r.so -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-z,max-page-size=16384 -Wl,-z,nostart-stop-gc
endif
LIBS = -llog -lm -ldl -lz -landroid -laaudio
# 与 Makefile 同一份源单,去掉 macOS 专属(.m、touch_mac.c、front_mac.m、memstat.m)
# Same source list as Makefile, minus the macOS-only ones (.m, touch_mac.c, front_mac.m, memstat.m)
# Makefile 的 SRC 是续行写的(一行一个),读到第一条不带续行符的行为止 | Makefile's SRC uses continuation lines (one per line); read up to the first line without a continuation
SRC_MAC := $(filter %.c,$(shell awk '/^SRC=/{f=1} f{l=$$0; sub(/^SRC=/,"",l); c=(l ~ /[\\\\]$$/); sub(/[\\\\]$$/,"",l); print l; if(!c) exit}' Makefile))
SRC := $(filter-out touch_mac.c,$(SRC_MAC)) $(sort $(wildcard hle_*.c)) $(wildcard compat/linux/*.c)
ifneq ($(APP),1)
SRC += ../android/Sources/front_headless.c
else
SRC += ../android/Sources/front_app.c ../android/Sources/touch_app.c \
../touch/dm_touch_game_bridge.c ../touch/dm_touch_game_state.c ../touch/dm_touch_game_identity.c ../touch/dm_touch_native_art.c
endif
GFX := $(sort $(wildcard ../gfx/*.c ../gfx/nvn/*.c ../gfx/tex/*.c ../gfx/vulkan/*.c))
LIBDEFLATE := $(shell sed -n 's/^LIBDEFLATE=//p' Makefile)
ASM := entry.S ../gfx/nvn/nvn_entry.S ../gfx/nvn/nvn_thunks.S
OBJ := $(patsubst %.c,$(OUT)/obj/%.o,$(subst ../,up/,$(SRC) $(GFX) $(LIBDEFLATE))) \
$(patsubst %.S,$(OUT)/obj/%.o,$(subst ../,up/,$(ASM)))
$(OUT)/dmhost: $(OBJ)
$(CC) $(LDFLAGS) -Wl,--error-limit=0 -o $@ $^ $(LIBS)
$(OUT)/libd2r.so: $(OBJ)
$(CC) $(LDFLAGS) -Wl,--error-limit=0 -o $@ $^ $(LIBS)
# 图形回放(gfx/,含 Vulkan 后端 gfx/vulkan/)是逐绘制热路径,用 -O2;其余宿主代码保持 -O1,与 Mac 构建一致
# Graphics replay (gfx/, including the Vulkan backend gfx/vulkan/) is the per-draw hot path, built at -O2; the rest of the host stays at -O1 like the Mac build
$(OUT)/obj/up/gfx/%.o: CFLAGS += -O2
$(OUT)/obj/up/%.o: ../%.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(OUT)/obj/%.o: %.c dm.h hle.h compat/linux/compat_linux.h
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
# Mach-O 汇编转 ELF:去符号前导 _、@PAGE/@PAGEOFF 换 ELF 写法、.cstring 换 .rodata
# Mach-O assembly to ELF: strip the leading _ of symbols, @PAGE/@PAGEOFF to the ELF forms, .cstring to .rodata
ASM2ELF = perl -pe 's/(?<![\w.])_([A-Za-z])/$$1/g; s/(\w+)\@PAGEOFF/:lo12:$$1/g; s/(\w+)\@PAGE\b/$$1/g; s/^\s*\.cstring\b/\t.section .rodata/'
$(OUT)/obj/up/%.o: ../%.S
@mkdir -p $(dir $@)
$(ASM2ELF) $< > $(@:.o=.elf.S) && $(CC) -c $(@:.o=.elf.S) -o $@
$(OUT)/obj/%.o: %.S
@mkdir -p $(dir $@)
$(ASM2ELF) $< > $(@:.o=.elf.S) && $(CC) -c $(@:.o=.elf.S) -o $@
clean:
rm -rf $(OUT)
.PHONY: clean