Skip to content

Commit

Permalink
kern: Misc build system upgrades
Browse files Browse the repository at this point in the history
  • Loading branch information
mintsuki committed Nov 29, 2024
1 parent 5d770ed commit 1c81da3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
38 changes: 16 additions & 22 deletions kernel/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,37 @@ MAKEFLAGS += -rR
# Change as needed.
override OUTPUT := vinix

# Convenience macro to reliably declare user overridable variables.
override USER_VARIABLE = $(if $(filter $(origin $(1)),default undefined),$(eval override $(1) := $(2)))

# Destination directory on install (should always be empty by default).
$(call USER_VARIABLE,DESTDIR,)

# Install prefix; /usr/local is a good, standard default pick.
$(call USER_VARIABLE,PREFIX,/usr/local)
PREFIX := /usr/local

# User controllable C compiler command.
$(call USER_VARIABLE,CC,cc)
CC := cc

# User controllable archiver command.
$(call USER_VARIABLE,AR,ar)
AR := ar

# User controllable linker command.
$(call USER_VARIABLE,LD,ld)
LD := ld

# User controllable objdump command.
$(call USER_VARIABLE,OBJDUMP,objdump)
OBJDUMP := objdump

# User controllable V command.
$(call USER_VARIABLE,V,v)
V := v

# User controllable C flags.
$(call USER_VARIABLE,CFLAGS,-g -O2 -pipe)
CFLAGS := -g -O2 -pipe

# User controllable C preprocessor flags. We set none by default.
$(call USER_VARIABLE,CPPFLAGS,)
CPPFLAGS :=

# User controllable V flags. We set none by default.
$(call USER_VARIABLE,VFLAGS,)
VFLAGS :=

# User controllable linker flags. We set none by default.
$(call USER_VARIABLE,LDFLAGS,)
LDFLAGS :=

$(call USER_VARIABLE,PROD,)
PROD :=

# Ensure the dependencies have been obtained.
ifneq ($(shell ( test '$(MAKECMDGOALS)' = clean || test '$(MAKECMDGOALS)' = distclean ); echo $$?),0)
Expand Down Expand Up @@ -143,7 +137,7 @@ override HEADER_DEPS := $(addprefix obj/,$(CFILES:.c=.c.d) $(ASFILES:.S=.S.d))
all: bin/$(OUTPUT)

# Link rules for building the C compiler runtime.
cc-runtime-x86_64/cc-runtime.a: cc-runtime/*
cc-runtime-x86_64/cc-runtime.a: GNUmakefile cc-runtime/*
rm -rf cc-runtime-x86_64
cp -r cc-runtime cc-runtime-x86_64
$(MAKE) -C cc-runtime-x86_64 -f cc-runtime.mk \
Expand All @@ -160,16 +154,16 @@ bin/$(OUTPUT): GNUmakefile linker.ld obj/blob.c.o $(OBJ) cc-runtime-x86_64/cc-ru
$(CC) $(CFLAGS) $(CPPFLAGS) -c obj/symbol_table.c -o obj/symbol_table.c.o
$(LD) obj/blob.c.o $(OBJ) cc-runtime-x86_64/cc-runtime.a $(LDFLAGS) -o $@

obj/blob.c.o: $(VFILES)
# Include header dependencies.
-include obj/blob.c.d $(HEADER_DEPS)

obj/blob.c.o: GNUmakefile $(VFILES)
mkdir -p "$$(dirname $@)"
$(V) $(VFLAGS) -o obj/blob.c .
sed 's/call 0(/call *(/g' < obj/blob.c > obj/blob.c.tmp
mv obj/blob.c.tmp obj/blob.c
$(CC) $(CFLAGS) $(CPPFLAGS) -w -c obj/blob.c -o $@

# Include header dependencies.
-include $(HEADER_DEPS)

# Compilation rules for *.c files.
obj/%.c.o: c/%.c GNUmakefile
mkdir -p "$$(dirname $@)"
Expand Down
4 changes: 2 additions & 2 deletions kernel/get-deps
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,12 @@ clone_repo_commit \
clone_repo_commit \
https://github.com/osdev0/cc-runtime.git \
cc-runtime \
13fe6383470f0e4982d926472448d6d3b80a851f
9c281448fe40498a6341d74f55c9af4f642c0b1d

clone_repo_commit \
https://github.com/mintsuki/flanterm.git \
c/flanterm \
ef07a10cc38b34aa003d17be97a9f3542e275069
a6f6edd6631c01caab932a59dce97bbd5f0c72c8

download_by_hash \
https://github.com/eyalroz/printf/raw/2d75fef6c605e699d2643267cbaeaaa49b0a2635/src/printf/printf.c \
Expand Down

0 comments on commit 1c81da3

Please sign in to comment.