-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
104 lines (83 loc) · 2.86 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
PREFIX :=
TOPDIR=$(shell pwd)
# Include user config
ifeq ($(MACHINE_TYPE),)
-include .config
MACHINE_TYPE=$(subst $\",,$(CONFIG_MACHINE_TYPE))
-include Make.defs
-include arch/*/$(MACHINE_TYPE)/Make.defs
CFLAGS+=$(subst $\",,$(CONFIG_CFLAGS))
LDFLAGS+=$(subst $\",,$(CONFIG_LDFLAGS))
ifneq ($(CONFIG_PREFIX_TOOLCHAIN),)
PREFIX := $(CONFIG_PREFIX_TOOLCHAIN)
endif
endif
$(info machine_type=$(MACHINE_TYPE))
TARGET=$(MACHINE_TYPE)
# List the directories that contain the MACHINE_TYPE name
SRC_DIRS := $(shell find . -iname $(MACHINE_TYPE))
SRC_DIRS += sched utils apps lib drivers
# This is the archive where we will bundle the object files
TMP_LIB=libtmp.a
# Export varios variables that will be used across Makefiles
export CFLAGS
export PREFIX
export TOPDIR
export TMP_LIB
export TARGET
#ifneq ($(CONFIG_HOST_OS),"Linux")
#CFLAGS +=-I/lib/modules/$(shell uname -r)/build/include/
#endif
all: create_board_file create_object_files s_alloc/s_heap.o
mkdir -p build
ifeq ($(CONFIG_TWO_PASS_BUILD),y)
@echo "Two pass build"
cd build && ${PREFIX}ar xv ${TOPDIR}/${TMP_LIB} && \
${PREFIX}ld -r -L${TOPDIR}/ $(LDFLAGS) *.o $(LDUNEXPORTSYMBOLS)
ifneq ($(CONFIG_HOST_OS),"Darwin")
${PREFIX}objcopy --redefine-syms=Linux-names.dat build/build.rel
endif
${PREFIX}gcc build/build.rel arch/sim/sim/host_board_up.o -o build.elf $(EXTRALINK)
else
cd build && ${PREFIX}ar xv ${TOPDIR}/${TMP_LIB} && \
${PREFIX}gcc *.o -o build.elf ${LDFLAGS} && \
${PREFIX}objcopy -O ihex build.elf build.hex && \
${PREFIX}objcopy -O binary build.elf build.bin
endif
@echo "Build finished successfully."
s_alloc/s_heap.o:
$(MAKE) -C s_alloc all ;
create_object_files:
for src_dir in $(SRC_DIRS) ; do \
$(MAKE) -C $$src_dir all;\
done ;
create_board_file: .config
mkdir -p include/chip/ && cp arch/*/$(MACHINE_TYPE)/include/*.h include/chip/.
echo "#ifndef __BOARD_CFG_H\n#define __BOARD_CFG_H" > include/board_cfg.h
cat .config | grep -v "^#" | grep -v "^$$" | tail -n +3 | sed 's/^/#define /' | sed 's/=/ /' >> include/board_cfg.h
echo "#endif /* __BOARD_CFG_H */" >> include/board_cfg.h
cat .config | grep -v "^#" | grep -v "^$$" | tail -n +3 | sed 's/^/export /' | sed 's/=/ /' > Make.defs
load:
eval $(CONFIG_COMMAND_LOAD)
config:
cp config/$(MACHINE_TYPE)/release/defconfig .config
cat .config | grep -v '^#' | grep -v '^$$' | tail -n +4 | sed 's/^/export /' | sed 's/=/ /' > Make.defs
savedefconfig:
cp .config defconfig
menuconfig:
cp arch/*/$(MACHINE_TYPE)/Kconfig include/.
kconfig-mconf Kconfig
.PHONY: clean debug config load create_board_file distclean menuconfig savedefconfig
clean:
for src_dir in $(SRC_DIRS) ; do \
$(MAKE) -C $$src_dir clean; \
done ;
$(MAKE) -C s_alloc clean;
rm -rf build/ && rm -f $(TMP_LIB)
rm -f include/Kconfig 2> /dev/null
rm -f include/chip/* 2> /dev/null
distclean: clean
rm -f .config
rm -f Make.defs
rm -f include/Kconfig
rm -f include/chip/* 2> /dev/null