From 9e713872dcfddcd3f51fdcb44d93c366fa9fbd85 Mon Sep 17 00:00:00 2001 From: Adam Greenwood-Byrne Date: Fri, 12 Feb 2021 20:21:45 +0000 Subject: [PATCH] Updated part2 to explain Makefiles on other platforms --- part2-building/Makefile | 6 +++--- part2-building/README.md | 10 ++++++++-- part3-helloworld/Makefile | 6 +++--- part4-miniuart/Makefile | 6 +++--- part5-framebuffer/Makefile | 6 +++--- part6-breakout/Makefile | 6 +++--- part7-bluetooth/Makefile | 6 +++--- part8-breakout-ble/Makefile | 6 +++--- 8 files changed, 29 insertions(+), 23 deletions(-) diff --git a/part2-building/Makefile b/part2-building/Makefile index 12441a6..371b8b1 100644 --- a/part2-building/Makefile +++ b/part2-building/Makefile @@ -1,15 +1,15 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part2-building/README.md b/part2-building/README.md index 4405d5a..0f0db9e 100644 --- a/part2-building/README.md +++ b/part2-building/README.md @@ -6,7 +6,7 @@ Making a makefile I could now just tell you the commands required to build this very simple kernel one after the other, but let's try to future-proof a little. I anticipate that our kernel will become more complex, with multiple C files needing to be built. It therefore makes sense to craft a **makefile**. A makefile is written in (yet another) language that automates the build process for us. -Save the following as _Makefile_: +If you're using Arm gcc on Linux, save the following as _Makefile_ (in the repo as _Makefile.gcc_): ``` CFILES = $(wildcard *.c) @@ -43,12 +43,18 @@ Carrying on, to build _kernel8.img_ we must first have built _boot.o_ and also e I would now hope that the "clean" and "all" targets are self-explanatory. +Makefiles on other platforms +---------------------------- + +If you're using clang on Mac OS X, the file already named _Makefile_ in the repo will be the one you need. Ensure the LLVMPATH is correctly set, of course. It doesn't look much different to the Arm gcc one, so the above explanation mostly applies. + +Similarly, if you're using Arm gcc natively on Windows, [part8-breakout-ble](../part8-breakout-ble) has a _Makefile.gcc.windows_ just as an example. + Building -------- Now that we have our _Makefile_ in place, we simply type `make` to build our kernel image. Since "all" is the first target listed in our _Makefile_, `make` will build this unless you tell it otherwise. When building "all", it will first clean up any old builds and then make us a fresh build of _kernel8.img_. - Copying our kernel image to the SD card --------------------------------------- diff --git a/part3-helloworld/Makefile b/part3-helloworld/Makefile index 12441a6..371b8b1 100644 --- a/part3-helloworld/Makefile +++ b/part3-helloworld/Makefile @@ -1,15 +1,15 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part4-miniuart/Makefile b/part4-miniuart/Makefile index 12441a6..371b8b1 100644 --- a/part4-miniuart/Makefile +++ b/part4-miniuart/Makefile @@ -1,15 +1,15 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part5-framebuffer/Makefile b/part5-framebuffer/Makefile index 12441a6..371b8b1 100644 --- a/part5-framebuffer/Makefile +++ b/part5-framebuffer/Makefile @@ -1,15 +1,15 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part6-breakout/Makefile b/part6-breakout/Makefile index 12441a6..371b8b1 100644 --- a/part6-breakout/Makefile +++ b/part6-breakout/Makefile @@ -1,15 +1,15 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf diff --git a/part7-bluetooth/Makefile b/part7-bluetooth/Makefile index d0d1f1d..3189646 100644 --- a/part7-bluetooth/Makefile +++ b/part7-bluetooth/Makefile @@ -1,18 +1,18 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o BCM4345C0.o : BCM4345C0.hcd $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) BCM4345C0.o $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf diff --git a/part8-breakout-ble/Makefile b/part8-breakout-ble/Makefile index d0d1f1d..3189646 100644 --- a/part8-breakout-ble/Makefile +++ b/part8-breakout-ble/Makefile @@ -1,18 +1,18 @@ CFILES = $(wildcard *.c) OFILES = $(CFILES:.c=.o) LLVMPATH = /opt/homebrew/opt/llvm/bin -GCCFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd +CLANGFLAGS = -Wall -O2 -ffreestanding -nostdinc -nostdlib -mcpu=cortex-a72+nosimd all: clean kernel8.img boot.o: boot.S - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c boot.S -o boot.o + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c boot.S -o boot.o BCM4345C0.o : BCM4345C0.hcd $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ %.o: %.c - $(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ + $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@ kernel8.img: boot.o $(OFILES) BCM4345C0.o $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf