lsw: JPN fix
[savezelda.git] / lsw / Makefile
1 # Copyright 2008-2009  Segher Boessenkool  <segher@kernel.crashing.org>
2 # Copyright      2011  roto <roto@mozy.org>
3 # Copyright      2011  Bernhard Urban <lewurm@gmail.com>
4 # This code is licensed to you under the terms of the GNU GPL, version 2;
5 # see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
6
7
8 # Configuration:
9
10 # What toolchain prefix should we use
11 CROSS ?= broadway-
12
13 # Where are the tools (http://git.infradead.org/users/segher/wii.git)
14 TOOLS ?= $(HOME)/wii/segher
15
16 # End of configuration.
17
18
19
20 # Set CC, LD, OBJCOPY based on CROSS, unless they are set already
21
22 ifeq ($(origin CC), default)
23         CC := $(CROSS)gcc -m32
24 endif
25 ifeq ($(origin LD), default)
26         LD := $(CROSS)ld
27 endif
28 OBJCOPY ?= $(CROSS)objcopy
29
30
31 # The compiler flags we need.
32
33 CFLAGS := -Wall -W -Os -ffreestanding -mno-eabi -mno-sdata -mcpu=750
34
35
36 # Build with "V=1" to see the commands executed; be quiet otherwise.
37
38 ifeq ($(V),1)
39         Q :=
40 else
41         Q := @
42         MAKEFLAGS += --no-print-directory
43 endif
44
45
46 targets := rlge.bin rlgp.bin rlgj.bin
47
48 ppms := $(targets:%.bin=%-icon.ppm) generic-banner.ppm
49 assets := title.bin $(ppms)
50
51 loader := ../loader/loader.bin
52
53
54 titleid = $(shell perl titleid.pl $(1))
55
56
57 define twintig
58         D=$(call titleid,$(1));                         \
59         $(TOOLS)/twintig $$D $@ toc-$1
60 endef
61
62
63 all: $(targets)
64
65 $(targets): %.bin: toc-% FILE_V28 $(assets)
66         @echo "  TWINTIG   $@"
67         $(Q)$(call twintig,$*)
68
69 FILE_V28: head.bin exploit.bin $(loader)
70         @echo "  LEGOSTACK $@"
71         $(Q)./pack.sh $@ $^
72         $(Q)$(TOOLS)/lego-cksum $@ 32380 #32328 #32688
73
74 head.bin: head.elf
75         @echo "  OBJCOPY   $@"
76         $(Q)$(OBJCOPY) -Obinary $< $@
77
78 exploit.bin: exploit.elf
79         @echo "  OBJCOPY   $@"
80         $(Q)$(OBJCOPY) -Obinary $< $@
81
82 exploit.elf: lego.lds exploit.o
83         @echo "  LINK      $@"
84         $(Q)$(LD) -T $^ -o $@
85
86 head.elf: head.o
87         @echo "  LINK      $@"
88         $(Q)$(LD) -e 0 $< -o $@
89
90 exploit.o: exploit.s
91         @echo "  ASSEMBLE  $@"
92         $(Q)$(CC) $(CFLAGS) -c $< -o $@
93
94 head.o: head.s head.b exploit2.s exploit.bin
95         @echo "  ASSEMBLE  $@"
96         $(Q)$(CC) $(CFLAGS) \
97                 -Wa,--defsym,exploitlen=$(shell wc -c exploit.bin | awk '{ print $$1 }') \
98                 -c $< -o $@
99
100 title.bin: ../.version
101         @echo "  TITLEBIN  $@"
102         $(Q)perl make-title-bin.pl > $@
103
104 ../.version: FORCE
105         $(Q)$(MAKE) -C .. .version
106
107 $(ppms): %.ppm: %.png
108         @echo "  PPM       $@"
109         $(Q)convert $< $@
110
111 zero16k:
112         $(Q)dd if=/dev/zero bs=18256 count=1 2>/dev/null > $@
113 #17332
114 #16384
115 FAILURE:
116         $(Q)echo FAILURE > $@
117
118 $(loader): FORCE
119         $(Q)$(MAKE) -C ../loader
120
121 FORCE:
122
123 clean:
124         -rm -f $(targets) FILE_V28
125         -rm -f exploit.bin exploit.elf exploit.o
126         -rm -f head.bin head.elf head.o
127         -rm -f title.bin