paul@18 | 1 | # Makefile - Build the NanoNote payload |
paul@18 | 2 | # |
paul@18 | 3 | # Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk> |
paul@18 | 4 | # Copyright (C) Xiangfu Liu <xiangfu@sharism.cc> |
paul@18 | 5 | # |
paul@18 | 6 | # This program is free software; you can redistribute it and/or modify it under |
paul@18 | 7 | # the terms of the GNU General Public License as published by the Free Software |
paul@18 | 8 | # Foundation; either version 3 of the License, or (at your option) any later |
paul@18 | 9 | # version. |
paul@18 | 10 | # |
paul@18 | 11 | # This program is distributed in the hope that it will be useful, but WITHOUT |
paul@18 | 12 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@18 | 13 | # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@18 | 14 | # details. |
paul@18 | 15 | # |
paul@18 | 16 | # You should have received a copy of the GNU General Public License along with |
paul@18 | 17 | # this program. If not, see <http://www.gnu.org/licenses/>. |
paul@18 | 18 | |
paul@18 | 19 | ARCH = mipsel-linux-gnu |
paul@18 | 20 | CC = $(ARCH)-gcc |
paul@18 | 21 | LD = $(ARCH)-ld |
paul@18 | 22 | NM = $(ARCH)-nm |
paul@18 | 23 | OBJCOPY=$(ARCH)-objcopy |
paul@18 | 24 | OBJDUMP=$(ARCH)-objdump |
paul@18 | 25 | |
paul@18 | 26 | # NOTE: -O2 is actually needed to prevent memcpy references, whereas probably |
paul@18 | 27 | # NOTE: one of the -f{freestanding, no-hosted, no-builtin} options should work. |
paul@18 | 28 | # NOTE: See: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 |
paul@18 | 29 | |
paul@18 | 30 | ASM_INC = /usr/src/linux-headers-4.0.0-1-common/arch/mips/include |
paul@18 | 31 | CFLAGS = -O2 -Wall \ |
paul@18 | 32 | -fno-unit-at-a-time -fno-zero-initialized-in-bss \ |
paul@18 | 33 | -ffreestanding -fno-hosted -fno-builtin \ |
paul@18 | 34 | -march=mips32 -fPIC \ |
paul@18 | 35 | -I../include -I$(ASM_INC) -I$(ASM_INC)/asm/mach-generic |
paul@18 | 36 | LDFLAGS = -nostdlib -EL -pie |
paul@18 | 37 | |
paul@18 | 38 | PAYLOAD = stage2.bin |
paul@18 | 39 | TARGET = $(PAYLOAD:.bin=.elf) |
paul@18 | 40 | DUMP = $(PAYLOAD:.bin=.dump) |
paul@18 | 41 | MAP = $(PAYLOAD:.bin=.map) |
paul@18 | 42 | |
paul@18 | 43 | # Ordering of objects is important and cannot be left to replacement rules. |
paul@18 | 44 | |
paul@18 | 45 | SRC = head2.S stage2.c board-nanonote.c nanonote_gpm940b0.c lcd.c |
paul@18 | 46 | OBJ = head2.o stage2.o board-nanonote.o nanonote_gpm940b0.o lcd.o |
paul@18 | 47 | |
paul@18 | 48 | .PHONY: all clean distclean |
paul@18 | 49 | |
paul@18 | 50 | all: $(PAYLOAD) |
paul@18 | 51 | |
paul@18 | 52 | clean: |
paul@18 | 53 | rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) *.map |
paul@18 | 54 | |
paul@18 | 55 | distclean: clean |
paul@18 | 56 | echo "Nothing else to clean." |
paul@18 | 57 | |
paul@18 | 58 | $(PAYLOAD): $(TARGET) |
paul@18 | 59 | $(OBJCOPY) -O binary $(@:.bin=.elf) $@+ |
paul@18 | 60 | $(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump) |
paul@18 | 61 | $(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map) |
paul@18 | 62 | $(NM) -n $(@:.bin=.elf) > System.map |
paul@18 | 63 | chmod -x $@+ |
paul@18 | 64 | mv -f $@+ $@ |
paul@18 | 65 | |
paul@18 | 66 | stage2.elf: $(OBJ) |
paul@18 | 67 | $(LD) $(LDFLAGS) -pie -T $(@:.elf=.ld) $(OBJ) -o $@ |
paul@18 | 68 | |
paul@18 | 69 | .c.o: |
paul@18 | 70 | $(CC) -c $(CFLAGS) $< -o $@ |
paul@18 | 71 | |
paul@18 | 72 | .S.o: |
paul@18 | 73 | $(CC) -c $(CFLAGS) $< -o $@ |