Advertisement
Guest User

Untitled

a guest
Aug 16th, 2022
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 34.12 KB | None | 0 0
  1.  
  2. # Makefile to rebuild SM64 split image
  3.  
  4. ### Default target ###
  5.  
  6. default: all
  7.  
  8. ### Build Options ###
  9.  
  10. # These options can either be changed by modifying the makefile, or
  11. # by building with 'make SETTING=value'. 'make clean' may be required.
  12.  
  13. # Build debug version
  14. DEBUG ?= 0
  15. # Version of the game to build
  16. VERSION ?= us
  17. # Graphics microcode used
  18. GRUCODE ?= f3dex2e
  19. # If COMPARE is 1, check the output sha1sum when building 'all'
  20. COMPARE ?= 1
  21. # If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended)
  22. NON_MATCHING ?= 1
  23.  
  24. # Build and optimize for Raspberry Pi(s)
  25. TARGET_RPI ?= 0
  26.  
  27. # Build for Emscripten/WebGL
  28. TARGET_WEB ?= 0
  29.  
  30. # Makeflag to enable OSX fixes
  31. OSX_BUILD ?= 0
  32.  
  33. # Enable -no-pie linker option
  34. NO_PIE ?= 1
  35.  
  36. # Specify the target you are building for, TARGET_BITS=0 means native
  37. TARGET_ARCH ?= native
  38. TARGET_BITS ?= 0
  39.  
  40. # Disable better camera by default
  41. BETTERCAMERA ?= 0
  42. # Disable no drawing distance by default
  43. NODRAWINGDISTANCE ?= 0
  44. # Disable texture fixes by default (helps with them purists)
  45. TEXTURE_FIX ?= 0
  46. # Enable extended options menu by default
  47. EXT_OPTIONS_MENU ?= 1
  48. # Disable text-based save-files by default
  49. TEXTSAVES ?= 0
  50. # Load resources from external files
  51. EXTERNAL_DATA ?= 0
  52. # Enable Discord Rich Presence
  53. DISCORDRPC ?= 0
  54.  
  55. # Various workarounds for weird toolchains
  56.  
  57. NO_BZERO_BCOPY ?= 0
  58. NO_LDIV ?= 0
  59.  
  60. # Backend selection
  61.  
  62. # Renderers: GL, GL_LEGACY, D3D11, D3D12
  63. RENDER_API ?= GL
  64. # Window managers: SDL1, SDL2, DXGI (forced if D3D11 or D3D12 in RENDER_API)
  65. WINDOW_API ?= SDL2
  66. # Audio backends: SDL1, SDL2
  67. AUDIO_API ?= SDL2
  68. # Controller backends (can have multiple, space separated): SDL2, SDL1
  69. CONTROLLER_API ?= SDL2
  70.  
  71. # Misc settings for EXTERNAL_DATA
  72.  
  73. BASEDIR ?= res
  74. BASEPACK ?= base.zip
  75.  
  76. # Automatic settings for PC port(s)
  77.  
  78. WINDOWS_BUILD ?= 0
  79.  
  80. # Attempt to detect OS
  81.  
  82. ifeq ($(OS),Windows_NT)
  83. HOST_OS ?= Windows
  84. else
  85. HOST_OS ?= $(shell uname -s 2>/dev/null || echo Unknown)
  86. # some weird MINGW/Cygwin env that doesn't define $OS
  87. ifneq (,$(findstring MINGW,HOST_OS))
  88. HOST_OS := Windows
  89. endif
  90. endif
  91.  
  92. ifeq ($(TARGET_WEB),0)
  93. ifeq ($(HOST_OS),Windows)
  94. WINDOWS_BUILD := 1
  95. endif
  96. endif
  97.  
  98. # MXE overrides
  99.  
  100. ifeq ($(WINDOWS_BUILD),1)
  101. ifeq ($(CROSS),i686-w64-mingw32.static-)
  102. TARGET_ARCH = i386pe
  103. TARGET_BITS = 32
  104. NO_BZERO_BCOPY := 1
  105. else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
  106. TARGET_ARCH = i386pe
  107. TARGET_BITS = 64
  108. NO_BZERO_BCOPY := 1
  109. endif
  110. endif
  111.  
  112. # macOS overrides
  113. ifeq ($(HOST_OS),Darwin)
  114. OSX_BUILD := 1
  115. # Using MacPorts?
  116. ifeq ($(shell test -d /opt/local/lib && echo y),y)
  117. OSX_GCC_VER = $(shell find /opt/local/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
  118. CC := gcc-mp-$(OSX_GCC_VER)
  119. CXX := g++-mp-$(OSX_GCC_VER)
  120. CPP := cpp-mp-$(OSX_GCC_VER) -P
  121. PLATFORM_CFLAGS := -I /opt/local/include
  122. PLATFORM_LDFLAGS := -L /opt/local/lib
  123. else
  124. # Using Homebrew?
  125. ifeq ($(shell which brew >/dev/null 2>&1 && echo y),y)
  126. OSX_GCC_VER = $(shell find `brew --prefix`/bin/gcc* | grep -oE '[[:digit:]]+' | sort -n | uniq | tail -1)
  127. CC := gcc-$(OSX_GCC_VER)
  128. CXX := g++-$(OSX_GCC_VER)
  129. CPP := cpp-$(OSX_GCC_VER) -P
  130. PLATFORM_CFLAGS := -I /usr/local/include
  131. PLATFORM_LDFLAGS := -L /usr/local/lib
  132. else
  133. $(error No suitable macOS toolchain found, have you installed Homebrew?)
  134. endif
  135. endif
  136. endif
  137.  
  138. ifneq ($(TARGET_BITS),0)
  139. BITS := -m$(TARGET_BITS)
  140. endif
  141.  
  142. # Release (version) flag defs
  143.  
  144. ifeq ($(VERSION),jp)
  145. VERSION_DEF := VERSION_JP
  146. else
  147. ifeq ($(VERSION),us)
  148. VERSION_DEF := VERSION_US
  149. else
  150. ifeq ($(VERSION),eu)
  151. VERSION_DEF := VERSION_EU
  152. else
  153. ifeq ($(VERSION),sh)
  154. $(warning Building SH is experimental and is prone to breaking. Try at your own risk.)
  155. VERSION_DEF := VERSION_SH
  156. # TODO: GET RID OF THIS!!! We should mandate assets for Shindou like EU but we dont have the addresses extracted yet so we'll just pretend you have everything extracted for now.
  157. NOEXTRACT := 1
  158. else
  159. $(error unknown version "$(VERSION)")
  160. endif
  161. endif
  162. endif
  163. endif
  164.  
  165. TARGET := sm64.$(VERSION)
  166. VERSION_CFLAGS := -D$(VERSION_DEF) -D_LANGUAGE_C
  167. VERSION_ASFLAGS := --defsym $(VERSION_DEF)=1
  168.  
  169. # Stuff for showing the git hash in the intro on nightly builds
  170. # From https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source
  171. ifeq ($(shell git rev-parse --abbrev-ref HEAD),nightly)
  172. GIT_HASH := $(shell git rev-parse --short HEAD)
  173. VERSION_CFLAGS += -DNIGHTLY -DGIT_HASH="\"$(GIT_HASH)\""
  174. endif
  175.  
  176. # Microcode
  177.  
  178. ifeq ($(GRUCODE),f3dex) # Fast3DEX
  179. GRUCODE_DEF := F3DEX_GBI
  180. GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
  181. TARGET := $(TARGET).f3dex
  182. COMPARE := 0
  183. else
  184. ifeq ($(GRUCODE),f3dex2) # Fast3DEX2
  185. GRUCODE_DEF := F3DEX_GBI_2
  186. GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
  187. TARGET := $(TARGET).f3dex2
  188. COMPARE := 0
  189. else
  190. ifeq ($(GRUCODE),f3dex2e) # Fast3DEX2 Extended (PC default)
  191. GRUCODE_DEF := F3DEX_GBI_2E
  192. TARGET := $(TARGET).f3dex2e
  193. COMPARE := 0
  194. else
  195. ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H (Shindou)
  196. GRUCODE_DEF := F3D_NEW
  197. TARGET := $(TARGET).f3d_new
  198. COMPARE := 0
  199. else
  200. ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori)
  201. $(warning Fast3DZEX is experimental. Try at your own risk.)
  202. GRUCODE_DEF := F3DEX_GBI_2
  203. GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED=1
  204. TARGET := $(TARGET).f3dzex
  205. COMPARE := 0
  206. endif
  207. endif
  208. endif
  209. endif
  210. endif
  211.  
  212. GRUCODE_CFLAGS := -D$(GRUCODE_DEF)
  213. GRUCODE_ASFLAGS := $(GRUCODE_ASFLAGS) --defsym $(GRUCODE_DEF)=1
  214.  
  215. # Default build is for PC now
  216. VERSION_CFLAGS := $(VERSION_CFLAGS) -DNON_MATCHING -DAVOID_UB
  217.  
  218. ifeq ($(TARGET_RPI),1) # Define RPi to change SDL2 title & GLES2 hints
  219. VERSION_CFLAGS += -DUSE_GLES
  220. endif
  221.  
  222. ifeq ($(OSX_BUILD),1) # Modify GFX & SDL2 for OSX GL
  223. VERSION_CFLAGS += -DOSX_BUILD
  224. endif
  225.  
  226. VERSION_ASFLAGS := --defsym AVOID_UB=1
  227. COMPARE := 0
  228.  
  229. ifeq ($(TARGET_WEB),1)
  230. VERSION_CFLAGS := $(VERSION_CFLAGS) -DTARGET_WEB -DUSE_GLES
  231. endif
  232.  
  233. # Check backends
  234.  
  235. ifneq (,$(filter $(RENDER_API),D3D11 D3D12))
  236. ifneq ($(WINDOWS_BUILD),1)
  237. $(error DirectX is only supported on Windows)
  238. endif
  239. ifneq ($(WINDOW_API),DXGI)
  240. $(warning DirectX renderers require DXGI, forcing WINDOW_API value)
  241. WINDOW_API := DXGI
  242. endif
  243. else
  244. ifeq ($(WINDOW_API),DXGI)
  245. $(error DXGI can only be used with DirectX renderers)
  246. endif
  247. endif
  248.  
  249. ################### Universal Dependencies ###################
  250.  
  251. # (This is a bit hacky, but a lot of rules implicitly depend
  252. # on tools and assets, and we use directory globs further down
  253. # in the makefile that we want should cover assets.)
  254.  
  255. ifneq ($(MAKECMDGOALS),clean)
  256. ifneq ($(MAKECMDGOALS),cleantools)
  257. ifneq ($(MAKECMDGOALS),distclean)
  258.  
  259. # Make sure assets exist
  260. NOEXTRACT ?= 0
  261. ifeq ($(NOEXTRACT),0)
  262. DUMMY != ./extract_assets.py $(VERSION) >&2 || echo FAIL
  263. ifeq ($(DUMMY),FAIL)
  264. $(error Failed to extract assets)
  265. endif
  266. endif
  267.  
  268. # Make tools if out of date
  269. DUMMY != CC=$(CC) CXX=$(CXX) $(MAKE) -C tools >&2 || echo FAIL
  270. ifeq ($(DUMMY),FAIL)
  271. $(error Failed to build tools)
  272. endif
  273.  
  274. endif
  275. endif
  276. endif
  277.  
  278. ################ Target Executable and Sources ###############
  279.  
  280. # BUILD_DIR is location where all build artifacts are placed
  281. BUILD_DIR_BASE := build
  282.  
  283. ifeq ($(TARGET_WEB),1)
  284. BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_web
  285. else
  286. BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)_pc
  287. endif
  288.  
  289. LIBULTRA := $(BUILD_DIR)/libultra.a
  290.  
  291. ifeq ($(TARGET_WEB),1)
  292. EXE := $(BUILD_DIR)/$(TARGET).html
  293. else
  294. ifeq ($(WINDOWS_BUILD),1)
  295. EXE := $(BUILD_DIR)/$(TARGET).exe
  296.  
  297. else # Linux builds/binary namer
  298. ifeq ($(TARGET_RPI),1)
  299. EXE := $(BUILD_DIR)/$(TARGET).arm
  300. else
  301. EXE := $(BUILD_DIR)/$(TARGET)
  302. endif
  303. endif
  304. endif
  305.  
  306. ELF := $(BUILD_DIR)/$(TARGET).elf
  307. LD_SCRIPT := sm64.ld
  308. MIO0_DIR := $(BUILD_DIR)/bin
  309. SOUND_BIN_DIR := $(BUILD_DIR)/sound
  310. TEXTURE_DIR := textures
  311. ACTOR_DIR := actors
  312. LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
  313.  
  314. # Directories containing source files
  315.  
  316. # Hi, I'm a PC
  317. SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
  318. ASM_DIRS :=
  319.  
  320. ifeq ($(DISCORDRPC),1)
  321. SRC_DIRS += src/pc/discord
  322. endif
  323.  
  324. BIN_DIRS := bin bin/$(VERSION)
  325.  
  326. ULTRA_SRC_DIRS := lib/src lib/src/math
  327. ULTRA_ASM_DIRS := lib/asm lib/data
  328. ULTRA_BIN_DIRS := lib/bin
  329.  
  330. GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists
  331.  
  332. MIPSISET := -mips2
  333. MIPSBIT := -32
  334.  
  335. ifeq ($(DEBUG),1)
  336. OPT_FLAGS := -g
  337. else
  338. OPT_FLAGS := -O2
  339. endif
  340.  
  341. # Set BITS (32/64) to compile for
  342. OPT_FLAGS += $(BITS)
  343.  
  344. ifeq ($(TARGET_WEB),1)
  345. OPT_FLAGS := -O2 -g4 --source-map-base http://localhost:8080/
  346. endif
  347.  
  348. ifeq ($(TARGET_RPI),1)
  349. machine = $(shell sh -c 'uname -m 2>/dev/null || echo unknown')
  350. # Raspberry Pi B+, Zero, etc
  351. ifneq (,$(findstring armv6l,$(machine)))
  352. OPT_FLAGS := -march=armv6zk+fp -mfpu=vfp -Ofast
  353. endif
  354.  
  355. # Raspberry Pi 2 and 3 in ARM 32bit mode
  356. ifneq (,$(findstring armv7l,$(machine)))
  357. model = $(shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown')
  358.  
  359. ifneq (,$(findstring 3,$(model)))
  360. OPT_FLAGS := -march=armv8-a+crc -mtune=cortex-a53 -mfpu=neon-fp-armv8 -O3
  361. else
  362. OPT_FLAGS := -march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -O3
  363. endif
  364. endif
  365.  
  366. # RPi3 or RPi4, in ARM64 (aarch64) mode. NEEDS TESTING 32BIT.
  367. # DO NOT pass -mfpu stuff here, thats for 32bit ARM only and will fail for 64bit ARM.
  368. ifneq (,$(findstring aarch64,$(machine)))
  369. model = $(shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown')
  370. ifneq (,$(findstring 3,$(model)))
  371. OPT_FLAGS := -march=armv8-a+crc -mtune=cortex-a53 -O3
  372. else ifneq (,$(findstring 4,$(model)))
  373. OPT_FLAGS := -march=armv8-a+crc+simd -mtune=cortex-a72 -O3
  374. endif
  375.  
  376. endif
  377. endif
  378.  
  379. # File dependencies and variables for specific files
  380. include Makefile.split
  381.  
  382. # Source code files
  383. LEVEL_C_FILES := $(wildcard levels/*/leveldata.c) $(wildcard levels/*/script.c) $(wildcard levels/*/geo.c)
  384. C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(LEVEL_C_FILES)
  385. CXX_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.cpp))
  386. S_FILES := $(foreach dir,$(ASM_DIRS),$(wildcard $(dir)/*.s))
  387. GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
  388.  
  389. GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c \
  390. $(addprefix $(BUILD_DIR)/bin/,$(addsuffix _skybox.c,$(notdir $(basename $(wildcard textures/skyboxes/*.png)))))
  391.  
  392. ULTRA_C_FILES := \
  393. alBnkfNew.c \
  394. guLookAtRef.c \
  395. guMtxF2L.c \
  396. guNormalize.c \
  397. guOrthoF.c \
  398. guPerspectiveF.c \
  399. guRotateF.c \
  400. guScaleF.c \
  401. guTranslateF.c \
  402. ldiv.c
  403.  
  404. C_FILES := $(filter-out src/game/main.c,$(C_FILES))
  405. ULTRA_C_FILES := $(addprefix lib/src/,$(ULTRA_C_FILES))
  406.  
  407. # "If we're not N64, use the above"
  408.  
  409. ifeq ($(VERSION),sh)
  410. SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
  411. SOUND_SEQUENCE_FILES := $(wildcard sound/sequences/jp/*.m64) \
  412. $(wildcard sound/sequences/*.m64) \
  413. $(foreach file,$(wildcard sound/sequences/jp/*.s),$(BUILD_DIR)/$(file:.s=.m64)) \
  414. $(foreach file,$(wildcard sound/sequences/*.s),$(BUILD_DIR)/$(file:.s=.m64))
  415. else
  416. SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
  417. SOUND_SEQUENCE_FILES := $(wildcard sound/sequences/$(VERSION)/*.m64) \
  418. $(wildcard sound/sequences/*.m64) \
  419. $(foreach file,$(wildcard sound/sequences/$(VERSION)/*.s),$(BUILD_DIR)/$(file:.s=.m64)) \
  420. $(foreach file,$(wildcard sound/sequences/*.s),$(BUILD_DIR)/$(file:.s=.m64))
  421. endif
  422.  
  423. SOUND_SAMPLE_DIRS := $(wildcard sound/samples/*)
  424. SOUND_SAMPLE_AIFFS := $(foreach dir,$(SOUND_SAMPLE_DIRS),$(wildcard $(dir)/*.aiff))
  425. SOUND_SAMPLE_TABLES := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.table))
  426. SOUND_SAMPLE_AIFCS := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.aifc))
  427. SOUND_OBJ_FILES := $(SOUND_BIN_DIR)/sound_data.o
  428.  
  429. # Object files
  430. O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
  431. $(foreach file,$(CXX_FILES),$(BUILD_DIR)/$(file:.cpp=.o)) \
  432. $(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
  433. $(foreach file,$(GENERATED_C_FILES),$(file:.c=.o))
  434.  
  435. ULTRA_O_FILES := $(foreach file,$(ULTRA_S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
  436. $(foreach file,$(ULTRA_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
  437.  
  438. GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
  439.  
  440. RPC_LIBS :=
  441. ifeq ($(DISCORDRPC),1)
  442. ifeq ($(WINDOWS_BUILD),1)
  443. RPC_LIBS := lib/discord/libdiscord-rpc.dll
  444. else ifeq ($(OSX_BUILD),1)
  445. # needs testing
  446. RPC_LIBS := lib/discord/libdiscord-rpc.dylib
  447. else
  448. RPC_LIBS := lib/discord/libdiscord-rpc.so
  449. endif
  450. endif
  451.  
  452. # Automatic dependency files
  453. DEP_FILES := $(O_FILES:.o=.d) $(ULTRA_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d
  454.  
  455. # Segment elf files
  456. SEG_FILES := $(SEGMENT_ELF_FILES) $(ACTOR_ELF_FILES) $(LEVEL_ELF_FILES)
  457.  
  458. ##################### Compiler Options #######################
  459. INCLUDE_CFLAGS := -I include -I $(BUILD_DIR) -I $(BUILD_DIR)/include -I src -I .
  460. ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
  461.  
  462. # Huge deleted N64 section was here
  463.  
  464. AS := $(CROSS)as
  465.  
  466. ifeq ($(OSX_BUILD),1)
  467. AS := i686-w64-mingw32-as
  468. endif
  469.  
  470. ifneq ($(TARGET_WEB),1) # As in, not-web PC port
  471. CC ?= $(CROSS)gcc
  472. CXX ?= $(CROSS)g++
  473. else
  474. CC := emcc
  475. CXX := emcc
  476. endif
  477.  
  478. LD := $(CC)
  479.  
  480. ifeq ($(DISCORDRPC),1)
  481. LD := $(CXX)
  482. else ifeq ($(WINDOWS_BUILD),1)
  483. ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL
  484. LD := $(CC)
  485. else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
  486. LD := $(CC)
  487. else
  488. LD := $(CXX)
  489. endif
  490. endif
  491.  
  492. ifeq ($(WINDOWS_BUILD),1) # fixes compilation in MXE on Linux and WSL
  493. CPP := cpp -P
  494. OBJCOPY := objcopy
  495. OBJDUMP := $(CROSS)objdump
  496. else ifeq ($(OSX_BUILD),1)
  497. OBJDUMP := i686-w64-mingw32-objdump
  498. OBJCOPY := i686-w64-mingw32-objcopy
  499. else # Linux & other builds
  500. CPP := $(CROSS)cpp -P
  501. OBJCOPY := $(CROSS)objcopy
  502. OBJDUMP := $(CROSS)objdump
  503. endif
  504.  
  505. PYTHON := python3
  506. SDLCONFIG := $(CROSS)sdl2-config
  507.  
  508. # configure backend flags
  509.  
  510. BACKEND_CFLAGS := -DRAPI_$(RENDER_API)=1 -DWAPI_$(WINDOW_API)=1 -DAAPI_$(AUDIO_API)=1
  511. # can have multiple controller APIs
  512. BACKEND_CFLAGS += $(foreach capi,$(CONTROLLER_API),-DCAPI_$(capi)=1)
  513. BACKEND_LDFLAGS :=
  514.  
  515. SDL1_USED := 0
  516. SDL2_USED := 0
  517.  
  518. # for now, it's either SDL+GL or DXGI+DirectX, so choose based on WAPI
  519. ifeq ($(WINDOW_API),DXGI)
  520. DXBITS := `cat $(ENDIAN_BITWIDTH) | tr ' ' '\n' | tail -1`
  521. ifeq ($(RENDER_API),D3D12)
  522. BACKEND_CFLAGS += -Iinclude/dxsdk
  523. endif
  524. BACKEND_LDFLAGS += -ld3dcompiler -ldxgi -ldxguid
  525. BACKEND_LDFLAGS += -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -static
  526. else ifeq ($(findstring SDL,$(WINDOW_API)),SDL)
  527. ifeq ($(WINDOWS_BUILD),1)
  528. BACKEND_LDFLAGS += -lglew32 -lglu32 -lopengl32
  529. else ifeq ($(TARGET_RPI),1)
  530. BACKEND_LDFLAGS += -lGLESv2
  531. else ifeq ($(OSX_BUILD),1)
  532. BACKEND_LDFLAGS += -framework OpenGL $(shell pkg-config --libs glew)
  533. else
  534. BACKEND_LDFLAGS += -lGL
  535. endif
  536. endif
  537.  
  538. ifneq (,$(findstring SDL2,$(AUDIO_API)$(WINDOW_API)$(CONTROLLER_API)))
  539. SDL2_USED := 1
  540. endif
  541.  
  542. ifneq (,$(findstring SDL1,$(AUDIO_API)$(WINDOW_API)$(CONTROLLER_API)))
  543. SDL1_USED := 1
  544. endif
  545.  
  546. ifeq ($(SDL1_USED)$(SDL2_USED),11)
  547. $(error Cannot link both SDL1 and SDL2 at the same time)
  548. endif
  549.  
  550. # SDL can be used by different systems, so we consolidate all of that shit into this
  551.  
  552. ifeq ($(SDL2_USED),1)
  553. SDLCONFIG := $(CROSS)sdl2-config
  554. BACKEND_CFLAGS += -DHAVE_SDL2=1
  555. else ifeq ($(SDL1_USED),1)
  556. SDLCONFIG := $(CROSS)sdl-config
  557. BACKEND_CFLAGS += -DHAVE_SDL1=1
  558. endif
  559.  
  560. ifneq ($(SDL1_USED)$(SDL2_USED),00)
  561. ifeq ($(OSX_BUILD),1)
  562. # on OSX at least the homebrew version of sdl-config gives include path as `.../include/SDL2` instead of `.../include`
  563. OSX_PREFIX := $(shell $(SDLCONFIG) --prefix)
  564. BACKEND_CFLAGS += -I$(OSX_PREFIX)/include $(shell $(SDLCONFIG) --cflags)
  565. else
  566. BACKEND_CFLAGS += $(shell $(SDLCONFIG) --cflags)
  567. endif
  568. ifeq ($(WINDOWS_BUILD),1)
  569. BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --static-libs) -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
  570. else
  571. BACKEND_LDFLAGS += $(shell $(SDLCONFIG) --libs)
  572. endif
  573. endif
  574.  
  575. ifeq ($(WINDOWS_BUILD),1)
  576. CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
  577. CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
  578.  
  579. else ifeq ($(TARGET_WEB),1)
  580. CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -s USE_SDL=2
  581. CFLAGS := $(OPT_FLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL=2
  582.  
  583. # Linux / Other builds below
  584. else
  585. CC_CHECK := $(CC) -fsyntax-only -fsigned-char $(BACKEND_CFLAGS) $(PLATFORM_CFLAGS) $(INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $(VERSION_CFLAGS) $(GRUCODE_CFLAGS)
  586. CFLAGS := $(OPT_FLAGS) $(PLATFORM_CFLAGS) $(INCLUDE_CFLAGS) $(BACKEND_CFLAGS) $(VERSION_CFLAGS) $(GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
  587. endif
  588.  
  589. # Check for enhancement options
  590.  
  591. # Check for Puppycam option
  592. ifeq ($(BETTERCAMERA),1)
  593. CC_CHECK += -DBETTERCAMERA
  594. CFLAGS += -DBETTERCAMERA
  595. EXT_OPTIONS_MENU := 1
  596. endif
  597.  
  598. ifeq ($(TEXTSAVES),1)
  599. CC_CHECK += -DTEXTSAVES
  600. CFLAGS += -DTEXTSAVES
  601. endif
  602.  
  603. # Check for no drawing distance option
  604. ifeq ($(NODRAWINGDISTANCE),1)
  605. CC_CHECK += -DNODRAWINGDISTANCE
  606. CFLAGS += -DNODRAWINGDISTANCE
  607. endif
  608.  
  609. # Check for Discord Rich Presence option
  610. ifeq ($(DISCORDRPC),1)
  611. CC_CHECK += -DDISCORDRPC
  612. CFLAGS += -DDISCORDRPC
  613. endif
  614.  
  615. # Check for texture fix option
  616. ifeq ($(TEXTURE_FIX),1)
  617. CC_CHECK += -DTEXTURE_FIX
  618. CFLAGS += -DTEXTURE_FIX
  619. endif
  620.  
  621. # Check for extended options menu option
  622. ifeq ($(EXT_OPTIONS_MENU),1)
  623. CC_CHECK += -DEXT_OPTIONS_MENU
  624. CFLAGS += -DEXT_OPTIONS_MENU
  625. endif
  626.  
  627. # Check for no bzero/bcopy workaround option
  628. ifeq ($(NO_BZERO_BCOPY),1)
  629. CC_CHECK += -DNO_BZERO_BCOPY
  630. CFLAGS += -DNO_BZERO_BCOPY
  631. endif
  632.  
  633. # Use internal ldiv()/lldiv()
  634. ifeq ($(NO_LDIV),1)
  635. CC_CHECK += -DNO_LDIV
  636. CFLAGS += -DNO_LDIV
  637. endif
  638.  
  639. # Use OpenGL 1.3
  640. ifeq ($(LEGACY_GL),1)
  641. CC_CHECK += -DLEGACY_GL
  642. CFLAGS += -DLEGACY_GL
  643. endif
  644.  
  645. # Load external textures
  646. ifeq ($(EXTERNAL_DATA),1)
  647. CC_CHECK += -DEXTERNAL_DATA -DFS_BASEDIR="\"$(BASEDIR)\""
  648. CFLAGS += -DEXTERNAL_DATA -DFS_BASEDIR="\"$(BASEDIR)\""
  649. # tell skyconv to write names instead of actual texture data and save the split tiles so we can use them later
  650. SKYTILE_DIR := $(BUILD_DIR)/textures/skybox_tiles
  651. SKYCONV_ARGS := --store-names --write-tiles "$(SKYTILE_DIR)"
  652. endif
  653.  
  654. ASFLAGS := -I include -I $(BUILD_DIR) $(VERSION_ASFLAGS)
  655.  
  656. ifeq ($(TARGET_WEB),1)
  657. LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY=64MB -g4 --source-map-base http://localhost:8080/ -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']"
  658.  
  659. else ifeq ($(WINDOWS_BUILD),1)
  660. LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -Llib -lpthread $(BACKEND_LDFLAGS) -static
  661. ifeq ($(CROSS),)
  662. LDFLAGS += -no-pie
  663. endif
  664. ifeq ($(WINDOWS_CONSOLE),1)
  665. LDFLAGS += -mconsole
  666. endif
  667.  
  668. else ifeq ($(TARGET_RPI),1)
  669. LDFLAGS := $(OPT_FLAGS) -lm $(BACKEND_LDFLAGS) -no-pie
  670.  
  671. else ifeq ($(OSX_BUILD),1)
  672. LDFLAGS := -lm $(PLATFORM_LDFLAGS) $(BACKEND_LDFLAGS) -lpthread
  673.  
  674. else ifeq ($(HOST_OS),Haiku)
  675. LDFLAGS := $(BACKEND_LDFLAGS) -no-pie
  676.  
  677. else
  678. LDFLAGS := $(BITS) -march=$(TARGET_ARCH) -lm $(BACKEND_LDFLAGS) -lpthread -ldl
  679. ifeq ($(NO_PIE), 1)
  680. LDFLAGS += -no-pie
  681. endif
  682.  
  683. ifeq ($(DISCORDRPC),1)
  684. LDFLAGS += -Wl,-rpath .
  685. endif
  686.  
  687. endif # End of LDFLAGS
  688.  
  689. # Prevent a crash with -sopt
  690. export LANG := C
  691.  
  692. ####################### Other Tools #########################
  693.  
  694. # N64 conversion tools
  695. TOOLS_DIR = tools
  696. MIO0TOOL = $(TOOLS_DIR)/mio0
  697. N64CKSUM = $(TOOLS_DIR)/n64cksum
  698. N64GRAPHICS = $(TOOLS_DIR)/n64graphics
  699. N64GRAPHICS_CI = $(TOOLS_DIR)/n64graphics_ci
  700. TEXTCONV = $(TOOLS_DIR)/textconv
  701. AIFF_EXTRACT_CODEBOOK = $(TOOLS_DIR)/aiff_extract_codebook
  702. VADPCM_ENC = $(TOOLS_DIR)/vadpcm_enc
  703. EXTRACT_DATA_FOR_MIO = $(TOOLS_DIR)/extract_data_for_mio
  704. SKYCONV = $(TOOLS_DIR)/skyconv
  705. EMULATOR = mupen64plus
  706. EMU_FLAGS = --noosd
  707. LOADER = loader64
  708. LOADER_FLAGS = -vwf
  709. SHA1SUM = sha1sum
  710. ZEROTERM = $(PYTHON) $(TOOLS_DIR)/zeroterm.py
  711.  
  712. ###################### Dependency Check #####################
  713.  
  714. # Stubbed
  715.  
  716. ######################## Targets #############################
  717.  
  718. all: $(EXE)
  719.  
  720. # thank you apple very cool
  721. ifeq ($(HOST_OS),Darwin)
  722. CP := gcp
  723. else
  724. CP := cp
  725. endif
  726.  
  727. ifeq ($(EXTERNAL_DATA),1)
  728.  
  729. BASEPACK_PATH := $(BUILD_DIR)/$(BASEDIR)/$(BASEPACK)
  730. BASEPACK_LST := $(BUILD_DIR)/basepack.lst
  731.  
  732. # depend on resources as well
  733. all: $(BASEPACK_PATH)
  734.  
  735. # phony target for building resources
  736. res: $(BASEPACK_PATH)
  737.  
  738. # prepares the basepack.lst
  739. $(BASEPACK_LST): $(EXE)
  740. @mkdir -p $(BUILD_DIR)/$(BASEDIR)
  741. @touch $(BASEPACK_LST)
  742. @echo "$(BUILD_DIR)/sound/bank_sets sound/bank_sets" >> $(BASEPACK_LST)
  743. @echo "$(BUILD_DIR)/sound/sequences.bin sound/sequences.bin" >> $(BASEPACK_LST)
  744. @echo "$(BUILD_DIR)/sound/sound_data.ctl sound/sound_data.ctl" >> $(BASEPACK_LST)
  745. @echo "$(BUILD_DIR)/sound/sound_data.tbl sound/sound_data.tbl" >> $(BASEPACK_LST)
  746. @$(foreach f, $(wildcard $(SKYTILE_DIR)/*), echo $(f) gfx/$(f:$(BUILD_DIR)/%=%) >> $(BASEPACK_LST);)
  747. @find actors -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
  748. @find levels -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
  749. @find textures -name \*.png -exec echo "{} gfx/{}" >> $(BASEPACK_LST) \;
  750.  
  751. # prepares the resource ZIP with base data
  752. $(BASEPACK_PATH): $(BASEPACK_LST)
  753. @$(PYTHON) $(TOOLS_DIR)/mkzip.py $(BASEPACK_LST) $(BASEPACK_PATH)
  754.  
  755. endif
  756.  
  757. clean:
  758. $(RM) -r $(BUILD_DIR_BASE)
  759.  
  760. cleantools:
  761. $(MAKE) -s -C tools clean
  762.  
  763. distclean:
  764. $(RM) -r $(BUILD_DIR_BASE)
  765. ./extract_assets.py --clean
  766.  
  767. test: $(ROM)
  768. $(EMULATOR) $(EMU_FLAGS) $<
  769.  
  770. load: $(ROM)
  771. $(LOADER) $(LOADER_FLAGS) $<
  772.  
  773. $(BUILD_DIR)/$(RPC_LIBS):
  774. @$(CP) -f $(RPC_LIBS) $(BUILD_DIR)
  775.  
  776. libultra: $(BUILD_DIR)/libultra.a
  777.  
  778. $(BUILD_DIR)/asm/boot.o: $(IPL3_RAW_FILES)
  779. $(BUILD_DIR)/src/game/crash_screen.o: $(CRASH_TEXTURE_C_FILES)
  780.  
  781. $(BUILD_DIR)/lib/rsp.o: $(BUILD_DIR)/rsp/rspboot.bin $(BUILD_DIR)/rsp/fast3d.bin $(BUILD_DIR)/rsp/audio.bin
  782.  
  783. #Required so the compiler doesn't complain about this not existing.
  784. $(BUILD_DIR)/src/game/camera.o: $(BUILD_DIR)/include/text_strings.h
  785.  
  786. $(BUILD_DIR)/include/text_strings.h: include/text_strings.h.in
  787. $(TEXTCONV) charmap.txt $< $@
  788.  
  789. $(BUILD_DIR)/include/text_menu_strings.h: include/text_menu_strings.h.in
  790. $(TEXTCONV) charmap_menu.txt $< $@
  791.  
  792. $(BUILD_DIR)/include/text_options_strings.h: include/text_options_strings.h.in
  793. $(TEXTCONV) charmap.txt $< $@
  794.  
  795. ifeq ($(VERSION),eu)
  796. TEXT_DIRS := text/de text/us text/fr
  797.  
  798. # EU encoded text inserted into individual segment 0x19 files,
  799. # and course data also duplicated in leveldata.c
  800. $(BUILD_DIR)/bin/eu/translation_en.o: $(BUILD_DIR)/text/us/define_text.inc.c
  801. $(BUILD_DIR)/bin/eu/translation_de.o: $(BUILD_DIR)/text/de/define_text.inc.c
  802. $(BUILD_DIR)/bin/eu/translation_fr.o: $(BUILD_DIR)/text/fr/define_text.inc.c
  803. $(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/us/define_courses.inc.c
  804. $(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/de/define_courses.inc.c
  805. $(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/fr/define_courses.inc.c
  806.  
  807. else
  808. ifeq ($(VERSION),sh)
  809. TEXT_DIRS := text/jp
  810. $(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/jp/define_text.inc.c
  811.  
  812. else
  813. TEXT_DIRS := text/$(VERSION)
  814.  
  815. # non-EU encoded text inserted into segment 0x02
  816. $(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/$(VERSION)/define_text.inc.c
  817. endif
  818. endif
  819.  
  820. $(BUILD_DIR)/text/%/define_courses.inc.c: text/define_courses.inc.c text/%/courses.h
  821. $(CPP) $(VERSION_CFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
  822.  
  823. $(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h text/%/dialogs.h
  824. $(CPP) $(VERSION_CFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
  825.  
  826. RSP_DIRS := $(BUILD_DIR)/rsp
  827. ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(ASM_DIRS) $(GODDARD_SRC_DIRS) $(ULTRA_SRC_DIRS) $(ULTRA_ASM_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) include) $(MIO0_DIR) $(addprefix $(MIO0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION) $(RSP_DIRS)
  828.  
  829. # Make sure build directory exists before compiling anything
  830. DUMMY != mkdir -p $(ALL_DIRS)
  831.  
  832. $(BUILD_DIR)/include/text_strings.h: $(BUILD_DIR)/include/text_menu_strings.h
  833. $(BUILD_DIR)/include/text_strings.h: $(BUILD_DIR)/include/text_options_strings.h
  834.  
  835. ifeq ($(VERSION),eu)
  836. $(BUILD_DIR)/src/menu/file_select.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  837. $(BUILD_DIR)/src/menu/star_select.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  838. $(BUILD_DIR)/src/game/ingame_menu.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  839. $(BUILD_DIR)/src/game/options_menu.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  840. O_FILES += $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  841. ifeq ($(DISCORDRPC),1)
  842. $(BUILD_DIR)/src/pc/discord/discordrpc.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
  843. endif
  844. else
  845. $(BUILD_DIR)/src/menu/file_select.o: $(BUILD_DIR)/include/text_strings.h
  846. $(BUILD_DIR)/src/menu/star_select.o: $(BUILD_DIR)/include/text_strings.h
  847. $(BUILD_DIR)/src/game/ingame_menu.o: $(BUILD_DIR)/include/text_strings.h
  848. $(BUILD_DIR)/src/game/options_menu.o: $(BUILD_DIR)/include/text_strings.h
  849. ifeq ($(DISCORDRPC),1)
  850. $(BUILD_DIR)/src/pc/discord/discordrpc.o: $(BUILD_DIR)/include/text_strings.h
  851. endif
  852. endif
  853.  
  854. ################################################################
  855. # TEXTURE GENERATION #
  856. ################################################################
  857.  
  858. # RGBA32, RGBA16, IA16, IA8, IA4, IA1, I8, I4
  859.  
  860. ifeq ($(EXTERNAL_DATA),1)
  861.  
  862. $(BUILD_DIR)/%: %.png
  863. $(ZEROTERM) "$(patsubst %.png,%,$^)" > $@
  864.  
  865. else
  866.  
  867. $(BUILD_DIR)/%: %.png
  868. $(N64GRAPHICS) -i $@ -g $< -f $(lastword $(subst ., ,$@))
  869.  
  870. endif
  871.  
  872. $(BUILD_DIR)/%.inc.c: $(BUILD_DIR)/% %.png
  873. hexdump -v -e '1/1 "0x%X,"' $< > $@
  874. echo >> $@
  875.  
  876. ifeq ($(EXTERNAL_DATA),0)
  877.  
  878. # Color Index CI8
  879. $(BUILD_DIR)/%.ci8: %.ci8.png
  880. $(N64GRAPHICS_CI) -i $@ -g $< -f ci8
  881.  
  882. # Color Index CI4
  883. $(BUILD_DIR)/%.ci4: %.ci4.png
  884. $(N64GRAPHICS_CI) -i $@ -g $< -f ci4
  885.  
  886. endif
  887.  
  888. ################################################################
  889.  
  890. # compressed segment generation
  891.  
  892. # PC Area
  893. $(BUILD_DIR)/%.table: %.aiff
  894. $(AIFF_EXTRACT_CODEBOOK) $< >$@
  895.  
  896. $(BUILD_DIR)/%.aifc: $(BUILD_DIR)/%.table %.aiff
  897. $(VADPCM_ENC) -c $^ $@
  898.  
  899. $(BUILD_DIR)/rsp/%.bin $(BUILD_DIR)/rsp/%_data.bin: rsp/%.s
  900. $(RSPASM) -sym $@.sym -definelabel $(VERSION_DEF) 1 -definelabel $(GRUCODE_DEF) 1 -strequ CODE_FILE $(BUILD_DIR)/rsp/$*.bin -strequ DATA_FILE $(BUILD_DIR)/rsp/$*_data.bin $<
  901.  
  902. $(ENDIAN_BITWIDTH): tools/determine-endian-bitwidth.c
  903. $(CC) -c $(CFLAGS) -o $@.dummy2 $< 2>$@.dummy1; true
  904. grep -o 'msgbegin --endian .* --bitwidth .* msgend' $@.dummy1 > $@.dummy2
  905. head -n1 <$@.dummy2 | cut -d' ' -f2-5 > $@
  906. @rm $@.dummy1
  907. @rm $@.dummy2
  908.  
  909. $(SOUND_BIN_DIR)/sound_data.ctl: sound/sound_banks/ $(SOUND_BANK_FILES) $(SOUND_SAMPLE_AIFCS) $(ENDIAN_BITWIDTH)
  910. $(PYTHON) tools/assemble_sound.py $(BUILD_DIR)/sound/samples/ sound/sound_banks/ $(SOUND_BIN_DIR)/sound_data.ctl $(SOUND_BIN_DIR)/sound_data.tbl $(VERSION_CFLAGS) $$(cat $(ENDIAN_BITWIDTH))
  911.  
  912. $(SOUND_BIN_DIR)/sound_data.tbl: $(SOUND_BIN_DIR)/sound_data.ctl
  913. @true
  914.  
  915. ifeq ($(VERSION),sh)
  916. $(SOUND_BIN_DIR)/sequences.bin: $(SOUND_BANK_FILES) sound/sequences.json sound/sequences/ sound/sequences/jp/ $(SOUND_SEQUENCE_FILES) $(ENDIAN_BITWIDTH)
  917. $(PYTHON) tools/assemble_sound.py --sequences $@ $(SOUND_BIN_DIR)/bank_sets sound/sound_banks/ sound/sequences.json $(SOUND_SEQUENCE_FILES) $(VERSION_CFLAGS) $$(cat $(ENDIAN_BITWIDTH))
  918. else
  919. $(SOUND_BIN_DIR)/sequences.bin: $(SOUND_BANK_FILES) sound/sequences.json sound/sequences/ sound/sequences/$(VERSION)/ $(SOUND_SEQUENCE_FILES) $(ENDIAN_BITWIDTH)
  920. $(PYTHON) tools/assemble_sound.py --sequences $@ $(SOUND_BIN_DIR)/bank_sets sound/sound_banks/ sound/sequences.json $(SOUND_SEQUENCE_FILES) $(VERSION_CFLAGS) $$(cat $(ENDIAN_BITWIDTH))
  921. endif
  922.  
  923. $(SOUND_BIN_DIR)/bank_sets: $(SOUND_BIN_DIR)/sequences.bin
  924. @true
  925.  
  926. $(SOUND_BIN_DIR)/%.m64: $(SOUND_BIN_DIR)/%.o
  927. $(OBJCOPY) -j .rodata $< -O binary $@
  928.  
  929. $(SOUND_BIN_DIR)/%.o: $(SOUND_BIN_DIR)/%.s
  930. $(AS) $(ASFLAGS) -o $@ $<
  931.  
  932. ifeq ($(EXTERNAL_DATA),1)
  933.  
  934. $(SOUND_BIN_DIR)/%.inc.c: $(SOUND_BIN_DIR)/%
  935. $(ZEROTERM) "$(patsubst $(BUILD_DIR)/%,%,$^)" | hexdump -v -e '1/1 "0x%X,"' > $@
  936.  
  937. else
  938.  
  939. $(SOUND_BIN_DIR)/%.inc.c: $(SOUND_BIN_DIR)/%
  940. hexdump -v -e '1/1 "0x%X,"' $< > $@
  941. echo >> $@
  942.  
  943. endif
  944.  
  945. $(SOUND_BIN_DIR)/sound_data.o: $(SOUND_BIN_DIR)/sound_data.ctl.inc.c $(SOUND_BIN_DIR)/sound_data.tbl.inc.c $(SOUND_BIN_DIR)/sequences.bin.inc.c $(SOUND_BIN_DIR)/bank_sets.inc.c
  946.  
  947. $(BUILD_DIR)/levels/scripts.o: $(BUILD_DIR)/include/level_headers.h
  948.  
  949. $(BUILD_DIR)/include/level_headers.h: levels/level_headers.h.in
  950. $(CPP) -I . levels/level_headers.h.in | $(PYTHON) tools/output_level_headers.py > $(BUILD_DIR)/include/level_headers.h
  951.  
  952. $(BUILD_DIR)/assets/mario_anim_data.c: $(wildcard assets/anims/*.inc.c)
  953. $(PYTHON) tools/mario_anims_converter.py > $@
  954.  
  955. $(BUILD_DIR)/assets/demo_data.c: assets/demo_data.json $(wildcard assets/demos/*.bin)
  956. $(PYTHON) tools/demo_data_converter.py assets/demo_data.json $(VERSION_CFLAGS) > $@
  957.  
  958. # Source code
  959. $(BUILD_DIR)/levels/%/leveldata.o: OPT_FLAGS := -g
  960. $(BUILD_DIR)/actors/%.o: OPT_FLAGS := -g
  961. $(BUILD_DIR)/bin/%.o: OPT_FLAGS := -g
  962. $(BUILD_DIR)/src/goddard/%.o: OPT_FLAGS := -g
  963. $(BUILD_DIR)/src/goddard/%.o: MIPSISET := -mips1
  964. $(BUILD_DIR)/src/audio/%.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0
  965. $(BUILD_DIR)/src/audio/load.o: OPT_FLAGS := -O2 -framepointer -Wo,-loopunroll,0
  966. $(BUILD_DIR)/lib/src/%.o: OPT_FLAGS :=
  967. $(BUILD_DIR)/lib/src/math/ll%.o: MIPSISET := -mips3 -32
  968. $(BUILD_DIR)/lib/src/math/%.o: OPT_FLAGS := -O2
  969. $(BUILD_DIR)/lib/src/math/ll%.o: OPT_FLAGS :=
  970. $(BUILD_DIR)/lib/src/ldiv.o: OPT_FLAGS := -O2
  971. $(BUILD_DIR)/lib/src/string.o: OPT_FLAGS := -O2
  972. $(BUILD_DIR)/lib/src/gu%.o: OPT_FLAGS := -O3
  973. $(BUILD_DIR)/lib/src/al%.o: OPT_FLAGS := -O3
  974.  
  975. ifeq ($(VERSION),eu)
  976. $(BUILD_DIR)/lib/src/_Litob.o: OPT_FLAGS := -O3
  977. $(BUILD_DIR)/lib/src/_Ldtob.o: OPT_FLAGS := -O3
  978. $(BUILD_DIR)/lib/src/_Printf.o: OPT_FLAGS := -O3
  979. $(BUILD_DIR)/lib/src/sprintf.o: OPT_FLAGS := -O3
  980.  
  981. # enable loop unrolling except for external.c (external.c might also have used
  982. # unrolling, but it makes one loop harder to match)
  983. $(BUILD_DIR)/src/audio/%.o: OPT_FLAGS := -O2
  984. $(BUILD_DIR)/src/audio/load.o: OPT_FLAGS := -O2
  985. $(BUILD_DIR)/src/audio/external.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0
  986. else
  987.  
  988. # The source-to-source optimizer copt is enabled for audio. This makes it use
  989. # acpp, which needs -Wp,-+ to handle C++-style comments.
  990. $(BUILD_DIR)/src/audio/effects.o: OPT_FLAGS := -O2 -Wo,-loopunroll,0 -sopt,-inline=sequence_channel_process_sound,-scalaroptimize=1 -Wp,-+
  991. $(BUILD_DIR)/src/audio/synthesis.o: OPT_FLAGS := -O2 -sopt,-scalaroptimize=1 -Wp,-+
  992. #$(BUILD_DIR)/src/audio/seqplayer.o: OPT_FLAGS := -O2 -sopt,-inline_manual,-scalaroptimize=1 -Wp,-+ #-Wo,-v,-bb,-l,seqplayer_list.txt
  993.  
  994. # Add a target for build/eu/src/audio/*.copt to make it easier to see debug
  995. $(BUILD_DIR)/src/audio/%.acpp: src/audio/%.c
  996. $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/acpp $(TARGET_CFLAGS) $(INCLUDE_CFLAGS) $(VERSION_CFLAGS) $(MATCH_CFLAGS) $(GRUCODE_CFLAGS) -D__sgi -+ $< > $@
  997.  
  998. $(BUILD_DIR)/src/audio/seqplayer.copt: $(BUILD_DIR)/src/audio/seqplayer.acpp
  999. $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/copt -signed -I=$< -CMP=$@ -cp=i -scalaroptimize=1 -inline_manual
  1000.  
  1001. $(BUILD_DIR)/src/audio/%.copt: $(BUILD_DIR)/src/audio/%.acpp
  1002. $(QEMU_IRIX) -silent -L $(IRIX_ROOT) $(IRIX_ROOT)/usr/lib/copt -signed -I=$< -CMP=$@ -cp=i -scalaroptimize=1
  1003.  
  1004. endif
  1005.  
  1006. # Rebuild files with 'GLOBAL_ASM' if the NON_MATCHING flag changes.
  1007. $(GLOBAL_ASM_O_FILES): $(GLOBAL_ASM_DEP).$(NON_MATCHING)
  1008. $(GLOBAL_ASM_DEP).$(NON_MATCHING):
  1009. @rm -f $(GLOBAL_ASM_DEP).*
  1010. touch $@
  1011.  
  1012. $(BUILD_DIR)/%.o: %.cpp
  1013. @$(CXX) -fsyntax-only $(CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
  1014. $(CXX) -c $(CFLAGS) -o $@ $<
  1015.  
  1016. $(BUILD_DIR)/%.o: %.c
  1017. @$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
  1018. $(CC) -c $(CFLAGS) -o $@ $<
  1019.  
  1020.  
  1021. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
  1022. @$(CC_CHECK) $(CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $(BUILD_DIR)/$*.d $<
  1023. $(CC) -c $(CFLAGS) -o $@ $<
  1024.  
  1025. $(BUILD_DIR)/%.o: %.s
  1026. $(AS) $(ASFLAGS) -MD $(BUILD_DIR)/$*.d -o $@ $<
  1027.  
  1028.  
  1029.  
  1030. $(EXE): $(O_FILES) $(MIO0_FILES:.mio0=.o) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(BUILD_DIR)/$(RPC_LIBS)
  1031. $(LD) -L $(BUILD_DIR) -o $@ $(O_FILES) $(SOUND_OBJ_FILES) $(ULTRA_O_FILES) $(GODDARD_O_FILES) $(LDFLAGS)
  1032.  
  1033. .PHONY: all clean distclean default diff test load libultra res
  1034. .PRECIOUS: $(BUILD_DIR)/bin/%.elf $(SOUND_BIN_DIR)/%.ctl $(SOUND_BIN_DIR)/%.tbl $(SOUND_SAMPLE_TABLES) $(SOUND_BIN_DIR)/%.s $(BUILD_DIR)/%
  1035. .DELETE_ON_ERROR:
  1036.  
  1037. # Remove built-in rules, to improve performance
  1038. MAKEFLAGS += --no-builtin-rules
  1039.  
  1040. -include $(DEP_FILES)
  1041.  
  1042. print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
  1043.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement