1 # Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
2 # This code is licensed to you under the terms of the GNU GPL, version 2;
3 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
8 # What toolchain prefix should we use
11 # Where are the tools (http://git.infradead.org/users/segher/wii.git)
12 TOOLS ?= $(HOME)/wii/segher
14 # End of configuration.
18 # Set CC, LD, OBJCOPY based on CROSS, unless they are set already
20 ifeq ($(origin CC), default)
21 CC := $(CROSS)gcc -m32
23 ifeq ($(origin LD), default)
26 OBJCOPY ?= $(CROSS)objcopy
29 # The compiler flags we need.
31 CFLAGS := -Wall -W -Os -ffreestanding -mno-eabi -mno-sdata -mcpu=750
34 # Build with "V=1" to see the commands executed; be quiet otherwise.
40 MAKEFLAGS += --no-print-directory
44 targets := rzde-3.2.bin rzde-3.3.bin rzde-3.4.bin
45 targets += rzdj-3.2.bin rzdj-3.3.bin rzdj-3.4.bin
46 targets += rzdp-3.2.bin rzdp-3.3.bin rzdp-3.4.bin
47 targets-short := rzde rzdj rzdp
51 ppms := $(targets-short:%=%-icon.ppm) generic-banner.ppm
52 assets := title.bin $(ppms)
54 loader := loader/loader.bin
57 titleid = $(shell perl titleid.pl $(1))
60 # System menu 3.3 checks for the exploit, when a) you copy a save from SD,
61 # and b) when the menu starts up; but for a) it only looks at the first
62 # zeldaTp.dat file, and for b) it allows any file of non-aligned length.
64 # System menu 3.4 only looks at the last file in the wad when installing.
66 # System menu 4.0 finally avoids such silly bugs.
69 D=$(call titleid,$(1)); \
70 $(TOOLS)/twintig $$D $@ toc-$1
76 $(filter %-3.2.bin,$(targets)): %-3.2.bin: %.data
77 $(filter %-3.3.bin,$(targets)): %-3.3.bin: %.data zero16k
78 $(filter %-3.4.bin,$(targets)): %-3.4.bin: %.data FAILURE
79 $(targets): %.bin: toc-% $(assets)
81 $(Q)$(call twintig,$*)
83 saves := $(targets-short:%=%.data)
85 rzde.data: rzde0.slot rzde2.slot
90 $(Q)./pack.sh $@ $(filter %.slot,$^)
91 $(Q)$(TOOLS)/zelda-cksum $@
92 $(Q)cat $(loader) >> $@
95 slots := rzde0.slot rzde2.slot rzdj0.slot rzdp0.slot
97 $(slots): %.slot: %.elf
99 $(Q)$(OBJCOPY) -Obinary $< $@
101 elfs := $(slots:.slot=.elf)
103 rzde0.elf: baddr := 0x8046a3e0+0
104 rzde2.elf: baddr := 0x804519e0+0x0a94
105 rzdj0.elf: baddr := 0x8044f860+0
106 rzdp0.elf: baddr := 0x804522e0+0
107 $(elfs): %.elf: twilight.lds %.o $(objs)
109 $(Q)$(LD) --defsym baddr=$(baddr) -T $^ -o $@
111 exploit-objs := $(elfs:.elf=.o)
113 $(exploit-objs): slot-name := Twilight Hack
114 rzde0.o: slot-name := TwilightHack0
115 rzde2.o: slot-name := TwilightHack2
116 $(exploit-objs): %.o: start.S head.b
118 $(Q)$(CC) $(CFLAGS) -D NAME="$(slot-name)" -c $< -o $@
122 $(Q)$(CC) $(CFLAGS) -c $< -o $@
126 $(Q)perl make-title-bin.pl > $@
129 $(Q)./describe.sh > .$@-tmp
130 $(Q)cmp -s $@ .$@-tmp || cp .$@-tmp $@
133 $(ppms): %.ppm: %.png
138 $(Q)dd if=/dev/zero bs=16384 count=1 2>/dev/null > $@
141 $(Q)echo FAILURE > $@
143 $(loader): FORCE .version
144 $(Q)$(MAKE) -C loader
149 -rm -f $(targets) $(saves) $(elfs) $(exploit-objs) $(objs) $(slots)
150 -rm -f .version title.bin zero16k FAILURE
151 $(MAKE) -C loader clean