Makefile 6.02 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# Copyright (C) 2012       Alejandro Mery <amery@geeks.cl>
# Copyright (C) 2012,2013  Henrik Nordstrom <henrik@henriknordstrom.net>
# Copyright (C) 2013       Patrick Wood <patrickhwood@gmail.com>
# Copyright (C) 2013       Pat Wood <Pat.Wood@efi.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

19
CC ?= gcc
20
DEFAULT_CFLAGS := -g -O0 -Wall -Wextra -std=c99
Alejandro Mery's avatar
Alejandro Mery committed
21

22
DEFAULT_CFLAGS += -D_POSIX_C_SOURCE=200112L
23
24
# Define _BSD_SOURCE, necessary to expose all endian conversions properly.
# See http://linux.die.net/man/3/endian
25
DEFAULT_CFLAGS += -D_BSD_SOURCE
26
# glibc 2.20+ also requires _DEFAULT_SOURCE
27
DEFAULT_CFLAGS += -D_DEFAULT_SOURCE
28
29
ifeq (NetBSD,$(OS))
# add explicit _NETBSD_SOURCE, see https://github.com/linux-sunxi/sunxi-tools/pull/22
30
DEFAULT_CFLAGS += -D_NETBSD_SOURCE
31
endif
32

33
34
DEFAULT_CFLAGS += -Iinclude/

35
# Tools useful on host and target
Ian Campbell's avatar
Ian Campbell committed
36
37
38
39
TOOLS = sunxi-fexc sunxi-bootinfo sunxi-fel sunxi-nand-part

# Symlinks to sunxi-fexc
FEXC_LINKS = bin2fex fex2bin
Alejandro Mery's avatar
Alejandro Mery committed
40

41
# Tools which are only useful on the target
42
TARGET_TOOLS = sunxi-meminfo sunxi-pio
43

44
# Misc tools (of more "exotic" nature) not part of our default build / install
45
MISC_TOOLS = phoenix_info sunxi-nand-image-builder
46

47
48
# ARM binaries and images
# Note: To use this target, set/adjust CROSS_COMPILE and MKSUNXIBOOT if needed
49
BINFILES = fel-pio.bin jtag-loop.sunxi fel-sdboot.sunxi uart0-helloworld-sdboot.sunxi
50

51
CROSS_COMPILE ?= arm-none-eabi-
52
CROSS_CC ?= $(CROSS_COMPILE)gcc
53
MKSUNXIBOOT ?= mksunxiboot
54

Ian Campbell's avatar
Ian Campbell committed
55
56
57
58
59
DESTDIR ?=
PREFIX  ?= /usr/local
BINDIR  ?= $(PREFIX)/bin

.PHONY: all clean tools target-tools install install-tools install-target-tools
60

Ian Campbell's avatar
Ian Campbell committed
61
tools: $(TOOLS) $(FEXC_LINKS)
62
target-tools: $(TARGET_TOOLS)
Alejandro Mery's avatar
Alejandro Mery committed
63

64
65
all: tools target-tools

66
misc: $(MISC_TOOLS)
67

68
69
binfiles: $(BINFILES)

70
71
install: install-tools
install-all: install-tools install-target-tools
Ian Campbell's avatar
Ian Campbell committed
72
73
74
75
76
77
78
79
80

