GBDK libraries documentation
PrevChapter 1. Using GBDK and maccerNext

Using Makefiles

One of the most useful development tools is 'make', a program that automatically keeps your object files and images up to date with your source code. It works by having a set of rules of how to get from one file type to another, which normally involves running a program. For example by typing 'make image.gb' make will look for a C or assembler file called image.c or image.s, compile it and link it automatically creating the image image.gb. It really comes into its own when you have a project made up of multiple files as it only recompiles those that have changed since the last make.

A copy of GNU make for DOS is available as part of DJGPP. Most Unix systems come with make installed.

A general Makefile for Gameboy projects follows:

AS = lcc -c
CC = lcc -Wa-l -Wl-m

BIN = astro.gb
OBJS =  render.o sin_table.o stars.o debug.o fp_long.o sqrt.o floor.o \
        ftou.o sin_cos.o const.o inv_trig.o

all: $(BIN)

%.s: %.ms
     maccer -o $@ $<

$(BIN): $(OBJS)
     $(CC) -o $(BIN) $(OBJS)

clean:
     rm -f $(BIN) $(OBJS) *~
				
The first two lines convince make to use lcc as the assembler and linker instead of the default system ones. The BIN line specifies the name of the image file you want at the end. The OBJS line specifies what object files must be made for BIN to be built. The %.s: %.ms line tells make how to generate .s files for lcc from .ms (macro) files.

For example, suppose that I change the assembler file 'render.ms'. When make is run, it will find that astro.gb depends on render.o which in turn depends on render.ms. It will then use maccer to change the astro.ms file to astro.s, then it will use lcc to assemble astro.s to astro.o which is finally linked with all the other .o files to create astro.gb


PrevHomeNext
Using GBDK and maccerUpThe Gameboy as a Target