Skip to content

Commit

Permalink
Support cross-compiling
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Feb 4, 2024
1 parent a95a2c1 commit b262afe
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 195 deletions.
152 changes: 118 additions & 34 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,45 +1,129 @@
# This file is part of KASLD - https://github.com/bcoles/kasld
# ---
# <[email protected]>

SHELL = /bin/sh
.SUFFIXES: .c .o

CC = cc
# Warning: Do not compile with -O
FLAGS = -std=c99 -Wall -Wextra -pedantic
CFLAGS = -g -Wall -Wextra -pedantic
ALL_CFLAGS = -std=c99 $(CFLAGS)
LDFLAGS = -static
ALL_LDFLAGS = $(LDFLAGS)

ifndef _ARCH
_ARCH := $(shell $(CC) -dumpmachine)
export _ARCH
endif

BUILD_DIR := ./build
OBJ_DIR := $(BUILD_DIR)/$(_ARCH)
SRC_DIR := ./src
SRC_FILES := $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OBJ_DIR)/%.o,$(SRC_FILES))

.PHONY: all
all : build

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
-$(CC) $(ALL_CFLAGS) $(ALL_LDFLAGS) $< -o $@

.PHONY: pre-build
pre-build :
@echo "Building $(OBJ_DIR) ..."
mkdir -p "$(OBJ_DIR)"

all :
mkdir -p $(BUILD_DIR)
-$(CC) $(FLAGS) $(SRC_DIR)/bcm_msg_head_struct.c -o $(BUILD_DIR)/bcm_msg_head_struct.o
-$(CC) $(FLAGS) $(SRC_DIR)/boot-config.c -o $(BUILD_DIR)/boot-config.o
-$(CC) $(FLAGS) $(SRC_DIR)/cmdline.c -o $(BUILD_DIR)/cmdline.o
-$(CC) $(FLAGS) $(SRC_DIR)/default.c -o $(BUILD_DIR)/default.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_android_ion_snapshot.c -o $(BUILD_DIR)/dmesg_android_ion_snapshot.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_backtrace.c -o $(BUILD_DIR)/dmesg_backtrace.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_check_for_initrd.c -o $(BUILD_DIR)/dmesg_check_for_initrd.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_driver_component_ops.c -o $(BUILD_DIR)/dmesg_driver_component_ops.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_early_init_dt_add_memory_arch.c -o $(BUILD_DIR)/dmesg_early_init_dt_add_memory_arch.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_ex_handler_msr.c -o $(BUILD_DIR)/dmesg_ex_handler_msr.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_fake_numa_init.c -o $(BUILD_DIR)/dmesg_fake_numa_init.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_free_area_init_node.c -o $(BUILD_DIR)/dmesg_free_area_init_node.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_free_reserved_area.c -o $(BUILD_DIR)/dmesg_free_reserved_area.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_kaslr-disabled.c -o $(BUILD_DIR)/dmesg_kaslr-disabled.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_mem_init_kernel_layout.c -o $(BUILD_DIR)/dmesg_mem_init_kernel_layout.o
-$(CC) $(FLAGS) $(SRC_DIR)/dmesg_mmu_idmap.c -o $(BUILD_DIR)/dmesg_mmu_idmap.o
-$(CC) $(FLAGS) $(SRC_DIR)/entrybleed.c -o $(BUILD_DIR)/entrybleed.o
-$(CC) $(FLAGS) $(SRC_DIR)/mincore.c -o $(BUILD_DIR)/mincore.o
-$(CC) $(FLAGS) $(SRC_DIR)/mmap-brute-vmsplit.c -o $(BUILD_DIR)/mmap-brute-vmsplit.o
-$(CC) $(FLAGS) $(SRC_DIR)/perf_event_open.c -o $(BUILD_DIR)/perf_event_open.o
-$(CC) $(FLAGS) $(SRC_DIR)/proc-config.c -o $(BUILD_DIR)/proc-config.o
-$(CC) $(FLAGS) $(SRC_DIR)/pppd_kallsyms.c -o $(BUILD_DIR)/pppd_kallsyms.o
-$(CC) $(FLAGS) $(SRC_DIR)/proc-kallsyms.c -o $(BUILD_DIR)/proc-kallsyms.o
-$(CC) $(FLAGS) $(SRC_DIR)/proc-modules.c -o $(BUILD_DIR)/proc-modules.o
-$(CC) $(FLAGS) $(SRC_DIR)/proc-pid-syscall.c -o $(BUILD_DIR)/proc-pid-syscall.o
-$(CC) $(FLAGS) $(SRC_DIR)/proc-stat-wchan.c -o $(BUILD_DIR)/proc-stat-wchan.o
-$(CC) $(FLAGS) $(SRC_DIR)/sysfs_iscsi_transport_handle.c -o $(BUILD_DIR)/sysfs_iscsi_transport_handle.o
-$(CC) $(FLAGS) $(SRC_DIR)/sysfs-kernel-notes-xen.c -o $(BUILD_DIR)/sysfs-kernel-notes-xen.o
-$(CC) $(FLAGS) $(SRC_DIR)/sysfs-module-sections.c -o $(BUILD_DIR)/sysfs-module-sections.o
-$(CC) $(FLAGS) $(SRC_DIR)/sysfs_nf_conntrack.c -o $(BUILD_DIR)/sysfs_nf_conntrack.o
.PHONY: build
build : pre-build $(OBJ_FILES)

