From 1b90d450a0db3d0ca70872d8d7bdf26c483703b2 Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 20:47:17 +0100 Subject: [PATCH 1/6] Refactor makefiles to build libk, libc and init --- Makefile | 34 ++++++++++++++++++---------------- init/Makefile | 24 ++++++++---------------- 2 files changed, 26 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index be775d00d..923d4d1d1 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ NASM ?= nasm QEMU ?= qemu-system-x86_64 ifeq ($(shell uname -s),Darwin) - CC = x86_64-pc-elf-gcc - LD = x86_64-pc-elf-ld - AR = x86_64-pc-elf-ar + CC ?= x86_64-pc-elf-gcc + LD ?= x86_64-pc-elf-ld + AR ?= x86_64-pc-elf-ar endif OS_NAME = willOS @@ -22,14 +22,12 @@ LIBC = $(BUILD_DIR)/libc-$(OS_NAME).a LIBK = $(BUILD_DIR)/libk-$(OS_NAME).a OBJECTS := $(patsubst %.asm,%.o,$(shell find asm -name '*.asm')) -SOURCES := $(patsubst %.c,%.o,$(shell find libs src -name '*.c')) +LIBK_SOURCES := $(patsubst %.c,%_k.o,$(shell find libs src -name '*.c')) LIBC_SOURCES := $(patsubst %.c,%.o,$(shell find src/libc -name '*.c')) CFLAGS = -W -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib \ - -fno-builtin -fno-stack-protector \ - -mno-red-zone \ - -I src/include/ -I src/ -I libs/ \ - -D__is_libk + -fno-builtin -fno-stack-protector -mno-red-zone \ + -I src/include/ -I src/ -I libs/ DEBUG_CFLAGS = -DENABLE_KERNEL_DEBUG -DDEBUG_WITH_COLORS -DDISABLE_MMU_DEBUG @@ -47,10 +45,14 @@ $(OBJECTS): %.o: %.asm mkdir -p $(BUILD_DIR) $(NASM) -f elf64 $< -$(SOURCES): %.o: %.c +$(LIBK_SOURCES): CFLAGS += -D__is_libk +$(LIBK_SOURCES): %_k.o: %.c $(CC) $(CFLAGS) -c $< -o $@ -$(LIBK): $(SOURCES) +$(LIBC_SOURCES): %.o: %.c + $(CC) $(CFLAGS) -c $< -o $@ + +$(LIBK): $(LIBK_SOURCES) mkdir -p $(BUILD_DIR) $(AR) rcs $@ $^ @@ -59,7 +61,6 @@ $(LIBC): $(LIBC_SOURCES) $(AR) rcs $@ $^ libc: ## build the libc (for userland) -libc: CFLAGS := $(filter-out -D__is_libk, $(CFLAGS)) libc: $(LIBC) .PHONY: libc @@ -86,8 +87,9 @@ debug: $(ISO) clean: ## remove build artifacts find . -name '*.orig' -exec rm "{}" ";" - rm -f $(OBJECTS) $(SOURCES) $(KERNEL) $(ISO) $(LIBK) $(LIBC) + rm -f $(OBJECTS) $(LIBK_SOURCES) $(LIBC_SOURCES) $(KERNEL) $(ISO) $(LIBK) $(LIBC) rm -rf $(BUILD_DIR) + $(MAKE) -C init/ clean .PHONY: clean fmt: ## automatically format the code with astyle @@ -101,10 +103,10 @@ gdb: $(ISO) qemu-system-x86_64 -s -S -cdrom $< -serial file:/tmp/serial.log .PHONY: gdb -# TODO: there must be a better way to compile different modules from a -# top-level makefile. -init: $(LIBC) - cd init && make clean && make +init: ## compile the 'init' program (statically linked to libc) +init: libc + rm -f init/init + $(MAKE) -C init/ .PHONY: init help: diff --git a/init/Makefile b/init/Makefile index 6082b8a6e..4d6324ee0 100644 --- a/init/Makefile +++ b/init/Makefile @@ -1,26 +1,18 @@ -CC ?= gcc -LD ?= ld -AR ?= ar -NASM ?= nasm +CC ?= gcc ifeq ($(shell uname -s),Darwin) - CC = x86_64-pc-elf-gcc - LD = x86_64-pc-elf-ld - AR = x86_64-pc-elf-ar + CC ?= x86_64-pc-elf-gcc endif -TARGET = init -ROOT_DIR = .. -BUILD_DIR = . -CFLAGS = -Wl,-emain -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib -I $(ROOT_DIR)/src/include -LIBS = $(ROOT_DIR)/build/libc-willOS.a +CFLAGS = -Wl,-emain -W -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib \ + -fno-builtin -fno-stack-protector -I src/include/ +LIBS = ../build/libc-willOS.a -%.o: %.c - $(CC) $(CFLAGS) -c $< -o $@ +default: init -$(TARGET): $(TARGET).o +init: init.c $(CC) -o $@ $^ $(CFLAGS) $(LIBS) clean: - rm -rf $(TARGET) *.o + rm -f init *.o .PHONY: clean From a9593e989598247b928f6b271215942f328e3146 Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 20:49:11 +0100 Subject: [PATCH 2/6] Ensure all files are compiled in circle-ci --- .circleci/config.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 42c15c426..a22c74b90 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -9,4 +9,7 @@ jobs: - run: sudo apt-get install nasm xorriso build-essential grub2-common - run: make - run: test -f build/isofiles/boot/kernel.bin + - run: test -f build/isofiles/boot/init + - run: test -f build/libc-willOS.a + - run: test -f build/libk-willOS.a - run: test -f build/willOS.iso From 92978f3b1caf862ff194cd97bb4e857915ad610a Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 21:05:07 +0100 Subject: [PATCH 3/6] Make sure we generate bootable iso files in Docker --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 42f010703..6cea40477 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,6 @@ FROM ubuntu:latest -RUN apt-get update && apt-get install -y nasm xorriso build-essential grub2-common +RUN apt-get update && apt-get install -y nasm xorriso build-essential grub2-common grub-pc-bin RUN groupadd -r simpleuser && useradd --no-log-init -r -g simpleuser simpleuser From e6356c92637294b3dc10f4127e6c1f8cffed6a76 Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 21:06:10 +0100 Subject: [PATCH 4/6] Also fix circle-ci --- .circleci/config.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index a22c74b90..d8e33f221 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,7 @@ jobs: steps: - checkout - run: sudo apt-get update - - run: sudo apt-get install nasm xorriso build-essential grub2-common + - run: sudo apt-get install nasm xorriso build-essential grub2-common grub-pc-bin - run: make - run: test -f build/isofiles/boot/kernel.bin - run: test -f build/isofiles/boot/init From 70c23828a4cdaf585248bc5d0ae0c01aa9dc83e7 Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 21:12:13 +0100 Subject: [PATCH 5/6] Fix path to headers in init/Makefile --- init/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/Makefile b/init/Makefile index 4d6324ee0..d25006b74 100644 --- a/init/Makefile +++ b/init/Makefile @@ -5,7 +5,7 @@ ifeq ($(shell uname -s),Darwin) endif CFLAGS = -Wl,-emain -W -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib \ - -fno-builtin -fno-stack-protector -I src/include/ + -fno-builtin -fno-stack-protector -I ../src/include/ LIBS = ../build/libc-willOS.a default: init From 4d224ee1b0766673a530726d85b5cb357777062d Mon Sep 17 00:00:00 2001 From: William Durand Date: Tue, 17 Dec 2019 21:42:07 +0100 Subject: [PATCH 6/6] Fix Makefiles for MacOS --- Makefile | 6 +++--- init/Makefile | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 923d4d1d1..2f80be182 100644 --- a/Makefile +++ b/Makefile @@ -5,9 +5,9 @@ NASM ?= nasm QEMU ?= qemu-system-x86_64 ifeq ($(shell uname -s),Darwin) - CC ?= x86_64-pc-elf-gcc - LD ?= x86_64-pc-elf-ld - AR ?= x86_64-pc-elf-ar + CC = x86_64-pc-elf-gcc + LD = x86_64-pc-elf-ld + AR = x86_64-pc-elf-ar endif OS_NAME = willOS diff --git a/init/Makefile b/init/Makefile index d25006b74..abc801393 100644 --- a/init/Makefile +++ b/init/Makefile @@ -1,7 +1,7 @@ CC ?= gcc ifeq ($(shell uname -s),Darwin) - CC ?= x86_64-pc-elf-gcc + CC = x86_64-pc-elf-gcc endif CFLAGS = -Wl,-emain -W -Wall -pedantic -std=c11 -O2 -ffreestanding -nostdlib \