63 lines
1.7 KiB
Makefile
63 lines
1.7 KiB
Makefile
U=user
|
|
P=programs
|
|
|
|
# riscv64-unknown-elf- or riscv64-linux-gnu-
|
|
# perhaps in /opt/riscv/bin
|
|
#TOOLPREFIX =
|
|
|
|
# Try to infer the correct TOOLPREFIX if not set
|
|
ifndef TOOLPREFIX
|
|
TOOLPREFIX := $(shell if riscv64-unknown-elf-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
|
|
then echo 'riscv64-unknown-elf-'; \
|
|
elif riscv64-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
|
|
then echo 'riscv64-linux-gnu-'; \
|
|
elif riscv64-unknown-linux-gnu-objdump -i 2>&1 | grep 'elf64-big' >/dev/null 2>&1; \
|
|
then echo 'riscv64-unknown-linux-gnu-'; \
|
|
else echo "***" 1>&2; \
|
|
echo "*** Error: Couldn't find a riscv64 version of GCC/binutils." 1>&2; \
|
|
echo "*** To turn off this error, run 'gmake TOOLPREFIX= ...'." 1>&2; \
|
|
echo "***" 1>&2; exit 1; fi)
|
|
endif
|
|
|
|
CC = $(TOOLPREFIX)gcc
|
|
AS = $(TOOLPREFIX)gas
|
|
LD = $(TOOLPREFIX)ld
|
|
OBJCOPY = $(TOOLPREFIX)objcopy
|
|
OBJDUMP = $(TOOLPREFIX)objdump
|
|
|
|
CFLAGS = -Wall -Werror -O -fno-omit-frame-pointer -ggdb -gdwarf-2
|
|
CFLAGS += -MD
|
|
CFLAGS += -mcmodel=medany
|
|
CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
|
|
CFLAGS += -I.
|
|
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
|
|
|
# Disable PIE when possible (for Ubuntu 16.10 toolchain)
|
|
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
|
|
CFLAGS += -fno-pie -no-pie
|
|
endif
|
|
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]nopie'),)
|
|
CFLAGS += -fno-pie -nopie
|
|
endif
|
|
|
|
LDFLAGS = -z max-page-size=4096
|
|
|
|
.PHONY: build clean
|
|
|
|
ULIB = ulib.o usys.o printf.o umalloc.o
|
|
|
|
build: $(ULIB)
|
|
|
|
%.o: %.c *.h
|
|
$(CC) $(CFLAGS) -c $<
|
|
|
|
usys.S : usys.pl
|
|
perl usys.pl > usys.S
|
|
|
|
usys.o : usys.S
|
|
$(CC) $(CFLAGS) -c -o usys.o usys.S
|
|
|
|
clean:
|
|
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
|
|
*.o *.a *.d *.asm *.sym usys.S
|