.PHONY: run
run : build
@echo "Running build ..."
@echo

# run default first
-$(OBJ_DIR)/default.o
@echo
-$(OBJ_DIR)/bcm_msg_head_struct.o
@echo
-$(OBJ_DIR)/boot-config.o
@echo
-$(OBJ_DIR)/cmdline.o
@echo
-$(OBJ_DIR)/dmesg_android_ion_snapshot.o
@echo
-$(OBJ_DIR)/dmesg_backtrace.o
@echo
-$(OBJ_DIR)/dmesg_check_for_initrd.o
@echo
-$(OBJ_DIR)/dmesg_driver_component_ops.o
@echo
-$(OBJ_DIR)/dmesg_early_init_dt_add_memory_arch.o
@echo
-$(OBJ_DIR)/dmesg_ex_handler_msr.o
@echo
-$(OBJ_DIR)/dmesg_fake_numa_init.o
@echo
-$(OBJ_DIR)/dmesg_free_area_init_node.o
@echo
-$(OBJ_DIR)/dmesg_free_reserved_area.o
@echo
-$(OBJ_DIR)/dmesg_kaslr-disabled.o
@echo
-$(OBJ_DIR)/dmesg_mem_init_kernel_layout.o
@echo
-$(OBJ_DIR)/dmesg_mmu_idmap.o
@echo
-$(OBJ_DIR)/entrybleed.o
@echo
-$(OBJ_DIR)/mmap-brute-vmsplit.o
@echo
-$(OBJ_DIR)/perf_event_open.o
@echo
-$(OBJ_DIR)/proc-config.o
@echo
-$(OBJ_DIR)/pppd_kallsyms.o
@echo
-$(OBJ_DIR)/proc-kallsyms.o
@echo
-$(OBJ_DIR)/proc-modules.o
@echo
-$(OBJ_DIR)/proc-pid-syscall.o
@echo
-$(OBJ_DIR)/proc-stat-wchan.o
@echo
-$(OBJ_DIR)/sysfs_iscsi_transport_handle.o
@echo
-$(OBJ_DIR)/sysfs-kernel-notes-xen.o
@echo
-$(OBJ_DIR)/sysfs-module-sections.o
@echo
-$(OBJ_DIR)/sysfs_nf_conntrack.o
@echo
# slow - leave this one last
-$(OBJ_DIR)/mincore.o
@echo


