Skip to content

Commit

Permalink
Update Makefile(s) (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
willdurand committed Dec 17, 2019
1 parent 4bf033c commit a621904
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
5 changes: 4 additions & 1 deletion .circleci/config.yml
Expand Up @@ -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
2 changes: 1 addition & 1 deletion 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

Expand Down
28 changes: 15 additions & 13 deletions Makefile
Expand Up @@ -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

Expand All @@ -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 $@ $^

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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:
Expand Down
22 changes: 7 additions & 15 deletions 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

0 comments on commit a621904

Please sign in to comment.