aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-11-20 09:53:11 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-11-20 09:53:11 -0800
commit1c8d4e69205fd875f6bec3fa3bd929c2e7f52f62 (patch)
tree8bb6233e8f59d574e99a55a8c9aaf4d90396a2ce /Makefile
parent59d87ccc99f431da06a0ffab0d3e702d9ef82f48 (diff)
Feature: self hosting prototype implemented
This is a large change. In order to remove myself from libc's arcane interface, I implemented an independent runtime layer. It is based on musl's wonderful implementation mostly. Critically, if libc is linked to the program, then we cooperate. Namely, we call start main and let libc do all initialization. If not, then we have a noop defined in rt3.a. The general structure of the file is: 1. sys/$os/$arch contains all architecture dependent code 2. sys/$os/port contains all code that depends on the os, but is portable 3. rt/$arch contains all the runtime architecture dependent code 4. rt/* contains the portable runtime code. Obviously testing is needed. Specifically, while code is checked in for the most popular architectures, it only has been tested on one computer! Overall this is exciting and as been educational.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile20
1 files changed, 10 insertions, 10 deletions
diff --git a/Makefile b/Makefile
index 1a48db3..793d888 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ MAKEFLAGS += --no-builtin-variables
# Compiler, Linker, and Assembler
CC := gcc
AR := ar
-AS := nasm
+AS := gcc
PKG := PKG_CONFIG_PATH=lib/pkgconfig pkg-config
OS := linux
@@ -22,26 +22,26 @@ SRC_DIR := src
OBJ_DIR := obj
TST_DIR := test
-# C runtime library
-CINIT := $(LIB_DIR)/crt/crt1.o $(LIB_DIR)/crt/x86_64/crti.o `gcc --print-file-name=crtbeginS.o`
-CFINI := `gcc --print-file-name=crtendS.o` $(LIB_DIR)/crt/x86_64/crtn.o
+# runtime library
+INIT = $(RT1) $(RTI) `gcc --print-file-name=crtbeginT.o`
+FINI = `gcc --print-file-name=crtend.o` $(RTN) $(RT3)
# Flags, Libraries and Includes
CFLAGS := -g -march=native -fno-strict-aliasing -fwrapv -fms-extensions -Wno-microsoft-anon-tag
-STATIC := -nodefaultlibs -nostartfiles -nostdinc -static
-AFLAGS := -f elf64
+STATIC := -ffreestanding -nodefaultlibs -nostartfiles -nostdinc -static
+AFLAGS := -g
INCS := -I $(SYS_DIR)/$(OS)/$(ARCH) -I $(SYS_DIR)/$(OS)/port -I $(INC_DIR) -isystem $(INC_DIR)/vendor/libc
ELIBS := -L$(LIB_DIR) -lc
# Named generic rules (must be evaluated lazily)
COMPILE = @echo "CC "$(@:$(OBJ_DIR)/%=%);\
- $(CC) -MD $(CFLAGS) $(TCFLAGS) $(INCS) $(TINCS) -o $@ -c $<
+ $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) $(INCS) $(TINCS) -o $@ -c $<
LINK = @echo "LD "$(@:$(OBJ_DIR)/%=%);\
- $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) -o $@ $(CINIT) $< $(CFINI) $(TLIBS) $(ELIBS)
+ $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) -o $@ $(INIT) $< $(TLIBS) $(ELIBS) $(FINI)
COMPLINK = @echo "CC "$(@:$(OBJ_DIR)/%=%);\
- $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) $(INCS) $(TINCS) -o $@ $(CINIT) $^ $(CFINI) $(TLIBS) $(ELIBS)
+ $(CC) -MD $(CFLAGS) $(STATIC) $(TCFLAGS) $(INCS) $(TINCS) -o $@ $(INIT) $^ $(TLIBS) $(ELIBS) $(FINI)
ASSEMBLE = @echo "AS "$(@:$(OBJ_DIR)/%=%);\
- $(AS) $(AFLAGS) $(TCFLAGS) -o $@ $<
+ $(AS) $(AFLAGS) -o $@ -c $<
ARCHIVE = @echo "AR "$(@:$(OBJ_DIR)/%=%);\
$(AR) crs $@ $^