|
| 1 | + |
| 2 | +.SUFFIXES: |
| 3 | + |
| 4 | +################################################ |
| 5 | +# # |
| 6 | +# CONSTANT DEFINITIONS # |
| 7 | +# # |
| 8 | +################################################ |
| 9 | + |
| 10 | +# Directory constants |
| 11 | +SRCDIR := src |
| 12 | +BINDIR := bin |
| 13 | +OBJDIR := obj |
| 14 | +DEPDIR := dep |
| 15 | +RESDIR := res |
| 16 | + |
| 17 | +# Program constants |
| 18 | +ifneq ($(shell which rm),) |
| 19 | + # POSIX OSes |
| 20 | + RM_RF := rm -rf |
| 21 | + MKDIR_P := mkdir -p |
| 22 | + PY := |
| 23 | + filesize = echo 'NB_PB$2_BLOCKS equ (' `wc -c $1 | cut -d ' ' -f 1` ' + $2 - 1) / $2' |
| 24 | +else |
| 25 | + # Windows outside of a POSIX env (Cygwin, MSYS2, etc.) |
| 26 | + # We need Powershell to get any sort of decent functionality |
| 27 | + $(warning Powershell is required to get basic functionality) |
| 28 | + RM_RF := -del /q |
| 29 | + MKDIR_P := -mkdir |
| 30 | + PY := python |
| 31 | + filesize = powershell Write-Output $$('NB_PB$2_BLOCKS equ ' + [string] [int] (([IO.File]::ReadAllBytes('$1').Length + $2 - 1) / $2)) |
| 32 | +endif |
| 33 | + |
| 34 | +# Shortcut if you want to use a local copy of RGBDS |
| 35 | +RGBDS := ../rgbds/ |
| 36 | +RGBASM := $(RGBDS)rgbasm.exe |
| 37 | +RGBLINK := $(RGBDS)rgblink.exe |
| 38 | +RGBFIX := $(RGBDS)rgbfix.exe |
| 39 | +RGBGFX := $(RGBDS)rgbgfx.exe |
| 40 | + |
| 41 | +EMULATOR_EMULICIOUS = ../../Emulicious/Emulicious.exe |
| 42 | +EMULATOR_BGB = ../../bgb64/bgb64.exe |
| 43 | + |
| 44 | +ROMUSAGE := ../../Tools/romusage.exe |
| 45 | + |
| 46 | +ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT) |
| 47 | + |
| 48 | +# Argument constants |
| 49 | +INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/ |
| 50 | +WARNINGS = all extra |
| 51 | +ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS)) |
| 52 | +LDFLAGS = -p $(PADVALUE) |
| 53 | +FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE) |
| 54 | + |
| 55 | +# The list of "root" ASM files that RGBASM will be invoked on |
| 56 | +SRCS = $(wildcard $(SRCDIR)/*.asm) |
| 57 | +INCDIRS = $(SRCDIR)/ $(SRCDIR)/include/ |
| 58 | + |
| 59 | +## Project-specific configuration |
| 60 | +# Use this to override the above |
| 61 | +include project.mk |
| 62 | + |
| 63 | +################################################ |
| 64 | +# # |
| 65 | +# TARGETS # |
| 66 | +# # |
| 67 | +################################################ |
| 68 | + |
| 69 | +# `all` (Default target): build the ROM |
| 70 | +all: $(ROM) |
| 71 | +.PHONY: all |
| 72 | + |
| 73 | +# `clean`: Clean temp and bin files |
| 74 | +clean: |
| 75 | + $(RM_RF) $(BINDIR) |
| 76 | + $(RM_RF) $(OBJDIR) |
| 77 | + $(RM_RF) $(DEPDIR) |
| 78 | + $(RM_RF) $(RESDIR) |
| 79 | +.PHONY: clean |
| 80 | + |
| 81 | +# `rebuild`: Build everything from scratch |
| 82 | +# It's important to do these two in order if we're using more than one job |
| 83 | +rebuild: |
| 84 | + $(MAKE) clean |
| 85 | + $(MAKE) all |
| 86 | +.PHONY: rebuild |
| 87 | + |
| 88 | +runEmulicious: |
| 89 | + $(EMULATOR_EMULICIOUS) $(ROM) |
| 90 | +.PHONY: runEmulicious |
| 91 | + |
| 92 | +runBGB: |
| 93 | + $(EMULATOR_BGB) $(ROM) -watch |
| 94 | +.PHONY: runBGB |
| 95 | + |
| 96 | +romusage: |
| 97 | + $(ROMUSAGE) $(BINDIR)/$(ROMNAME).map -g |
| 98 | +.PHONY: romusage |
| 99 | + |
| 100 | +################################################ |
| 101 | +# # |
| 102 | +# GIT SUBMODULES # |
| 103 | +# # |
| 104 | +################################################ |
| 105 | + |
| 106 | +# By default, cloning the repo does not init submodules |
| 107 | +# If that happens, warn the user |
| 108 | +# Note that the real paths aren't used! |
| 109 | +# Since RGBASM fails to find the files, it outputs the raw paths, not the actual ones. |
| 110 | +hardware.inc/hardware.inc rgbds-structs/structs.asm: |
| 111 | + @echo 'hardware.inc is not present; have you initialized submodules?' |
| 112 | + @echo 'Run `git submodule update --init`, then `make clean`, then `make` again.' |
| 113 | + @echo 'Tip: to avoid this, use `git clone --recursive` next time!' |
| 114 | + @exit 1 |
| 115 | + |
| 116 | +################################################ |
| 117 | +# # |
| 118 | +# RESOURCE FILES # |
| 119 | +# # |
| 120 | +################################################ |
| 121 | + |
| 122 | +# By default, asset recipes convert files in `res/` into other files in `res/` |
| 123 | +# This line causes assets not found in `res/` to be also looked for in `src/res/` |
| 124 | +# "Source" assets can thus be safely stored there without `make clean` removing them |
| 125 | +VPATH := $(SRCDIR) |
| 126 | + |
| 127 | +$(RESDIR)/%.1bpp: $(RESDIR)/%.png |
| 128 | + @$(MKDIR_P) $(@D) |
| 129 | + $(RGBGFX) -d 1 -o $@ $< |
| 130 | + |
| 131 | +$(RESDIR)/%_linear.2bpp: $(RESDIR)/%_linear.png |
| 132 | + @$(MKDIR_P) $(@D) |
| 133 | + $(RGBGFX) -d 2 -o $@ $< |
| 134 | + |
| 135 | +$(RESDIR)/%_map.2bpp $(RESDIR)/%_map.tilemap: $(RESDIR)/%_map.png |
| 136 | + @$(MKDIR_P) $(@D) |
| 137 | + $(RGBGFX) -u -T -d 2 -o $@ $< |
| 138 | + |
| 139 | +$(RESDIR)/%.2bpp: $(RESDIR)/%.png |
| 140 | + @$(MKDIR_P) $(@D) |
| 141 | + $(RGBGFX) -h -d 2 -o $@ $< |
| 142 | + |
| 143 | +# Define how to compress files using the PackBits16 codec |
| 144 | +# Compressor script requires Python 3 |
| 145 | +$(RESDIR)/%.pb16: $(RESDIR)/% $(SRCDIR)/tools/pb16.py |
| 146 | + @$(MKDIR_P) $(@D) |
| 147 | + $(PY) $(SRCDIR)/tools/pb16.py $< $(RESDIR)/$*.pb16 |
| 148 | + |
| 149 | +$(RESDIR)/%.pb16.size: $(RESDIR)/% |
| 150 | + @$(MKDIR_P) $(@D) |
| 151 | + $(call filesize,$<,16) > $(RESDIR)/$*.pb16.size |
| 152 | + |
| 153 | +# Define how to compress files using the PackBits8 codec |
| 154 | +# Compressor script requires Python 3 |
| 155 | +$(RESDIR)/%.pb8: $(RESDIR)/% $(SRCDIR)/tools/pb8.py |
| 156 | + @$(MKDIR_P) $(@D) |
| 157 | + $(PY) $(SRCDIR)/tools/pb8.py $< $(RESDIR)/$*.pb8 |
| 158 | + |
| 159 | +$(RESDIR)/%.pb8.size: $(RESDIR)/% |
| 160 | + @$(MKDIR_P) $(@D) |
| 161 | + $(call filesize,$<,8) > $(RESDIR)/$*.pb8.size |
| 162 | + |
| 163 | +############################################### |
| 164 | +# # |
| 165 | +# COMPILATION # |
| 166 | +# # |
| 167 | +############################################### |
| 168 | + |
| 169 | +# How to build a ROM |
| 170 | +$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS)) |
| 171 | + @$(MKDIR_P) $(@D) |
| 172 | + $(RGBASM) $(ASFLAGS) -o $(OBJDIR)/build_date.o $(SRCDIR)/res/build_date.asm |
| 173 | + $(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ $(OBJDIR)/build_date.o \ |
| 174 | + && $(RGBFIX) -v $(FIXFLAGS) $(BINDIR)/$*.$(ROMEXT) |
| 175 | + |
| 176 | +# `.mk` files are auto-generated dependency lists of the "root" ASM files, to save a lot of hassle. |
| 177 | +# Also add all obj dependencies to the dep file too, so Make knows to remake it |
| 178 | +# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK |
| 179 | +# (and produce weird errors) |
| 180 | +$(OBJDIR)/%.o $(DEPDIR)/%.mk: $(SRCDIR)/%.asm |
| 181 | + @$(MKDIR_P) $(patsubst %/,%,$(dir $(OBJDIR)/$* $(DEPDIR)/$*)) |
| 182 | + $(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $< |
| 183 | + |
| 184 | +ifneq ($(MAKECMDGOALS),clean) |
| 185 | +-include $(patsubst $(SRCDIR)/%.asm,$(DEPDIR)/%.mk,$(SRCS)) |
| 186 | +endif |
| 187 | + |
| 188 | +# Catch non-existent files |
| 189 | +# KEEP THIS LAST!! |
| 190 | +%: |
| 191 | + @false |
0 commit comments