From 1605c7f5737ee4544bb6f8419ed1cc13faa1f72b Mon Sep 17 00:00:00 2001 From: Christian Cunningham Date: Sat, 4 Dec 2021 19:42:25 -0700 Subject: Consolidated Common Make --- Common.mk | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Unix.mk | 75 +-------------------------------------------------------------- Win.mk | 75 +-------------------------------------------------------------- 3 files changed, 77 insertions(+), 148 deletions(-) create mode 100644 Common.mk diff --git a/Common.mk b/Common.mk new file mode 100644 index 0000000..edff8ac --- /dev/null +++ b/Common.mk @@ -0,0 +1,75 @@ +C_SOURCES = $(wildcard src/*.c src/**/*.c) +C_HEADERS = $(wildcard src/*.h src/**/*.h) +C_OBJECTS = ${C_SOURCES:.c=.co} +C_OBJECTD = ${subst src,obj,${C_OBJECTS}} +A_SOURCES = $(wildcard src/*.S src/**/*.S) +A_OBJECTS = ${A_SOURCES:.S=.ao} +A_OBJECTD = ${subst src,obj,${A_OBJECTS}} + +CROSS = arm-none-eabi +CC = ${CROSS}-gcc +AS = ${CROSS}-as +OBJCOPY = ${CROSS}-objcopy +OBJDUMP = ${CROSS}-objdump +QEMU = /mnt/c/qemu/qemu-system-arm.exe +GDB = gdb-multiarch +CFLAGS = -mcpu=cortex-a7 -fpic -ffreestanding -std=gnu99 -O3 -Wall -Wextra -nostdlib -g +AFLAGS = -mcpu=cortex-a7 -g +QFLAGS = -M raspi2 -cpu arm1176 -m 1G -serial mon:stdio -nographic + +BSP ?= 2 + +ifeq ($(BSP),2) + BSP23 = 1 + CFLAGS += -DBSP23 +endif + +CFLAGS += -DVERSION="\"0.0c\"" + +.PHONY: clean run run-debug debug export tree + +default: clean build/kernel7.img + +build/kernel7.img: build/kernel.elf + @mkdir -p $(@D) + ${OBJCOPY} $< -O binary $@ + +build/kernel.list: build/kernel-g.elf + @mkdir -p $(@D) + ${OBJDUMP} -D $< > $@ + +build/kernel-g.elf: ${A_OBJECTD} ${C_OBJECTD} + @mkdir -p $(@D) + ${CC} -T linker.ld -o $@ ${CFLAGS} $^ -lgcc + +build/kernel.elf: ${A_OBJECTD} ${C_OBJECTD} + @mkdir -p $(@D) + ${CC} -T linker.ld -o $@ -ffreestanding -O3 -nostdlib $^ -lgcc + +export: build/kernel.list + cp build/kernel-g.elf /mnt/c/Local/ + +obj/%.co: src/%.c + @mkdir -p $(@D) + ${CC} ${CFLAGS} -c $< -o $@ + +obj/%.ao: src/%.S + @mkdir -p $(@D) + ${AS} ${AFLAGS} -c $< -o $@ + +run: build/kernel.elf + @echo Starting QEMU + @${QEMU} -kernel $< ${QFLAGS} + +run-debug: build/kernel-g.elf + @echo Starting QEMU in Debug Mode + @${QEMU} -kernel $< -s -S ${QFLAGS} + +debug: build/kernel-g.elf build/kernel.list + ${GDB} $< -command=gdbinit + +clean: + rm -rf obj/* build/* + +tree: + @tree -a -I obj\|build\|.git\|.gitignore diff --git a/Unix.mk b/Unix.mk index ee1e2c7..b6c5ad1 100644 --- a/Unix.mk +++ b/Unix.mk @@ -1,75 +1,2 @@ -C_SOURCES = $(wildcard src/*.c src/**/*.c) -C_HEADERS = $(wildcard src/*.h src/**/*.h) -C_OBJECTS = ${C_SOURCES:.c=.co} -C_OBJECTD = ${subst src,obj,${C_OBJECTS}} -A_SOURCES = $(wildcard src/*.S src/**/*.S) -A_OBJECTS = ${A_SOURCES:.S=.ao} -A_OBJECTD = ${subst src,obj,${A_OBJECTS}} - -CROSS = arm-none-eabi -CC = ${CROSS}-gcc -AS = ${CROSS}-as -OBJCOPY = ${CROSS}-objcopy -OBJDUMP = ${CROSS}-objdump QEMU = qemu-system-arm -GDB = gdb-multiarch -CFLAGS = -mcpu=cortex-a7 -fpic -ffreestanding -std=gnu99 -O3 -Wall -Wextra -nostdlib -g -AFLAGS = -mcpu=cortex-a7 -g -QFLAGS = -M raspi2 -cpu arm1176 -m 1G -serial mon:stdio -nographic - -BSP ?= 2 - -ifeq ($(BSP),2) - BSP23 = 1 - CFLAGS += -DBSP23 -endif - -CFLAGS += -DVERSION="\"0.0c\"" - -.PHONY: clean run run-debug debug export tree - -default: clean build/kernel7.img - -build/kernel7.img: build/kernel.elf - @mkdir -p $(@D) - ${OBJCOPY} $< -O binary $@ - -build/kernel.list: build/kernel-g.elf - @mkdir -p $(@D) - ${OBJDUMP} -D $< > $@ - -build/kernel-g.elf: ${A_OBJECTD} ${C_OBJECTD} - @mkdir -p $(@D) - ${CC} -T linker.ld -o $@ ${CFLAGS} $^ -lgcc - -build/kernel.elf: ${A_OBJECTD} ${C_OBJECTD} - @mkdir -p $(@D) - ${CC} -T linker.ld -o $@ -ffreestanding -O3 -nostdlib $^ -lgcc - -export: build/kernel.list - cp build/kernel-g.elf /mnt/c/Local/ - -obj/%.co: src/%.c - @mkdir -p $(@D) - ${CC} ${CFLAGS} -c $< -o $@ - -obj/%.ao: src/%.S - @mkdir -p $(@D) - ${AS} ${AFLAGS} -c $< -o $@ - -run: build/kernel.elf - @echo Starting QEMU - @${QEMU} -kernel $< ${QFLAGS} - -run-debug: build/kernel-g.elf - @echo Starting QEMU in Debug Mode - @${QEMU} -kernel $< -s -S ${QFLAGS} - -debug: build/kernel-g.elf build/kernel.list - ${GDB} $< -command=gdbinit - -clean: - rm -rf obj/* build/* - -tree: - @tree -a -I obj\|build\|.git\|.gitignore +include Common.mk diff --git a/Win.mk b/Win.mk index edff8ac..8ad16f4 100644 --- a/Win.mk +++ b/Win.mk @@ -1,75 +1,2 @@ -C_SOURCES = $(wildcard src/*.c src/**/*.c) -C_HEADERS = $(wildcard src/*.h src/**/*.h) -C_OBJECTS = ${C_SOURCES:.c=.co} -C_OBJECTD = ${subst src,obj,${C_OBJECTS}} -A_SOURCES = $(wildcard src/*.S src/**/*.S) -A_OBJECTS = ${A_SOURCES:.S=.ao} -A_OBJECTD = ${subst src,obj,${A_OBJECTS}} - -CROSS = arm-none-eabi -CC = ${CROSS}-gcc -AS = ${CROSS}-as -OBJCOPY = ${CROSS}-objcopy -OBJDUMP = ${CROSS}-objdump QEMU = /mnt/c/qemu/qemu-system-arm.exe -GDB = gdb-multiarch -CFLAGS = -mcpu=cortex-a7 -fpic -ffreestanding -std=gnu99 -O3 -Wall -Wextra -nostdlib -g -AFLAGS = -mcpu=cortex-a7 -g -QFLAGS = -M raspi2 -cpu arm1176 -m 1G -serial mon:stdio -nographic - -BSP ?= 2 - -ifeq ($(BSP),2) - BSP23 = 1 - CFLAGS += -DBSP23 -endif - -CFLAGS += -DVERSION="\"0.0c\"" - -.PHONY: clean run run-debug debug export tree - -default: clean build/kernel7.img - -build/kernel7.img: build/kernel.elf - @mkdir -p $(@D) - ${OBJCOPY} $< -O binary $@ - -build/kernel.list: build/kernel-g.elf - @mkdir -p $(@D) - ${OBJDUMP} -D $< > $@ - -build/kernel-g.elf: ${A_OBJECTD} ${C_OBJECTD} - @mkdir -p $(@D) - ${CC} -T linker.ld -o $@ ${CFLAGS} $^ -lgcc - -build/kernel.elf: ${A_OBJECTD} ${C_OBJECTD} - @mkdir -p $(@D) - ${CC} -T linker.ld -o $@ -ffreestanding -O3 -nostdlib $^ -lgcc - -export: build/kernel.list - cp build/kernel-g.elf /mnt/c/Local/ - -obj/%.co: src/%.c - @mkdir -p $(@D) - ${CC} ${CFLAGS} -c $< -o $@ - -obj/%.ao: src/%.S - @mkdir -p $(@D) - ${AS} ${AFLAGS} -c $< -o $@ - -run: build/kernel.elf - @echo Starting QEMU - @${QEMU} -kernel $< ${QFLAGS} - -run-debug: build/kernel-g.elf - @echo Starting QEMU in Debug Mode - @${QEMU} -kernel $< -s -S ${QFLAGS} - -debug: build/kernel-g.elf build/kernel.list - ${GDB} $< -command=gdbinit - -clean: - rm -rf obj/* build/* - -tree: - @tree -a -I obj\|build\|.git\|.gitignore +include Common.mk -- cgit v1.2.1