165 lines
4.9 KiB
Makefile
165 lines
4.9 KiB
Makefile
RM= rm
|
|
CC= $(CONFIG_TARGET_CC)
|
|
AS= $(CONFIG_TARGET_CC)
|
|
# NOTE(dinosaure): we must use [aarch64-none-elf-gcc] to compile assembly code
|
|
# to be able to include some files and define some macros.
|
|
LD= $(CONFIG_TARGET_LD)
|
|
AR= aarch64-linux-gnu-ar # TODO
|
|
OBJDUMP= aarch64-linux-gnu-objdump # TODO
|
|
OBJCOPY= $(CONFIG_TARGET_OBJCOPY)
|
|
|
|
export TOPDIR := $(abspath .)
|
|
|
|
$(TOPDIR)/Makeconf:
|
|
$(error Makeconf not found, please run ./configure.sh)
|
|
|
|
include $(TOPDIR)/Makeconf
|
|
|
|
include/$(CONFIG_TARGET_TRIPLE):
|
|
@echo "GEN $@"
|
|
@./gen-headers.sh $@
|
|
|
|
CPU ?= -mcpu=cortex-a76 -mlittle-endian
|
|
ARCH += -DAARCH=64 $(CPU)
|
|
TARGET ?= kernel_2712
|
|
|
|
DEFINE += -DSSP_GUARD_SYMBOL=__stack_chk_guard \
|
|
-DSSP_FAIL_SYMBOL=__stack_chk_fail
|
|
|
|
INCLUDE += -I $(TOPDIR)/include -I $(TOPDIR)/include/$(CONFIG_TARGET_TRIPLE) \
|
|
-I $(TOPDIR)/nolibc/include
|
|
|
|
AFLAGS += $(ARCH) $(DEFINE) $(INCLUDE)
|
|
|
|
CFLAGS += -std=c11 -ffreestanding -fstack-protector-strong -nostdlib \
|
|
-nostartfiles -mstrict-align -Wall \
|
|
$(ARCH) $(DEFINE) $(INCLUDE) $(CONFIG_TARGET_CC_CFLAGS)
|
|
|
|
LDFLAGS += -nostdlib -static -Wl,--no-warn-rwx-segments \
|
|
-Wl,--section-start=.init=0x80000 -Wl,--build-id=none \
|
|
-Wl,--start-group -L lib/$(CONFIG_TARGET_TRIPLE) -lgilbraltar.rpi5 -L nolibc -lnolibc -L openlibm -lopenlibm -lgcc -Wl,--end-group
|
|
|
|
SRCS= kernel.c timer.c led.c interrupt_handler.c exception_handler.c \
|
|
mbox.c clock.c crt.c serial.c log.c power.c tag.c coherent_page.c dtb.c \
|
|
synchronize.c spinlock.c memory.c pager.c translation_table.c
|
|
|
|
ASMS= startup.S exception_stub.S
|
|
|
|
SRCS:=$(addprefix kernel/,$(SRCS))
|
|
ASMS:=$(addprefix kernel/,$(ASMS))
|
|
|
|
OBJS= $(SRCS:c=o) $(ASMS:S=o)
|
|
|
|
bin:
|
|
@test ! -d $@
|
|
@mkdir -p $@
|
|
|
|
bin/$(CONFIG_TARGET_TRIPLE)-%: toolchain/%.in | bin
|
|
@echo "SUBST $@"
|
|
@sed -e 's!@@CONFIG_TARGET_ARCH@@!$(CONFIG_TARGET_ARCH)!g' \
|
|
-e 's!@@CONFIG_TARGET_TRIPLE@@!$(CONFIG_TARGET_TRIPLE)!g' \
|
|
-e 's!@@CONFIG_TARGET_CC@@!$(CONFIG_TARGET_CC)!g' \
|
|
-e 's!@@CONFIG_TARGET_CC_CFLAGS@@!$(CONFIG_TARGET_CC_CFLAGS)!g' \
|
|
-e 's!@@CONFIG_TARGET_CC_LDFLAGS@@!$(CONFIG_TARGET_CC_LDFLAGS)!g' \
|
|
-e 's!@@CONFIG_TARGET_LD@@!$(CONFIG_TARGET_LD)!g' \
|
|
-e 's!@@CONFIG_TARGET_LD_LDFLAGS@@!$(CONFIG_TARGET_LD_LDFLAGS)!g' \
|
|
-e 's!@@CONFIG_TARGET_OBJCOPY@@!$(CONFIG_TARGET_OBJCOPY)!g' \
|
|
$< >$@
|
|
@chmod +x $@
|
|
|
|
%.o: %.S
|
|
@echo "AS $@"
|
|
@$(AS) $(AFLAGS) -c -o $@ $<
|
|
|
|
%.o: %.c include/$(CONFIG_TARGET_TRIPLE)
|
|
@echo "CC $@"
|
|
@$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
lib/$(CONFIG_TARGET_TRIPLE):
|
|
@test ! -d $@
|
|
@mkdir -p $@
|
|
|
|
lib/$(CONFIG_TARGET_TRIPLE)/libgilbraltar.rpi5.a: $(OBJS) | lib/$(CONFIG_TARGET_TRIPLE)
|
|
@echo "AR $@"
|
|
@rm -f $@
|
|
@$(AR) cr $@ $^
|
|
|
|
lib/$(CONFIG_TARGET_TRIPLE)/libgilbraltar.stub.a: | lib/$(CONFIG_TARGET_TRIPLE)
|
|
@$(AR) cr $@
|
|
|
|
.PHONY: phony-openlibm
|
|
phony-openlibm: include/$(CONFIG_TARGET_TRIPLE)
|
|
@$(MAKE) -C openlibm \
|
|
"CC=$(CC)" "CPPFLAGS=$(CFLAGS)" libopenlibm.a
|
|
|
|
openlibm/libopenlibm.a: phony-openlibm
|
|
|
|
ocaml:
|
|
test ! -d $@
|
|
cp -r "$$(ocamlfind query ocaml-src)" $@
|
|
VERSION="$$(head -n1 ocaml/VERSION)" ; \
|
|
if test -d "patches/$$VERSION" ; then \
|
|
git apply --directory=$@ "patches/$$VERSION"/*; \
|
|
fi
|
|
|
|
ocaml/Makefile.config: | ocaml
|
|
PATH="$$PWD/bin/:$$PATH" ; \
|
|
cd ocaml && \
|
|
./configure \
|
|
--host="$(CONFIG_HOST_ARCH)-unknown-none" \
|
|
--target="$(CONFIG_TARGET_TRIPLE)" \
|
|
--prefix="$(CONFIG_SYSROOT)" \
|
|
--disable-shared \
|
|
--disable-systhreads \
|
|
--disable-unix-lib \
|
|
--disable-instrumented-runtime \
|
|
--disable-debug-runtime \
|
|
--disable-ocamltest \
|
|
--disable-ocamldoc \
|
|
--without-zstd \
|
|
$(MAKECONF_OCAML_CONFIGURE_OPTIONS)
|
|
|
|
OCAML_IS_BUILT := _build/ocaml_is_built
|
|
$(OCAML_IS_BUILT): ocaml/Makefile.config | _build
|
|
PATH="$$PWD/$(TOOLDIR_FOR_BUILD):$$PATH" $(MAKE) -C ocaml cross.opt
|
|
cd ocaml && ocamlrun tools/stripdebug ocamlc ocamlc.tmp
|
|
cd ocaml && ocamlrun tools/stripdebug ocalmopt ocamlopt.tmp
|
|
touch $@
|
|
|
|
NOLIBC_CFLAGS= $(CFLAGS) -I $(TOPDIR)/nolibc/include -I $(TOPDIR)/openlibm/src -I $(TOPDIR)/openlibm/include
|
|
|
|
.PHONY: phony-nolibc
|
|
phony-nolibc: include/$(CONFIG_TARGET_TRIPLE)
|
|
$(MAKE) -C nolibc libnolibc.a \
|
|
"CC=$(CC)" "FREESTANDING_CFLAGS=$(NOLIBC_CFLAGS)"
|
|
|
|
nolibc/libnolibc.a: phony-nolibc
|
|
|
|
.PHONY: all
|
|
all: kernel/libgilbraltar.rpi5.a
|
|
|
|
.PHONY: clean
|
|
clean:
|
|
$(RM) -f kernel/*.o kernel/*.a *.elf *.bin *.img *.map
|
|
$(RM) -rf include/$(CONFIG_TARGET_TRIPLE)/
|
|
$(RM) -rf _build
|
|
$(RM) -rf bin/
|
|
$(RM) -rf lib/$(CONFIG_TARGET_TRIPLE)/
|
|
if [ -d ocaml ] ; then $(MAKE) -C ocaml clean ; fi
|
|
$(RM) -f test/*.o
|
|
$(MAKE) -C openlibm clean
|
|
$(MAKE) -C nolibc clean FREESTANDING_CFLAGS=_
|
|
|
|
.PHONY: distclean
|
|
distclean: clean
|
|
$(RM) -f Makeconf Makeconf.sh
|
|
if [ -d ocaml ] ; then $(MAKE) -C ocaml distclean ; fi
|
|
|
|
test/%.o: test/%.c
|
|
@echo "CC $@"
|
|
@$(CC) $(CFLAGS) -c -o $@ $<
|
|
|
|
kernel_2712.img: lib/$(CONFIG_TARGET_TRIPLE)/libgilbraltar.rpi5.a nolibc/libnolibc.a openlibm/libopenlibm.a test/test.o
|
|
@echo "LD ${@:img=elf}"
|
|
@$(LD) test/test.o -o ${@:img=elf} $(LDFLAGS) -Wl,-Map ${@:img=map} -Wl,-T gilbraltar.rpi5.ld
|
|
@$(OBJCOPY) ${@:img=elf} -O binary $@
|