LEGO Indiana Jones
[savezelda.git] / lego / 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 := rlie.bin rlij.bin rlip.bin
45
46 ppms := $(targets:%.bin=%-icon.ppm) rli-banner.ppm
47 assets := title.bin $(ppms)
48
49 loader := ../loader/loader.bin
50
51
52 titleid = $(shell perl titleid.pl $(1))
53
54
55 define twintig
56         D=$(call titleid,$(1));                         \
57         $(TOOLS)/twintig $$D $@ toc-$1
58 endef
59
60
61 all: $(targets)
62
63 $(targets): %.bin: toc-% FILE_V28 $(assets)
64         @echo "  TWINTIG   $@"
65         $(Q)$(call twintig,$*)
66
67 FILE_V28: head.bin exploit.bin $(loader)
68         @echo "  LEGOSTACK $@"
69         $(Q)./pack.sh $@ $^
70         $(Q)$(TOOLS)/lego-cksum $@ 32688
71
72 head.bin: head.elf
73         @echo "  OBJCOPY   $@"
74         $(Q)$(OBJCOPY) -Obinary $< $@
75
76 exploit.bin: exploit.elf
77         @echo "  OBJCOPY   $@"
78         $(Q)$(OBJCOPY) -Obinary $< $@
79
80 exploit.elf: baddr := 0x903b0780
81 exploit.elf: lego.lds exploit.o
82         @echo "  LINK      $@"
83         $(Q)$(LD) --defsym baddr=$(baddr) -T $^ -o $@
84
85 head.elf: head.lds head.o
86         @echo "  LINK      $@"
87         $(Q)$(LD) -T $^ -o $@
88
89 exploit.o: exploit.s
90         @echo "  ASSEMBLE  $@"
91         $(Q)$(CC) $(CFLAGS) -c $< -o $@
92
93 head.o: head.s head.b
94         @echo "  ASSEMBLE  $@"
95         $(Q)$(CC) $(CFLAGS) -c $< -o $@
96
97 title.bin: ../.version
98         @echo "  TITLEBIN  $@"
99         $(Q)perl make-title-bin.pl > $@
100
101 ../.version: FORCE
102         $(Q)$(MAKE) -C .. .version
103
104 $(ppms): %.ppm: %.png
105         @echo "  PPM       $@"
106         $(Q)convert $< $@
107
108 $(loader): FORCE
109         $(Q)$(MAKE) -C ../loader
110
111 FORCE:
112
113 clean:
114         -rm -f $(targets) FILE_V28
115         -rm -f exploit.bin exploit.elf exploit.o
116         -rm -f head.bin head.elf head.o
117         -rm -f title.bin