diff --git a/.circleci/config.yml b/.circleci/config.yml index 42c15c426..d8e33f221 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -6,7 +6,10 @@ 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 + - run: test -f build/libc-willOS.a + - run: test -f build/libk-willOS.a - run: test -f build/willOS.iso 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 diff --git a/Makefile b/Makefile index be775d00d..2f80be182 100644 --- a/Makefile +++ b/Makefile @@ -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..abc801393 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 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