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