-
Notifications
You must be signed in to change notification settings - Fork 4
/
Makefile
146 lines (99 loc) · 3.88 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#######################################################
# Tachyos Root Makefile #
# Author : Doowoong,Lee #
#######################################################
-include .config
-include version.mk
# setup root directory of source tree
ROOT_DIR := $(CURDIR)
CONFIG_DIR :=$(ROOT_DIR)/source/arch/$(ARCH)/configs
AUTOGEN_DIR :=$(ROOT_DIR)/include/kernel/autogen
# setup tools for 'make' works
CC:=$(CROSS_COMPILE)gcc
CXX:=$(CROSS_COMPILE)g++
SIZE:=$(CROSS_COMPILE)size
PY:=python
PIP:=pip
MKDIR:=mkdir
TOOL_DIR:=$(ROOT_DIR)/tools
CONFIG_PY:= $(ROOT_DIR)/tools/jconfigpy
OBJS_DIR_DEBUG:= $(ROOT_DIR)/DEBUG
OBJS_DIR_RELEASE:= $(ROOT_DIR)/RELEASE
OBJS_DEBUG=$(OBJ-y:%=$(OBJS_DIR_DEBUG)/%)
OBJS_RELEASE=$(OBJ-y:%=$(OBJS_DIR_RELEASE)/%)
KCONFIG_ENTRY:=$(ROOT_DIR)/config.json
KCONFIG_TARGET:=$(ROOT_DIR)/.config
KCONFIG_AUTOGEN:=$(AUTOGEN_DIR)/autogen.h
# SRC-y and INC-y are source and header directory list for each made from recipe file(recipe.mk)
VPATH= $(SRC-y)
INC=$(INC-y:%=-I%)
LIBS= $(SLIB-y:%=-l:%)
LIBDIR= $(LDIR-y:%=-L%)
# Assembler flag used in kernel source build
ASFLAG_KERNEL:= -nostdinc
CFLAG_KERNEL=$(CFLAG_COMMON)
CFLAG_APP=$(CFLAG_COMMON)
CFLAG_MODULE=$(CFLAG_COMMON)
CFLAG_DEBUG:=-O0 -g3 -D__DBG
CFLAG_RELEASE:=-O2 -g0
LDFLAG_KERNEL=$(LDFLAG_COMMON)
LDFLAG_APP=$(LDFLAG_COMMON)
LDFLAG_MODULE=$(LDFLAG_COMMON)
LDFLAG_KERNEL+=$(DEF:%=-defsym,%)
DEF-y+=$(DEF)
DEFS=$(DEF-y:%=-D%)
DEBUG_OBJS=$(OBJ-y:%=DEBUG/%)
RELEASE_OBJS=$(OBJ-y:%=RELEASE/%)
DEBUG_TARGET=TachyOS_dbg_$(MAJOR).$(MINOR).$(PATCH).elf
RELEASE_TARGET=TachyOS_rel_$(MAJOR).$(MINOR).$(PATCH).elf
PHONY=config all debug release clean config_clean
.SILENT : $(SILENT)
SILENT=config $(OBJ-y:%=DEBUG/%) $(OBJ-y:%=RELEASE/%) $(DEBUG_TARGET) $(RELEASE_TARGET) reset clean
all : debug
config: $(KCONFIG_TARGET)
ifeq ($(DEFCONF),)
$(KCONFIG_TARGET) : $(AUTOGEN_DIR) $(CONFIG_PY)
$(PY) $(CONFIG_PY) -c -i $(KCONFIG_ENTRY) -o $(KCONFIG_TARGET) -g $(KCONFIG_AUTOGEN)
else
$(KCONFIG_TARGET) : $(AUTOGEN_DIR) $(CONFIG_PY)
$(PY) $(CONFIG_PY) -s -i $(CONFIG_DIR)/$(DEFCONF) -t $(KCONFIG_ENTRY) -o $(KCONFIG_TARGET) -g $(KCONFIG_AUTOGEN)
endif
$(CONFIG_PY):
$(PIP) install jconfigpy -t $(TOOL_DIR)
debug: $(OBJS_DIR_DEBUG) $(DEBUG_TARGET)
release: $(OBJS_DIR_RELEASE) $(RELEASE_TARGET)
$(DEBUG_TARGET) : $(DEBUG_OBJS)
@echo 'building elf image.. $@'
$(CC) $(CFLAG_DEBUG) $(CFLAG_KERNEL) $(INC) $(DEFS) $(DEBUG_OBJS) $(LDFLAG_KERNEL:%=-Wl,%) -o $@ $(LIBDIR) $(LIBS)
$(SIZE) $@
@echo 'build complete!!'
$(RELEASE_TARGET) : $(RELEASE_OBJS)
@echo 'building elf image.. $@'
$(CC) $(CLFAG_RELEASE) $(CFLAG_KERNEL) $(INC) $(DEFS) $(RELEASE_OBJS) $(LDFLAG_KERNEL:%=-Wl,%) -o $@ $(LIBDIR) $(LIBS)
$(SIZE) $@
@echo 'build complete!!'
$(OBJS_DIR_DEBUG) $(OBJS_DIR_RELEASE) $(AUTOGEN_DIR):
$(MKDIR) $@
DEBUG/%.uo:%.c
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_DEBUG) $(CFLAG_APP) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_APP:%=-Wl,%) -o $@
DEBUG/%.ko:%.c
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_DEBUG) $(CFLAG_KERNEL) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_KERNEL:%=-Wl,%) -o $@
DEBUG/%.sko:%.S
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_DEBUG) $(CFLAG_KERNEL) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_KERNEL:%=-Wl,%) $(ASFLAG_KERNEL) -o $@
RELEASE/%.uo:%.c
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_RELEASE) $(CFLAG_APP) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_APP:%=-Wl,%) -o $@
RELEASE/%.ko:%.c
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_RELEASE) $(CFLAG_KERNEL) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_KERNEL:%=-Wl,%) -o $@
RELEASE/%.sko:%.S
@echo 'compile.. $@'
$(CC) $< -c $(CFLAG_RELEASE) $(CFLAG_KERNEL) $(INC) $(DEFS) $(LIBDIR) $(LIBS) $(LDFLAG_KERNEL:%=-Wl,%) $(ASFLAG_KERNEL) -o $@
clean:
rm -rf $(OBJ-y) $(DEBUG_TARGET) $(RELEASE_TARGET) $(RELEASE_OBJS) $(DEBUG_OBJS)
reset: clean
rm -rf $(KCONFIG_TARGET) $(KCONFIG_AUTOGEN) $(REPO-y) $(LDIR-y)
.PHONY = $(PHONY)