You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 21, 2025. It is now read-only.
Copy file name to clipboardExpand all lines: Makefile.nw
+46-5Lines changed: 46 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -314,7 +314,7 @@ The \texttt{\$\{@:.mk=.o\}} syntax means “expand to the contents of \texttt{\$
314
314
We also need to inform Make of the dependency files that it should read; but, we don't do so when running \texttt{make clean}, as we don't need dependency info when we're trying to wipe the slate clean!
315
315
<<Assembly rules>>=
316
316
ifeq ($(filter clean,${MAKECMDGOALS}),)
317
-
include $(patsubst src/%.asm,obj/%.mk,${SRCS})
317
+
include ${DEPFILES}
318
318
endif
319
319
@
320
320
Interestingly, Make also treats every such file as a target that needs to be made, and so it will automatically try to generate them if they don't exist yet.
Debugfiles are a recent addition to the Game Boy debugging experience.
346
+
They allow instructing the emulator to perform a lot of debug checks, without having to modify the ROM at all!
347
+
A more complete guide to debugfile macros \href{https://github.com/ISSOtm/debugfile.inc/wiki}{can be found on \texttt{debugfile.inc}'s wiki}; but for now, let's focus on how they are hooked up to the build system.
348
+
349
+
You see, they are implemented in a way you might find a bit strange.
350
+
Unless the symbol \texttt{PRINT\_DEBUGFILE} is defined, the macros from \texttt{debugfile.inc} do \emph{nothing}.
351
+
But if that symbol is defined, they \emph{print} their corresponding debugfile directives.
352
+
That's because this is the only way RGBASM provides of generating such a file; better debugfile integration is planned, but not here yet.
353
+
354
+
So, first, a debugfile can be generated by assembling the corresponding source file while defining the aforementioned symbol.
355
+
That said, we make the rule depend on the \emph{object file}, so that it's only executed after the whole dependency resolution process.
356
+
357
+
<<Assembly rules>>=
358
+
obj/%.dbg: obj/%.o
359
+
${RGBASM} ${ASFLAGS} src/$*.asm -DPRINT_DEBUGFILE
360
+
@
361
+
362
+
This generates one debugfile per source file, but by default, an emulator will only auto-load a single debugfile (and if it has the appropriate name, hence the use of \texttt{ROMNAME} here).
363
+
Thus, we also generate a “master file”, which includes all of the sub-files.
364
+
365
+
<<Assembly rules>>=
366
+
bin/${ROMNAME}.dbg: ${SRCS}
367
+
echo @debugfile 1.0 >$@
368
+
printf '@include "../%s"\n' ${DEBUGFILES} >>$@
369
+
@
370
+
371
+
Since the debugfile is made to depend on each source file, creating a new source file re-generates the list of debugfiles.
372
+
However, note that \emph{deleting} a source file will not invalidate the list; this is a limitation that I do not know how to solve with Make.
373
+
Please feel free to send a pull request or to contact me if you know how to solve this.
374
+
341
375
\subsubsection{Submodules}
342
376
343
377
A Git “submodule” is, largely, a Git repository inside of a Git repository; this has the benefit of making it easier to update the submodules, but the downside of being a little quirky.
@@ -347,6 +381,8 @@ By default, cloning the repo does not initialise submodules (so they are empty);
347
381
Note that the real paths aren't used!
348
382
Since RGBASM fails to find the files, it outputs the path(s) as passed to \texttt{include}, not where the file would actually be found (e.g. \texttt{src/hardware.inc/hardware.inc}).
349
383
384
+
\pagebreak % Otherwise the "header line" is on a different page than the code >_<
@echo '$@ is not present; have you initialized submodules?'
@@ -372,7 +408,7 @@ Since this is a commonly desirable feature, these names are common conventions.
372
408
It is also a little special, as it is the \emph{first} rule in the file (as we will see in \autoref{sec:overall}), it is also the “default” target, i.e. what Make selects as its target if invoked without one (just \texttt{make}).
373
409
374
410
<<Phony rules>>=
375
-
all: ${ROM}
411
+
all: ${ROM} ${DEBUGFILES} bin/${ROMNAME}.dbg
376
412
.PHONY: all
377
413
378
414
@
@@ -383,8 +419,6 @@ all: ${ROM}
383
419
384
420
(As we have seen in \autoref{sec:auto-discovery}, we also made it a little special, its presence suppressing dependency auto-discovery.)
385
421
386
-
\pagebreak
387
-
388
422
<<Phony rules>>=
389
423
clean:
390
424
rm -rf bin obj assets
@@ -413,7 +447,7 @@ This allows the following to work:
413
447
\begin{pygmented}[lang=console]
414
448
$ ls ~/rgbds-0.9.1
415
449
rgbasm rgbfix rgbgfx rgblink
416
-
$ export RGBDS=~/rgbds-0.9.1
450
+
$ export RGBDS=~/rgbds-0.9.1/
417
451
$ make
418
452
~/rgbds-0.9.1/rgbasm -p 0xFF (etc.)
419
453
\end{pygmented}
@@ -433,7 +467,14 @@ And some file names:
433
467
<<Configuration>>=
434
468
ROM = bin/${ROMNAME}.${ROMEXT}
435
469
SRCS := $(call rwildcard,src,*.asm)
470
+
@
436
471
472
+
Then some lists of files that will be generated from that list of sources, for convenience:
473
+
474
+
<<Configuration>>=
475
+
OBJS := $(patsubst src/%.asm,obj/%.o,${SRCS})
476
+
DEPFILES := ${OBJS:.o=.mk}
477
+
DEBUGFILES := ${OBJS:.o=.dbg}
437
478
@
438
479
439
480
And, last but not least, including the file containing project-specific configuration.
0 commit comments