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