LEGO Batman^H^H^Hhaxx
[savezelda.git] / batman / 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 := rlbp.bin rlbj.bin rlbe.bin
45
46 ppms := $(targets:%.bin=%-icon.ppm) rlb-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 $@
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: lego.lds exploit.o
81         @echo "  LINK      $@"
82         $(Q)$(LD) -T $^ -o $@
83
84 head.elf: head.o
85         @echo "  LINK      $@"
86         $(Q)$(LD) -e 0 $< -o $@
87
88 exploit.o: exploit.s
89         @echo "  ASSEMBLE  $@"
90         $(Q)$(CC) $(CFLAGS) -c $< -o $@
91
92 head.o: head.s head.b
93         @echo "  ASSEMBLE  $@"
94         $(Q)$(CC) $(CFLAGS) -c $< -o $@
95
96 title.bin: ../.version
97         @echo "  TITLEBIN  $@"
98         $(Q)perl make-title-bin.pl > $@
99
100 ../.version: FORCE
101         $(Q)$(MAKE) -C .. .version
102
103 $(ppms): %.ppm: %.png
104         @echo "  PPM       $@"
105         $(Q)convert $< $@
106
107 $(loader): FORCE
108         $(Q)$(MAKE) -C ../loader
109
110 FORCE:
111
112 clean:
113         -rm -f $(targets) FILE_V28
114         -rm -f exploit.bin exploit.elf exploit.o
115         -rm -f head.bin head.elf head.o
116         -rm -f title.bin