-
Notifications
You must be signed in to change notification settings - Fork 9
/
Makefile
executable file
·139 lines (115 loc) · 3.13 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
#
# Makefile for a workspace of EV3 Platform.
#
#
# Include configurations of EV3RT SDK
#
SDKDIR = ..
WSPDIR = $(basename $(PWD))
include $(SDKDIR)/Makefile.sdk.conf
# Configuration
SRCLANG := c
KERNEL := hrp2
#
# Functions
#
get_relpath = $(shell perl -MFile::Spec -e "print File::Spec->abs2rel(q($1),q($2))")
#
# Paths
#
KERNELDIR := $(PWD)/$(SDKDIR)/$(EV3RT_BASE_DIR)
OBJDIR := $(PWD)/$(SDKDIR)/$(EV3RT_PRJ_OBJ_DIR)
LIBKERNELDIR := $(PWD)/$(SDKDIR)/$(EV3RT_LIBKERNEL_DIR)
TARGETDIR := $(PWD)/$(KERNELDIR)/target/ev3_gcc
# Object files
OBJFILENAME := $(KERNEL)
ifneq (, $(findstring CYGWIN, $(shell uname)))
OBJFILENAME := $(OBJFILENAME).exe
endif
OBJBINARY := $(OBJDIR)/$(KERNEL).bin
#
# Determine Makefile for application
# OUTPUT:
# $(APPLDIR): Absolute path of application folder
# $(MKFILENAME): File name of Makefile
# $(MKFILE_DIR): Absolute path of the folder holding Makefile
#
ifdef img
APPLDIR := $(PWD)/$(img)
MKFILENAME := Makefile.img
endif
ifdef app
APPLDIR := $(PWD)/$(app)
MKFILENAME := Makefile.app
endif
MKFILE_DIR := $(APPLDIR)
ifeq (,$(wildcard $(mkfile_dir)/$(MKFILENAME)))
MKFILE_DIR := $(SDKDIR)/common
endif
# Target for an application (static)
#
ifdef img
include $(APPLDIR)/Makefile.inc
ifeq (,$(wildcard $(LIBKERNELDIR)/libkernel.a))
# Build libkernel.a if not exist
img: $(APPLDIR) $(LIBKERNELDIR)/libkernel.a prepare-obj-folder
else
img: $(APPLDIR) prepare-obj-folder
endif
@cd $(OBJDIR) && \
make offset.h kernel_cfg.h && \
make -j8 > /dev/null && \
arm-none-eabi-objcopy -O binary \
$(OBJFILENAME) $(call get_relpath,$(OBJBINARY),$(OBJDIR))
@mkimage -A arm -O linux -T kernel -C none -a 0xc0008000 -e 0xc0008000 \
-n "TOPPERS/$(KERNEL) Kernel (EV3)" \
-d $(call get_relpath,$(OBJBINARY),$(PWD)) uImage
@chmod +x uImage
@cp $(OBJDIR)/$(OBJFILENAME) $(PWD)
$(LIBKERNELDIR)/libkernel.a: prepare-obj-folder
@cd $(OBJDIR) && \
make clean && \
make libkernel.a > /dev/null && \
cp libkernel.a $(LIBKERNELDIR)/libkernel.a
endif
#
# Target for an application module (dynamic)
#
ifdef app
include $(APPLDIR)/Makefile.inc
app: $(APPLDIR) prepare-obj-folder
@cd $(OBJDIR) && \
make module_cfg.h && \
make -j8 && \
cp app $(PWD)/app # && cp app $(PWD)/app-$(subst /,,$(app))
endif
usage:
@echo make img="<folder>"
@echo make app="<folder>"
clean:
rm -rf $(OBJDIR)
realclean: clean
rm -rf $(notdir $(OBJFILENAME)) uImage app $(LIBKERNELDIR)/libkernel.a
#
# Phony target for preparing $(OBJDIR) folder
#
temp_mkfilename := .ev3rt_temp_Makefile
ifdef app
configure_copts := -DBUILD_MODULE
endif
prepare-obj-folder: clean
@cp $(MKFILE_DIR)/$(MKFILENAME) $(APPLDIR)/$(temp_mkfilename)
@mkdir -p $(OBJDIR)
cd $(OBJDIR) && \
$(KERNELDIR)/configure -T ev3_gcc -A app \
-a $(call get_relpath,$(APPLDIR),$(OBJDIR)) \
-t $(call get_relpath,$(APPLDIR),$(OBJDIR)) \
-D $(call get_relpath,$(KERNELDIR),$(OBJDIR)) \
-L $(call get_relpath,$(LIBKERNELDIR),$(OBJDIR)) \
-l $(SRCLANG) \
-m $(temp_mkfilename) -o "$(configure_copts)" \
-U "$(APPLOBJS)" && \
rm $(APPLDIR)/$(temp_mkfilename) && \
mv $(temp_mkfilename) Makefile && \
make clean
.PHONY: clean realclean prepare-obj-folder img app