Updated part2 to explain Makefiles on other platforms

This commit is contained in:
Adam Greenwood-Byrne 2021-02-12 20:21:45 +00:00
parent fcef8b6535
commit 9e713872dc
8 changed files with 29 additions and 23 deletions

View file

@ -1,15 +1,15 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot.o $(OFILES) kernel8.img: boot.o $(OFILES)
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf

View file

@ -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. 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) 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. 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 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_. 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 Copying our kernel image to the SD card
--------------------------------------- ---------------------------------------

View file

@ -1,15 +1,15 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot.o $(OFILES) kernel8.img: boot.o $(OFILES)
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf

View file

@ -1,15 +1,15 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot.o $(OFILES) kernel8.img: boot.o $(OFILES)
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf

View file

@ -1,15 +1,15 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot.o $(OFILES) kernel8.img: boot.o $(OFILES)
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf

View file

@ -1,15 +1,15 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 %.o: %.c
$(LLVMPATH)/clang --target=aarch64-elf $(GCCFLAGS) -c $< -o $@ $(LLVMPATH)/clang --target=aarch64-elf $(CLANGFLAGS) -c $< -o $@
kernel8.img: boot.o $(OFILES) kernel8.img: boot.o $(OFILES)
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) -T link.ld -o kernel8.elf

View file

@ -1,18 +1,18 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 BCM4345C0.o : BCM4345C0.hcd
$(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@
%.o: %.c %.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 kernel8.img: boot.o $(OFILES) BCM4345C0.o
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf

View file

@ -1,18 +1,18 @@
CFILES = $(wildcard *.c) CFILES = $(wildcard *.c)
OFILES = $(CFILES:.c=.o) OFILES = $(CFILES:.c=.o)
LLVMPATH = /opt/homebrew/opt/llvm/bin 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 all: clean kernel8.img
boot.o: boot.S 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 BCM4345C0.o : BCM4345C0.hcd
$(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@ $(LLVMPATH)/llvm-objcopy -I binary -O elf64-littleaarch64 -B aarch64 $< $@
%.o: %.c %.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 kernel8.img: boot.o $(OFILES) BCM4345C0.o
$(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf $(LLVMPATH)/ld.lld -m aarch64elf -nostdlib boot.o $(OFILES) BCM4345C0.o -T link.ld -o kernel8.elf