NanoPayload

Annotated Makefile

6:d94bf387cc11
2015-06-05 Paul Boddie Added support for multiple stages.
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@6 35
LDFLAGS = -nostdlib -EL
paul@0 36
paul@6 37
PAYLOAD = stage1.bin stage2.bin
paul@0 38
TARGET = $(PAYLOAD:.bin=.elf)
paul@0 39
DUMP = $(PAYLOAD:.bin=.dump)
paul@0 40
MAP = $(PAYLOAD:.bin=.map)
paul@6 41
paul@6 42
SRC1 = head1.S stage1.c board-nanonote.c
paul@6 43
SRC2 = head2.S stage2.c board-nanonote.c
paul@6 44
OBJ1 = $(filter %.o,$(SRC1:.c=.o) $(SRC1:.S=.o))
paul@6 45
OBJ2 = $(filter %.o,$(SRC2:.c=.o) $(SRC2:.S=.o))
paul@6 46
OBJ = $(OBJ1) $(OBJ2)
paul@0 47
paul@0 48
.PHONY:	all clean distclean
paul@0 49
paul@0 50
all:	$(PAYLOAD)
paul@0 51
paul@0 52
clean:
paul@6 53
	rm -f $(OBJ) $(TARGET) $(PAYLOAD) $(DUMP) $(MAP) #System.map
paul@0 54
paul@0 55
distclean: clean
paul@0 56
	echo "Nothing else to clean."
paul@0 57
paul@2 58
$(PAYLOAD): $(TARGET)
paul@6 59
	$(OBJCOPY) -O binary $(@:.bin=.elf) $@+
paul@6 60
	$(OBJDUMP) -D $(@:.bin=.elf) > $(@:.bin=.dump)
paul@6 61
	$(OBJDUMP) -h $(@:.bin=.elf) > $(@:.bin=.map)
paul@6 62
	#$(NM) -n $< > System.map
paul@0 63
	chmod -x $@+
paul@0 64
	mv -f $@+ $@
paul@0 65
paul@6 66
stage1.elf: $(OBJ1)
paul@6 67
	$(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ1) -o $@
paul@6 68
paul@6 69
stage2.elf: $(OBJ2)
paul@6 70
	$(LD) $(LDFLAGS) -T $(@:.elf=.ld) $(OBJ2) -o $@
paul@2 71
paul@0 72
.c.o:
paul@0 73
	$(CC) -c $(CFLAGS) $< -o $@
paul@0 74
paul@0 75
.S.o:
paul@0 76
	$(CC) -c $(CFLAGS) $< -o $@