Skip to content

Commit c5c40dd

Browse files
committed
Initial commit
0 parents  commit c5c40dd

File tree

5 files changed

+344
-0
lines changed

5 files changed

+344
-0
lines changed

core/main.mk

+254
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,254 @@
1+
ifneq ($(BUILD_WITH_COLORS),0)
2+
CL_RED="\033[1;31m"
3+
CL_GRN="\033[1;32m"
4+
CL_YLW="\033[1;33m"
5+
CL_BLU="\033[1;34m"
6+
CL_MAG="\033[1;35m"
7+
CL_CYN="\033[1;36m"
8+
CL_RST="\033[0m"
9+
endif
10+
11+
# enable GCC colors by default (if supported)
12+
export GCC_COLORS ?= 1
13+
14+
# Utility variables.
15+
empty :=
16+
space := $(empty) $(empty)
17+
comma := ,
18+
# Note that make will eat the newline just before endef.
19+
define newline
20+
21+
22+
endef
23+
# Unfortunately you can't simply define backslash as \ or \\.
24+
backslash := \a
25+
backslash := $(patsubst %a,%,$(backslash))
26+
27+
# log functions
28+
# logi(message)
29+
define logi
30+
$(info $(shell echo -e ${CL_CYN}$(1)${CL_RST}))
31+
endef
32+
# logw(message)
33+
define logw
34+
$(info $(shell echo -e ${CL_YLW}$(1)${CL_RST}))
35+
endef
36+
# loge(message)
37+
define loge
38+
$(info $(shell echo -e ${CL_RED}))
39+
$(error $(shell echo -e "$(1)"${CL_RST}))
40+
endef
41+
# logv(message)
42+
define logv
43+
$(info $(shell echo -e $(1)))
44+
endef
45+
46+
# Only use EFIDROID_BUILD_SHELL to wrap around bash.
47+
# DO NOT use other shells such as zsh.
48+
ifdef EFIDROID_BUILD_SHELL
49+
SHELL := $(EFIDROID_BUILD_SHELL)
50+
else
51+
# Use bash, not whatever shell somebody has installed as /bin/sh
52+
# This is repeated in config.mk, since envsetup.sh runs that file
53+
# directly.
54+
SHELL := /bin/bash
55+
endif
56+
57+
# this turns off the suffix rules built into make
58+
.SUFFIXES:
59+
60+
# this turns off the RCS / SCCS implicit rules of GNU Make
61+
% : RCS/%,v
62+
% : RCS/%
63+
% : %,v
64+
% : s.%
65+
% : SCCS/s.%
66+
67+
# If a rule fails, delete $@.
68+
.DELETE_ON_ERROR:
69+
70+
# Check for broken versions of make.
71+
# (Allow any version under Cygwin since we don't actually build the platform there.)
72+
ifeq (,$(findstring CYGWIN,$(shell uname -sm)))
73+
ifneq (1,$(strip $(shell expr $(MAKE_VERSION) \>= 3.81)))
74+
$(warning ********************************************************************************)
75+
$(warning * You are using version $(MAKE_VERSION) of make.)
76+
$(warning * EFIDroid can only be built by versions 3.81 and higher.)
77+
$(warning ********************************************************************************)
78+
$(error stopping)
79+
endif
80+
endif
81+
82+
# identify host kernel
83+
KERNEL_NAME := $(shell uname -s)
84+
ifeq ($(KERNEL_NAME),Linux)
85+
HOSTTYPE := linux-x86
86+
endif
87+
ifeq ($(KERNEL_NAME),Darwin)
88+
HOSTTYPE := darwin-x86
89+
endif
90+
ifeq ($(HOSTTYPE),)
91+
$(call loge,Unsupprted host kernel $(KERNEL_NAME))
92+
endif
93+
94+
# clean macro
95+
CLEANSTEPS =
96+
# add-clean-step(target)
97+
define add-clean-step
98+
$(eval CLEANSTEPS += $(1))
99+
endef
100+
101+
# distclean macro
102+
DISTCLEANSTEPS =
103+
# add-distclean-step(target)
104+
define add-distclean-step
105+
$(eval DISTCLEANSTEPS += $(1))
106+
endef
107+
108+
109+
# Absolute path of the present working direcotry.
110+
# This overrides the shell variable $PWD, which does not necessarily points to
111+
# the top of the source tree, for example when "make -C" is used in m/mm/mmm.
112+
PWD := $(shell pwd)
113+
114+
TOP := .
115+
TOPDIR :=
116+
117+
BUILD_SYSTEM := $(TOPDIR)build/core
118+
OUT := $(TOPDIR)out
119+
HOST_OUT := $(OUT)/host
120+
121+
# GCC
122+
GCC_DIR := $(PWD)/$(TOPDIR)prebuilts/gcc/$(HOSTTYPE)
123+
GCC_TARGET_DIR := $(GCC_DIR)/arm
124+
GCC_LINUX_GNUEABI := $(GCC_TARGET_DIR)/arm-linux-gnueabihf-4.9/bin/arm-linux-gnueabihf-
125+
GCC_EABI := $(GCC_TARGET_DIR)/arm-eabi-4.8/bin/arm-eabi-
126+
127+
# This is the default target. It must be the first declared target.
128+
.PHONY: all
129+
DEFAULT_GOAL := all
130+
$(DEFAULT_GOAL):
131+
132+
# Used to force goals to build. Only use for conditionally defined goals.
133+
.PHONY: FORCE
134+
FORCE:
135+
136+
# Hi :)
137+
$(call logi,EFIDroid Build System)
138+
139+
# These goals don't need to be built
140+
nobuild_goals := \
141+
help out \
142+
show_devices
143+
144+
ifneq ($(filter $(nobuild_goals), $(MAKECMDGOALS)),)
145+
146+
.PHONY: show_devices
147+
show_devices:
148+
@echo Devices:
149+
@for f in $(strip $(wildcard $(TOPDIR)device/*/*/config.mk)); do \
150+
parts=($${f//\// });\
151+
echo -e \\t$${parts[1]}/$${parts[2]}; \
152+
done
153+
154+
.PHONY: help
155+
help:
156+
@echo
157+
@echo "Common make targets:"
158+
@echo "----------------------------------------------------------------------------------"
159+
@echo "all Default target"
160+
@echo "clean run 'make clean' on all targets"
161+
@echo "distclean equivalent to rm -rf out/"
162+
@echo "help You're reading it right now"
163+
164+
165+
.PHONY: out
166+
out:
167+
@echo "I'm sure you're nice and all, but no thanks."
168+
169+
else
170+
171+
# add_cmake_target(type, outdir, sourcedir)
172+
define add_cmake_target
173+
$(strip \
174+
$(eval name := $(lastword $(subst /, ,$(3))))
175+
$(eval target := $(1)_$(name))
176+
177+
$(eval cmakeargs := )
178+
$(if $(filter $(1),target), \
179+
$(eval cmakeargs := -DCMAKE_C_COMPILER=$(PWD)/$(GCC_LINUX_GNUEABI)gcc) \
180+
$(eval cmakeargs += -DCMAKE_CXX_COMPILER=$(PWD)/$(GCC_LINUX_GNUEABI)g++) \
181+
)
182+
183+
$(eval .PHONY: $(target))
184+
$(eval $(target):
185+
@$${call logi,Compiling $(1)/$(name) ...}
186+
@mkdir -p $(2)/$(name)
187+
@cd $(2)/$(name) && cmake $(cmakeargs) $(PWD)/$(TOPDIR)external/$(1)/$(name) && $$(MAKE)
188+
)
189+
)
190+
endef
191+
192+
# load_task(path)
193+
define load_task
194+
$(strip \
195+
$(eval include $(1))
196+
)
197+
endef
198+
199+
# create main build dir
200+
$(shell mkdir -p ${OUT})
201+
# create host build dir
202+
$(shell mkdir -p ${HOST_OUT})
203+
204+
# define host targets
205+
$(foreach p,$(wildcard $(TOPDIR)external/host/*),$(call add_cmake_target,host,$(HOST_OUT),$(p)))
206+
207+
# check if device is set
208+
ifneq ($(DEVICEID),)
209+
210+
# check if device config exists
211+
DEVICE_CONFIG = $(wildcard device/$(DEVICEID)/config.mk)
212+
ifeq ("","$(DEVICE_CONFIG)")
213+
$(call loge,device $(DEVICEID) doesn't exist)
214+
endif
215+
216+
# include device config
217+
include $(DEVICE_CONFIG)
218+
219+
# validate config
220+
ifeq ($(DEVICE_NAME),)
221+
$(call loge,DEVICE_NAME is not set)
222+
endif
223+
224+
# extract vendor and device names
225+
VENDOR := $(shell (tmp=${DEVICEID};tmp=($${tmp//\// });echo $${tmp[0]}))
226+
DEVICE := $(shell (tmp=${DEVICEID};tmp=($${tmp//\// });echo $${tmp[1]}))
227+
TARGET_OUT := $(OUT)/target/product/$(DEVICE)
228+
229+
$(call logi,Building for ${DEVICE_NAME} \(${VENDOR}/${DEVICE}\))
230+
231+
# create target build dir
232+
$(shell mkdir -p ${TARGET_OUT})
233+
234+
# define device targets
235+
$(foreach p,$(wildcard $(TOPDIR)external/target/*),$(call add_cmake_target,target,$(TARGET_OUT),$(p)))
236+
237+
# include EDK2 first
238+
include $(BUILD_SYSTEM)/tasks/edk2.mk
239+
240+
# load all other tasks
241+
$(foreach p,$(filter-out $(BUILD_SYSTEM)/tasks/edk2.mk,$(wildcard $(BUILD_SYSTEM)/tasks/*.mk)),$(call load_task,$(p)))
242+
243+
else
244+
$(call logi,Building in host-only mode)
245+
endif
246+
247+
.PHONY: clean
248+
clean: $(CLEANSTEPS)
249+
250+
.PHONY: distclean
251+
distclean: $(DISTCLEANSTEPS)
252+
rm -Rf $(OUT)
253+
254+
endif # nobuild_goals

core/root.mk

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### DO NOT EDIT THIS FILE ###
2+
include build/core/main.mk
3+
### DO NOT EDIT THIS FILE ###

core/tasks/edk2.mk

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
EDK2_DIR := $(PWD)/$(TOPDIR)/uefi/edk2
2+
EDK2_OUT := $(PWD)/$(TARGET_OUT)/edk2
3+
EDK2_ENV := GCC48_ARM_PREFIX=$(GCC_LINUX_GNUEABI) MAKEFLAGS=
4+
EDK2_BIN := $(EDK2_OUT)/Build/LittleKernelPkg/DEBUG_GCC48/FV/LITTLEKERNELPKG_EFI.fd
5+
6+
.PHONY: edk2
7+
edk2:
8+
${call logi,EDK2: compile}
9+
mkdir -p $(EDK2_OUT)
10+
$(TOPDIR)build/tools/edk2_update "$(EDK2_DIR)" "$(EDK2_OUT)" "$(PWD)/$(TOPDIR)/uefi/LittleKernelPkg"
11+
12+
MAKEFLAGS= $(MAKE) -C $(EDK2_OUT)/BaseTools
13+
cd $(EDK2_OUT) && \
14+
source edksetup.sh && \
15+
$(EDK2_ENV) build -v -n4 -a ARM -t GCC48 -p LittleKernelPkg/LittleKernelPkg.dsc
16+
17+
.PHONY: edk2_clean
18+
edk2_clean:
19+
${call logi,EDK2: clean}
20+
rm -Rf $(EDK2_OUT)/*
21+
22+
.PHONY: edk2_distclean
23+
edk2_distclean: edk2_clean
24+
25+
$(call add-clean-step,edk2_clean)
26+
$(call add-distclean-step,edk2_distclean)

core/tasks/lk.mk

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
LK_DIR := $(TOPDIR)lk/common
2+
LK_OUT := $(TARGET_OUT)/lk
3+
LK_ENV := BOOTLOADER_OUT=$(PWD)/$(LK_OUT) ARCH=arm SUBARCH=arm TOOLCHAIN_PREFIX=$(GCC_EABI) EDK2_BIN=$(EDK2_BIN)
4+
5+
ifneq ($(LK_SOURCE),)
6+
LK_DIR := $(LK_SOURCE)
7+
endif
8+
9+
# lk_check()
10+
define lk_check
11+
$(if $(LK_TARGET),, \
12+
$(eval $(call loge,LK_TARGET is not set)) \
13+
)
14+
endef
15+
16+
.PHONY: lk
17+
lk: edk2
18+
${call logi,LK: compile}
19+
mkdir -p $(LK_OUT)
20+
$(call lk_check)
21+
$(LK_ENV) $(MAKE) -C $(LK_DIR) $(LK_TARGET)
22+
23+
.PHONY: lk_clean
24+
lk_clean:
25+
${call logi,LK: clean}
26+
$(call lk_check)
27+
$(LK_ENV) $(MAKE) -C lk $(LK_TARGET) clean
28+
29+
.PHONY: lk_distclean
30+
lk_distclean:
31+
${call logi,LK: distclean}
32+
rm -Rf $(LK_OUT)/*
33+
34+
$(call add-clean-step,lk_clean)
35+
$(call add-distclean-step,lk_distclean)

tools/edk2_update

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
3+
export SOURCE="$1"
4+
export BUILD="$2"
5+
export LKPKG="$3"
6+
7+
set -e
8+
9+
GREP_EXCLUDES='.git$\|.gitignore$\|Conf$\|BaseTools$'
10+
11+
# delete old links
12+
find ${BUILD} -maxdepth 1 -type l | grep -v ${GREP_EXCLUDES} | xargs -I{} rm {}
13+
14+
# create links
15+
find ${SOURCE} -maxdepth 1 | grep -v ${GREP_EXCLUDES} | xargs -I{} sh -c 'ln -s {} ${BUILD}/$(basename {})'
16+
17+
# copy BaseTools
18+
mkdir -p ${BUILD}/BaseTools
19+
cp -Rp ${SOURCE}/BaseTools/* ${BUILD}/BaseTools/
20+
21+
# copy Conf
22+
mkdir -p ${BUILD}/Conf
23+
cp -Rp ${SOURCE}/Conf/* ${BUILD}/Conf/
24+
25+
# link LittleKernelPkg
26+
ln -s ${LKPKG} ${BUILD}/LittleKernelPkg

0 commit comments

Comments
 (0)