-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathDefaults.mk
92 lines (79 loc) · 2.02 KB
/
Defaults.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## The following should be from the command line
OSNAME := VisualOS
BUILD_DIR := build
BIN_DIR := bin
# Build procedures
KERNEL := kernel
LIBS := libraries
LIBC := musl
VOSLIB := voslib
MODULES := modules
# Explicit kernel linking directive
KERNEL_SUFFIX := _k
USERSPACE_SUFFIX := _u
# Directories
SRC_DIR := src
BOOTLOADER_DIR := $(BIN_DIR)/bootloader
KERNEL_DIR := $(BUILD_DIR)/$(KERNEL)
LIBS_DIR := $(BUILD_DIR)/$(LIBS)
MODULES_DIR := $(BUILD_DIR)/$(MODULES)
ASMDUMP_DIR := $(BUILD_DIR)/asm
# Programs
CC := gcc
CXX := g++
LD := ld
AS := nasm
ML := ocamlopt
MAKE := make
OBJCOPY := objcopy
# LLVM
ifeq ($(TOOLCHAIN),llvm)
CC := clang
CXX := clang++
LD := lld
endif
CAS := $(CC)
# Flags
DEFAULT_CFLAGS := -fno-pic -fpie -m64 -ffreestanding -fno-builtin -nostdinc -fno-omit-frame-pointer
DEFAULT_ASFLAGS := -f elf64
ifdef DEBUG_MODE
DEBUG_CFLAGS := -O0 -gdwarf
DEBUG_ASFLAGS := -g -F dwarf
ifeq ($(CC), gcc)
DEBUG_CFLAGS += -fvar-tracking
endif
else
DEBUG_CFLAGS := -O1
DEBUG_ASFLAGS := -g -F dwarf
endif
FRAGMENT_CFLAGS := -fvisibility=default -fdata-sections -ffunction-sections
# Includes
DEFAULT_LIBC_INCLUDES := $(SRC_DIR)/$(LIBS)/$(LIBC)/include $(SRC_DIR)/$(LIBS)/$(LIBC)/arch/generic $(SRC_DIR)/$(LIBS)/$(LIBC)/arch/x86_64 $(SRC_DIR)/$(LIBS)/$(LIBC)/obj/include
# Shell configurations
NORMAL := $(shell tput sgr0)
BOLD := $(shell tput bold)
RED := $(shell tput setaf 1)
GREEN := $(shell tput setaf 2)
YELLOW := $(shell tput setaf 3)
BLUE := $(shell tput setaf 4)
MAGENTA := $(shell tput setaf 5)
CYAN := $(shell tput setaf 6)
# Other stuff
BUILD_DIR_ABS := $(abspath $(BUILD_DIR))
# HOST := $(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
# ARCH := $(shell $(CC) -dumpmachine | sed "s/\(-\).*$$//")
# LIBGCC := $(shell $(CC) -print-libgcc-file-name)
# Functions
define echo_build
@echo "$(GREEN)$(BOLD)Building $@$(NORMAL)"
endef
define to_obj
$(addsuffix .o, $(subst .,_, $(1)))
endef
define find_many
$(foreach ext,$(2), \
$(shell find $(1) -type f -name '*.$(ext)') \
)
endef
# Rules
default: all