lsw: JPN fix
[savezelda.git] / twilight / Makefile
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
4
5
6 # Configuration:
7
8 # What toolchain prefix should we use
9 CROSS ?= broadway-
10
11 # Where are the tools (http://git.infradead.org/users/segher/wii.git)
12 TOOLS ?= $(HOME)/wii/segher
13
14 # End of configuration.
15
16
17
18 # Set CC, LD, OBJCOPY based on CROSS, unless they are set already
19
20 ifeq ($(origin CC), default)
21         CC := $(CROSS)gcc -m32
22 endif
23 ifeq ($(origin LD), default)
24         LD := $(CROSS)ld
25 endif
26 OBJCOPY ?= $(CROSS)objcopy
27
28
29 # The compiler flags we need.
30
31 CFLAGS := -Wall -W -Os -ffreestanding -mno-eabi -mno-sdata -mcpu=750
32
33
34 # Build with "V=1" to see the commands executed; be quiet otherwise.
35
36 ifeq ($(V),1)
37         Q :=
38 else
39         Q := @
40         MAKEFLAGS += --no-print-directory
41 endif
42
43
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
48
49 objs := twilight.o
50
51 ppms := $(targets-short:%=%-icon.ppm) generic-banner.ppm
52 assets := title.bin $(ppms)
53
54 loader := ../loader/loader.bin
55
56
57 titleid = $(shell perl titleid.pl $(1))
58
59
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.
63 #
64 # System menu 3.4 only looks at the last file in the wad when installing.
65 #
66 # System menu 4.0 finally avoids such silly bugs.
67
68 define twintig
69         D=$(call titleid,$(1));                         \
70         $(TOOLS)/twintig $$D $@ toc-$1
71 endef
72
73
74 all: $(targets)
75
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)
80         @echo "  TWINTIG   $@"
81         $(Q)$(call twintig,$*)
82
83 saves := $(targets-short:%=%.data)
84
85 rzde.data: rzde0.slot rzde2.slot
86 rzdp.data: rzdp0.slot
87 rzdj.data: rzdj0.slot
88 $(saves): $(loader)
89         @echo "  ZELDAPACK $@"
90         $(Q)./pack.sh $@ $(filter %.slot,$^)
91         $(Q)$(TOOLS)/zelda-cksum $@
92         $(Q)cat $(loader) >> $@
93         $(Q)printf '\0' >> $@
94
95 slots := rzde0.slot rzde2.slot rzdj0.slot rzdp0.slot
96
97 $(slots): %.slot: %.elf
98         @echo "  OBJCOPY   $@"
99         $(Q)$(OBJCOPY) -Obinary $< $@
100
101 elfs := $(slots:.slot=.elf)
102
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)
108         @echo "  LINK      $@"
109         $(Q)$(LD) --defsym baddr=$(baddr) -T $^ -o $@
110
111 exploit-objs := $(elfs:.elf=.o)
112
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
117         @echo "  ASSEMBLE  $@"
118         $(Q)$(CC) $(CFLAGS) -D NAME="$(slot-name)" -c $< -o $@
119
120 %.o: %.c
121         @echo "  COMPILE   $@"
122         $(Q)$(CC) $(CFLAGS) -c $< -o $@
123
124 title.bin: ../.version
125         @echo "  TITLEBIN  $@"
126         $(Q)perl make-title-bin.pl > $@
127
128 ../.version: FORCE
129         $(Q)$(MAKE) -C .. .version
130
131 $(ppms): %.ppm: %.png
132         @echo "  PPM       $@"
133         $(Q)convert $< $@
134
135 zero16k:
136         $(Q)dd if=/dev/zero bs=16384 count=1 2>/dev/null > $@
137
138 FAILURE:
139         $(Q)echo FAILURE > $@
140
141 $(loader): FORCE
142         $(Q)$(MAKE) -C ../loader
143
144 FORCE:
145
146 clean:
147         -rm -f $(targets) $(saves) $(elfs) $(exploit-objs) $(objs) $(slots)
148         -rm -f title.bin zero16k FAILURE