make hello_world relocatable with BOOT_INIT_BASE define
[ls2.git] / hello_world / Makefile
1 ARCH = $(shell uname -m)
2 ifneq ("$(ARCH)", "ppc64")
3 ifneq ("$(ARCH)", "ppc64le")
4 CROSS_COMPILE ?= powerpc64le-linux-gnu-
5 endif
6 endif
7
8 BOOT_INIT_BASE ?= 0xf0000000 # at QSPI address
9 # BOOT_INIT_BASE ?= 0xff000000 # at ROM hi address (with coldboot firmware)
10 # BOOT_INIT_BASE ?= 0x0 # start at zero (usual)
11
12 CC = $(CROSS_COMPILE)gcc
13 LD = $(CROSS_COMPILE)ld
14 OBJCOPY = $(CROSS_COMPILE)objcopy
15
16 CFLAGS = -Os -g -Wall -std=c99 -mabi=elfv2 -msoft-float -mno-string \
17 -mno-multiple -mno-vsx -mno-altivec -mlittle-endian \
18 -fno-stack-protector -mstrict-align -ffreestanding \
19 -fdata-sections -ffunction-sections -I../include \
20 -DBOOT_INIT_BASE=$(BOOT_INIT_BASE)
21
22 ASFLAGS = $(CFLAGS)
23 LDFLAGS = -static -nostdlib -T powerpc.lds --gc-sections
24
25 all: hello_world.hex
26
27 powerpc.lds: powerpc.lds.S
28 $(CC) $(CFLAGS) -P -E powerpc.lds.S -o powerpc.lds
29
30 console.o: ../lib/console.c
31 $(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
32
33 hello_world.elf: hello_world.o head.o console.o powerpc.lds
34 $(LD) $(LDFLAGS) -o $@ hello_world.o head.o console.o
35
36 hello_world.bin: hello_world.elf
37 $(OBJCOPY) -O binary $^ $@
38
39 hello_world.hex: hello_world.bin
40 ../scripts/bin2hex.py $^ > $@
41
42 clean:
43 @rm -f *.o hello_world.elf hello_world.bin hello_world.hex
44 distclean: clean
45 rm -f *~
46