5 Building a Classic MacOS app
Uli Kusterer edited this page 2022-10-16 14:11:42 +02:00

This tutorial assumes that you've set up mpw already.

Building the standard SillyBalls example that comes with MPW

Create a folder named mpw-sillyballs to hold your project (you can choose any name here, but that's what we'll call it going forward).

Obtain the C source code

Find the SillyBalls.c example included with your copy of MPW from Apple. For MPW 3.5, it is at MPW/Examples/CExamples/SillyBalls.c. Copy it into the mpw-sillyballs folder.

Creating a resource file

Every application on classic MacOS needs a few resources that describe the application and its UI. Those are usually defined in a resource file. You can define this resource file in a text description language named Rez. We'll create a minimal resource file named SillyBalls.r that just tells the operating system about our application's abilities:

#include <SysTypes.r>
#include <Types.r>

/* here is the quintessential MultiFinder friendliness device, the SIZE resource */

resource 'SIZE' (-1) {
	dontSaveScreen,
	acceptSuspendResumeEvents,
	enableOptionSwitch,
	canBackground,                  /* we can background; we don't currently, but our sleep value */
                                        /* guarantees we don't hog the Mac while we are in the background */
	multiFinderAware,               /* this says we do our own activate/deactivate; don't fake us out */
	backgroundAndForeground,        /* this is definitely not a background-only application! */
	dontGetFrontClicks,             /* change this if you want "do first click" behavior like the Finder */
	ignoreChildDiedEvents,          /* essentially, I'm not a debugger (sub-launching) */
	is32BitCompatible,              /* this app is safe to run in 32-bit address space */
	reserved,
	reserved,
	reserved,
	reserved,
	reserved,
	reserved,
	reserved,
	23 * 1024,        /* 23k Preferred max. RAM */
	35 * 1024	  /* 35k Minimal RAM limit */
};

Create the Makefile for building this app

# This should point to wherever you've installed the 'mpw' tool from this repository:
MPW=/usr/local/bin/mpw

RINCLUDES=~/mpw/Interfaces/RIncludes

# 'SILB' is the unique "creator code" for this Silly Balls app, and used to associate icons
# with the app and its documents, and tell Finder to use this app to open a file. Make up
# your own unique 4-character code for your app here.
LDFLAGS =-w -c 'SILB' -t APPL \
	-sn STDIO=Main -sn INTENV=Main -sn %A5Init=Main

PPC_LDFLAGS =-m main -w -c 'SILB' -t APPL

LIBRARIES={Libraries}Stubs.o \
	{Libraries}MacRuntime.o \
	{Libraries}IntEnv.o \
	{Libraries}Interface.o \
	{Libraries}ToolLibs.o \
	{CLibraries}StdCLib.o

PPC_LIBRARIES={SharedLibraries}InterfaceLib \
	{SharedLibraries}StdCLib \
	{PPCLibraries}StdCRuntime.o \
	{PPCLibraries}PPCCRuntime.o

TOOLBOXFLAGS=-d OLDROUTINENAMES=1 -typecheck relaxed

SOURCES=SillyBalls.c

OBJECTS=$(SOURCES:%.c=obj/%.68k.o)
PPC_OBJECTS=$(SOURCES:%.c=obj/%.ppc.o)

RFILES=SillyBalls.r
EXECUTABLE=SillyBalls

all: prepass bin/$(EXECUTABLE).ppc bin/$(EXECUTABLE).68k

prepass:
	mkdir -p obj bin

bin/$(EXECUTABLE).ppc: $(PPC_OBJECTS)
	$(MPW) PPCLink $(PPC_LDFLAGS) $(PPC_OBJECTS) $(PPC_LIBRARIES) -o $@; \
	Rez -rd $(RFILES) -o $@ -i $(RINCLUDES) -append

bin/$(EXECUTABLE).68k: $(OBJECTS)
	$(MPW) link $(LDFLAGS) $(OBJECTS) $(LIBRARIES) -o $@
	Rez -rd $(RFILES) -o $@ -i $(RINCLUDES) -append

obj/%.68k.o : %.c
	$(MPW) SC $(TOOLBOXFLAGS) $< -o $@

obj/%.ppc.o : %.c
	$(MPW) MrC $(TOOLBOXFLAGS) $< -o $@; \

clean:
	rm -rf bin obj

Building the app

Just type make all in your mpw-sillyballs directory. The Makefile will now create a bin/SillyBalls.68k and a bin/SillyBalls.ppc executable.