.PHONY: clean
clean :
rm -f $(BUILD_DIR)/*.o
@echo "Cleaning $(BUILD_DIR) ..."
rm -rf "$(BUILD_DIR)"


.PHONY: help
help:
@echo
@echo " make [target] [OPTIONS]"
@echo
@echo " Targets:"
@echo " run Build and run"
@echo " all Build all from src directory"
@echo " clean Remove build directory"
@echo
@echo " Options:"
@echo " CC=compiler Compiler executable"
@echo " CFLAGS=flags Compiler flags"
@echo " LDFLAGS=flags Linker flags"
@echo
163 changes: 2 additions & 161 deletions kasld
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# 2019 - <[email protected]>

base_dir="$(dirname "$(readlink -f "$0")")"
build="${base_dir}/build"

cd "${base_dir}" || exit 1

Expand All @@ -31,166 +30,8 @@ echo "Readable /var/log/dmesg: $(test -r /var/log/dmesg && echo yes || echo
echo "Readable /var/log/kern.log: $(test -r /var/log/kern.log && echo yes || echo no)"
echo "Readable /var/log/syslog: $(test -r /var/log/syslog && echo yes || echo no)"
echo "Readable /boot/System.map: $(test -r /boot/System.map-$(uname -r) && echo yes || echo no)"
echo "Readable /boot/config: $(test -r /boot/config-$(uname -r) && echo yes || echo no)"
echo "Readable DebugFS: $(test -r /sys/kernel/debug && echo yes || echo no)"
echo

echo "Building ..."
echo

make || echo "build failed!"
echo

echo "Running build ..."
echo

# leave default as first
if [ -x "${build}/default.o" ]; then
"${build}/default.o"
echo
fi

if [ -x "${build}/boot-config.o" ]; then
"${build}/boot-config.o"
echo
fi

if [ -x "${build}/cmdline.o" ]; then
"${build}/cmdline.o"
echo
fi

if [ -x "${build}/bcm_msg_head_struct.o" ]; then
"${build}/bcm_msg_head_struct.o"
echo
fi

if [ -x "${build}/dmesg_android_ion_snapshot.o" ]; then
"${build}/dmesg_android_ion_snapshot.o"
echo
fi

if [ -x "${build}/dmesg_backtrace.o" ]; then
"${build}/dmesg_backtrace.o"
echo
fi

if [ -x "${build}/dmesg_check_for_initrd.o" ]; then
"${build}/dmesg_check_for_initrd.o"
echo
fi

if [ -x "${build}/dmesg_driver_component_ops.o" ]; then
"${build}/dmesg_driver_component_ops.o"
echo
fi

if [ -x "${build}/dmesg_early_init_dt_add_memory_arch.o" ]; then
"${build}/dmesg_early_init_dt_add_memory_arch.o"
echo
fi

if [ -x "${build}/dmesg_ex_handler_msr.o" ]; then
"${build}/dmesg_ex_handler_msr.o"
echo
fi

if [ -x "${build}/dmesg_fake_numa_init.o" ]; then
"${build}/dmesg_fake_numa_init.o"
echo
fi

if [ -x "${build}/dmesg_free_area_init_node.o" ]; then
"${build}/dmesg_free_area_init_node.o"
echo
fi

if [ -x "${build}/dmesg_free_reserved_area.o" ]; then
"${build}/dmesg_free_reserved_area.o"
echo
fi

if [ -x "${build}/dmesg_kaslr-disabled.o" ]; then
"${build}/dmesg_kaslr-disabled.o"
echo
fi

if [ -x "${build}/dmesg_mem_init_kernel_layout.o" ]; then
"${build}/dmesg_mem_init_kernel_layout.o"
echo
fi

if [ -x "${build}/dmesg_mmu_idmap.o" ]; then
"${build}/dmesg_mmu_idmap.o"
echo
fi

if [ -x "${build}/entrybleed.o" ]; then
"${build}/entrybleed.o"
echo
fi

if [ -x "${build}/mmap-brute-vmsplit.o" ]; then
"${build}/mmap-brute-vmsplit.o"
echo
fi

if [ -x "${build}/perf_event_open.o" ]; then
"${build}/perf_event_open.o"
echo
fi

if [ -x "${build}/pppd_kallsyms.o" ]; then
"${build}/pppd_kallsyms.o"
echo
fi

if [ -x "${build}/proc-config.o" ]; then
"${build}/proc-config.o"
echo
fi

if [ -x "${build}/proc-kallsyms.o" ]; then
"${build}/proc-kallsyms.o"
echo
fi

if [ -x "${build}/proc-modules.o" ]; then
"${build}/proc-modules.o"
echo
fi

if [ -x "${build}/proc-pid-syscall.o" ]; then
"${build}/proc-pid-syscall.o"
echo
fi

if [ -x "${build}/proc-stat-wchan.o" ]; then
"${build}/proc-stat-wchan.o"
echo
fi

if [ -x "${build}/sysfs_iscsi_transport_handle.o" ]; then
"${build}/sysfs_iscsi_transport_handle.o"
echo
fi

if [ -x "${build}/sysfs-kernel-notes-xen.o" ]; then
"${build}/sysfs-kernel-notes-xen.o"
echo
fi

if [ -x "${build}/sysfs-module-sections.o" ]; then
"${build}/sysfs-module-sections.o"
echo
fi

if [ -x "${build}/sysfs_nf_conntrack.o" ]; then
"${build}/sysfs_nf_conntrack.o"
echo
fi

# slow - leave last
if [ -x "${build}/mincore.o" ]; then
"${build}/mincore.o"
echo
fi
make run || echo "build failed!"

0 comments on commit b262afe

Please sign in to comment.