aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
blob: ceb9d5143cb1e7fe48f33a23095b098c4b5d3c1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# gbos - Game Boy Color Unix-flavored microkernel (scaffold)
# Toolchain: RGBDS (rgbasm/rgblink/rgbfix)

ROM      := gbos.gb
BUILD    := build
SRCS     := $(wildcard src/*.asm)
OBJS     := $(patsubst src/%.asm,$(BUILD)/%.o,$(SRCS))

ASFLAGS  := -I include -Wall
# MBC5 + RAM + battery; -r 3 = 32 KiB cart RAM (bump for more task banks)
FIXFLAGS := -v -C -m MBC5+RAM+BATTERY -r 4 -p 0xFF -t GBOS

.PHONY: all clean run

all: $(ROM)

$(BUILD)/%.o: src/%.asm | $(BUILD)
	rgbasm $(ASFLAGS) -o $@ $<

# C programs: compiled with SDCC into ROM-bank blobs and INCBIN'd by programs.asm
CBLOBS := c/chello.bin c/echo.bin c/true.bin c/false.bin c/uname.bin \
          c/pid.bin c/cat.bin c/wc.bin c/head.bin c/args.bin \
          c/ls.bin c/save.bin c/rm.bin c/sh.bin c/ps.bin c/kill.bin c/spin.bin c/blk.bin c/mkdir.bin c/count.bin c/ptest.bin
$(BUILD)/programs.o: $(CBLOBS)

# C programs also depend on the shared libc sources
$(CBLOBS): c/libc.c c/gbos.h

c/%.bin: c/%.c c/crt0.s c/libc.s c/build.sh
	sh c/build.sh $< $@

$(ROM): $(OBJS)
	rgblink -m $(BUILD)/gbos.map -n $(BUILD)/gbos.sym -o $@ $(OBJS)
	rgbfix $(FIXFLAGS) $@

$(BUILD):
	mkdir -p $(BUILD)

clean:
	rm -rf $(BUILD) $(ROM)

# convenience: run in an emulator if one is on PATH
run: $(ROM)
	@which sameboy >/dev/null 2>&1 && sameboy $(ROM) || \
	 which bgb >/dev/null 2>&1 && bgb $(ROM) || \
	 echo "no emulator found (sameboy/bgb)"