Implemented support for building host binaries to test kernel features

This commit is contained in:
2022-12-26 22:12:53 +00:00
parent 23e8e654d9
commit 83c7f2293c
7 changed files with 67 additions and 2 deletions

View File

@@ -60,9 +60,10 @@ $(BUILD_DIR)/%.o: %.c
@$(CC) $< -o $@ -c $(CFLAGS) $(ARCH_CFLAGS)
clean:
@printf " \033[1;93mRM\033[0m Deleting build artefacts.\n"
@printf " \033[1;93mRM\033[0m Deleting kernel build artefacts.\n"
@rm -rf $(BUILD_DIR)
@$(MAKE) -C sandbox clean
all: $(BUILD_DIR)/$(KERNEL_EXEC)
@@ -73,10 +74,13 @@ $(BUILD_DIR)/compile_commands.json:
@./tools/make/generate_compile_commands.py
sandbox:
@$(MAKE) -C sandbox
compile-db: $(BUILD_DIR)/compile_commands.json
include arch/$(ARCH)/extra.mk
.PHONY: all compile-db
.PHONY: all compile-db sandbox
.INTERMEDIATE: $(ARCH_TEMP_FILES)

13
sandbox/Makefile Normal file
View File

@@ -0,0 +1,13 @@
SANDBOX_DIR_LIST := hello
all:
@for prog in $(SANDBOX_DIR_LIST); do \
$(MAKE) -C $$prog; \
done
clean:
@for prog in $(SANDBOX_DIR_LIST); do \
$(MAKE) -C $$prog clean; \
done
.PHONY: all clean

4
sandbox/hello/Makefile Normal file
View File

@@ -0,0 +1,4 @@
SANDBOX_PROG_NAME := hello
include ../sandbox-config.mk
include ../sandbox-template.mk

7
sandbox/hello/main.c Normal file
View File

@@ -0,0 +1,7 @@
#include <stdio.h>
int main(int argc, const char **argv)
{
printf("Hello, world\n");
return 0;
}

View File

@@ -0,0 +1,8 @@
MAKEFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
SANDBOX_DIR := $(patsubst %/,%,$(dir $(MAKEFILE_PATH)))
include $(SANDBOX_DIR)/../tools/make/gcc-host.mk
SANDBOX_BUILD_DIR := $(SANDBOX_DIR)/../build/sandbox
BUILD_DIR := $(SANDBOX_BUILD_DIR)/$(SANDBOX_PROG_NAME)

View File

@@ -0,0 +1,22 @@
BUILD_DIR := $(SANDBOX_BUILD_DIR)/$(SANDBOX_PROG_NAME)
SRC := $(wildcard *.c)
OBJ := $(addprefix $(BUILD_DIR)/,$(SRC:.c=.o))
$(BUILD_DIR)/$(SANDBOX_PROG_NAME): $(OBJ)
@mkdir -p $(@D)
@printf " \033[1;36mHOSTLD\033[0m \033[1msandbox/$(SANDBOX_PROG_NAME)\033[0m\n"
@$(CC) $< -o $@ $(CFLAGS) $(LDFLAGS)
$(BUILD_DIR)/%.o: %.c
@printf " \033[1;32mHOSTCC\033[0m $(SANDBOX_PROG_NAME)/$^\n"
@mkdir -p $(@D)
@$(CC) $< -o $@ -c $(CFLAGS)
all: $(SANDBOX_PROG_NAME)
clean:
@printf " \033[1;93mRM\033[0m Deleting sandbox/$(SANDBOX_PROG_NAME)\n"
@rm -rf $(BUILD_DIR)

7
tools/make/gcc-host.mk Normal file
View File

@@ -0,0 +1,7 @@
LD := gcc
CC := gcc
ASM := gcc
CFLAGS := -Wall -Werror -pedantic
ASMFLAGS := $(CFLAGS)
LDFLAGS := -O2