install-tools: $(TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done
	@set -ex ; for l in $(FEXC_LINKS) ; do \
		ln -nfs sunxi-fexc $(DESTDIR)$(BINDIR)/$$l ; \
	done
Alejandro Mery's avatar
Alejandro Mery committed
81

Ian Campbell's avatar
Ian Campbell committed
82
83
84
85
86
87
install-target-tools: $(TARGET_TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done

88
89
90
91
92
93
install-misc: $(MISC_TOOLS)
	install -d $(DESTDIR)$(BINDIR)
	@set -ex ; for t in $^ ; do \
		install -m0755 $$t $(DESTDIR)$(BINDIR)/$$t ; \
	done

Ian Campbell's avatar
Ian Campbell committed
94
95
96

clean:
	@rm -vf $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) $(MISC_TOOLS)
97
	@rm -vf version.h *.o *.elf *.sunxi *.bin *.nm *.orig
98

99
$(TOOLS) $(TARGET_TOOLS) $(MISC_TOOLS): Makefile common.h version.h
100

101
fex2bin bin2fex: sunxi-fexc
102
	ln -nsf $< $@
103

104
sunxi-fexc: fexc.h script.h script.c \
Alejandro Mery's avatar
Alejandro Mery committed
105
	script_uboot.h script_uboot.c \
106
107
	script_bin.h script_bin.c \
	script_fex.h script_fex.c
Alejandro Mery's avatar
Alejandro Mery committed
108

109
LIBUSB = libusb-1.0
110
111
LIBUSB_CFLAGS ?= `pkg-config --cflags $(LIBUSB)`
LIBUSB_LIBS ?= `pkg-config --libs $(LIBUSB)`
112
113
ifeq ($(OS),Windows_NT)
	# Windows lacks mman.h / mmap()
114
	DEFAULT_CFLAGS += -DNO_MMAP
115
116
	# portable_endian.h relies on winsock2
	LIBS += -lws2_32
117
endif
118

119
120
HOST_CFLAGS = $(DEFAULT_CFLAGS) $(CFLAGS)

121
sunxi-fel: fel.c fel-to-spl-thunk.h progress.c progress.h
122
	$(CC) $(HOST_CFLAGS) $(LIBUSB_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS) $(LIBUSB_LIBS)
123

124
sunxi-nand-part: nand-part-main.c nand-part.c nand-part-a10.h nand-part-a20.h
125
126
127
	$(CC) $(HOST_CFLAGS) -c -o nand-part-main.o nand-part-main.c
	$(CC) $(HOST_CFLAGS) -c -o nand-part-a10.o nand-part.c -D A10
	$(CC) $(HOST_CFLAGS) -c -o nand-part-a20.o nand-part.c -D A20
128
129
	$(CC) $(LDFLAGS) -o $@ nand-part-main.o nand-part-a10.o nand-part-a20.o $(LIBS)

130
sunxi-%: %.c
131
	$(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $(filter %.c,$^) $(LIBS)
132
phoenix_info: phoenix_info.c
133
	$(CC) $(HOST_CFLAGS) $(LDFLAGS) -o $@ $< $(LIBS)
134

135
136
137
138
139
140
%.bin: %.elf
	$(CROSS_COMPILE)objcopy -O binary $< $@

%.sunxi: %.bin
	$(MKSUNXIBOOT) $< $@

141
fel-pio.bin: fel-pio.elf fel-pio.nm
142

143
ARM_ELF_FLAGS = -Os -marm -fpic -Wall
144
ARM_ELF_FLAGS += -fno-common -fno-builtin -ffreestanding -nostdinc -fno-strict-aliasing
145
146
ARM_ELF_FLAGS += -mno-thumb-interwork -fno-stack-protector -fno-toplevel-reorder
ARM_ELF_FLAGS += -Wstrict-prototypes -Wno-format-nonliteral -Wno-format-security
147

148
fel-pio.elf: fel-pio.c fel-pio.lds
149
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T fel-pio.lds
150
151

fel-pio.nm: fel-pio.elf
152
	$(CROSS_COMPILE)nm $< | grep -v " _" >$@
153
154

jtag-loop.elf: jtag-loop.c jtag-loop.lds
155
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T jtag-loop.lds -Wl,-N
156

157
fel-sdboot.elf: fel-sdboot.S fel-sdboot.lds
158
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T fel-sdboot.lds -Wl,-N
159

160
uart0-helloworld-sdboot.elf: uart0-helloworld-sdboot.c uart0-helloworld-sdboot.lds
161
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T uart0-helloworld-sdboot.lds -Wl,-N
162

163
boot_head_sun3i.elf: boot_head.S boot_head.lds
164
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1094
165
166

boot_head_sun4i.elf: boot_head.S boot_head.lds
167
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x1008
168
169

boot_head_sun5i.elf: boot_head.S boot_head.lds
170
	$(CROSS_CC) -g $(ARM_ELF_FLAGS) $< -nostdlib -o $@ -T boot_head.lds -Wl,-N -DMACHID=0x102A
171

172
sunxi-bootinfo: bootinfo.c
173

174
# target tools
175
TARGET_CFLAGS = $(DEFAULT_CFLAGS) -static $(CFLAGS)
176
sunxi-pio: pio.c
177
	$(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
178
sunxi-meminfo: meminfo.c
179
	$(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
180
sunxi-script_extractor: script_extractor.c
181
	$(CROSS_CC) $(TARGET_CFLAGS) -o $@ $<
182

183
184
185
version.h:
	@./autoversion.sh > $@

Alejandro Mery's avatar
Alejandro Mery committed
186
.gitignore: Makefile
187
	@for x in $(TOOLS) $(FEXC_LINKS) $(TARGET_TOOLS) version.h '*.o' '*.swp'; do \
Alejandro Mery's avatar
Alejandro Mery committed
188
		echo "$$x"; \
189
	done | sort -V > $@