forked from OpenOrbis/mira-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
129 lines (97 loc) · 3.78 KB
/
Makefile
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# CHANGEME: Default Orbis Version
ifeq ($(MIRA_PLATFORM),)
MIRA_PLATFORM := MIRA_PLATFORM_ORBIS_BSD_505
#MIRA_PLATFORM_STEAM_LINK2
#MIRA_PLATFORM_ORBIS_BSD_505
endif
# Project name
PROJ_NAME := Mira
# C++ compiler
CPPC := clang++
# Linker
LNK := ld # ps4-ld, we are compiling for the kernel so this is not going to use the OpenOrbis userland linker
# C compiler
CC := clang
# Archiver
AS := llvm-ar
# Objcopy
OBJCOPY := objcopy
# cppcheck
CPPCHECK := cppcheck
# Output directory, by default is build
ifeq ($(OUT_DIR),)
OUT_DIR := build
endif
# Source directory
SRC_DIR := src
# If the FREEBSD headers path is not set we will try to use the relative path
ifeq ($(BSD_INC),)
BSD_INC := external/freebsd-headers/include
endif
# Include directory paths
I_DIRS := -I. -I$(SRC_DIR) -I"$(BSD_INC)" -Iexternal/hde64 -Iexternal/protobuf-c
# Library directory paths
L_DIRS := -L. -Llib
# Included libraries
LIBS :=
# C Defines
C_DEFS := -D_KERNEL=1 -D_DEBUG -D_STANDALONE -D"MIRA_PLATFORM=${MIRA_PLATFORM}" -DMIRA_UNSUPPORTED_PLATFORMS -D__LP64__ -D_M_X64 -D__amd64__ -D__BSD_VISIBLE
# C++ Flags, -02 Optimizations break shit badly
CFLAGS := $(I_DIRS) $(C_DEFS) -fpic -m64 -O0 -fno-builtin -nodefaultlibs -nostdlib -nostdinc -fcheck-new -ffreestanding -fno-strict-aliasing -fno-exceptions -fno-asynchronous-unwind-tables -Wall -Werror -Wno-unknown-pragmas
# Assembly flags
SFLAGS := -pie -m64 -nodefaultlibs -nostdlib
# Linker flags
# -Wl,--build-id=none -T $(SRC_DIR)/link.x --emit-relocs -gc-sections -nmagic --relocatable
LFLAGS := -v $(L_DIRS) -nostdlib -entry="mira_entry" -pie
# Calculate the listing of all file paths
ALL_CPP := $(sort $(shell find $(SRC_DIR)/ -type f -name '*.cpp'))
ALL_C := $(sort $(shell find $(SRC_DIR)/ -type f -name '*.c'))
ALL_S := $(sort $(shell find $(SRC_DIR)/ -type f -name '*.s'))
ALL_SOURCES := $(ALL_S) $(ALL_C) $(ALL_CPP)
TO_BUILD := $(ALL_S:$(SRC_DIR)%=$(OUT_DIR)/$(SRC_DIR)%) $(ALL_C:$(SRC_DIR)%=$(OUT_DIR)/$(SRC_DIR)%) $(ALL_CPP:$(SRC_DIR)%=$(OUT_DIR)/$(SRC_DIR)%)
ALL_OBJ_CPP := $(TO_BUILD:.cpp=.o)
ALL_OBJ_C := $(ALL_OBJ_CPP:.c=.o)
ALL_OBJ := $(ALL_OBJ_C:.s=.o)
# Target elf name
TARGET = "$(PROJ_NAME)_Orbis_${MIRA_PLATFORM}.elf"
# Target payload name (data + text only, no elf)
PAYLOAD = "$(PROJ_NAME)_Orbis_${MIRA_PLATFORM}.bin"
.PHONY: all clean
all: post-build
pre-build:
@echo "Pre-Build"
@cppcheck $(SRC_DIR) $(I_DIRS) $(C_DEFS) --enable=information --check-config
@$(MAKE) --no-print-directory clean
post-build: main-build
@echo "Post-Build"
@echo "Linking $(PROJ_NAME)..."
@$(LNK) $(ALL_OBJ) -o $(OUT_DIR)/$(TARGET) $(LFLAGS) $(LIBS)
# @echo "Creating Payload..."
# @$(OBJCOPY) -O binary $(OUT_DIR)/$(TARGET) $(OUT_DIR)/$(PAYLOAD)
@echo "Building loader..."
@$(MAKE) --no-print-directory loader-build
main-build: pre-build
@echo "Building for Firmware $(MIRA_PLATFORM)..."
@scan-build $(MAKE) --no-print-directory $(ALL_OBJ)
loader-build:
@echo "Loader-Build"
$(MAKE) --no-print-directory -C loader clean
$(MAKE) --no-print-directory -C loader create
$(MAKE) --no-print-directory -C loader
$(OUT_DIR)/$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
@echo "Compiling $< ..."
@clang-tidy -checks=clang-analyzer-*,bugprone-*,portability-*,cert-* $< -- $(I_DIRS) $(C_DEFS)
@$(CC) $(CFLAGS) $(I_DIRS) -c $< -o $@
$(OUT_DIR)/$(SRC_DIR)/%.o: $(SRC_DIR)/%.cpp
@echo "Compiling $< ..."
@clang-tidy -checks=clang-analyzer-*,bugprone-*,portability-*,cert-* $< -- $(I_DIRS) $(C_DEFS)
@$(CPPC) $(CFLAGS) -std=c++17 -fno-rtti $(I_DIRS) -c $< -o $@
$(OUT_DIR)/$(SRC_DIR)/%.o: $(SRC_DIR)/%.s
@echo "Assembling $< ..."
@$(CC) $(SFLAGS) -c -o $@ $<
clean:
@echo "Cleaning project..."
@rm -f $(OUT_DIR)/$(TARGET) $(OUT_DIR)/$(PAYLOAD) $(shell find $(OUT_DIR)/ -type f -name '*.o')
create:
@echo "Creating directories..."
@mkdir -p $(shell find '$(SRC_DIR)/' -type d -printf '$(OUT_DIR)/%p\n')