Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use flag files to hack dependencies #146

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
155 changes: 123 additions & 32 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ TOOLCHAIN_HOST = linux-x86
TOOLCHAIN_PATH = ./glue/gonk/prebuilt/$(TOOLCHAIN_HOST)/toolchain/arm-eabi-4.4.3/bin

GONK_PATH = $(abspath glue/gonk)
B2G_PATH := $(abspath $(PWD))

# We need adb for config-* targets. Adb is built by building system
# of gonk that needs a correct product name provided by "GONK_TARGET".
Expand All @@ -33,12 +34,16 @@ endif
FAKE_JDK_PATH ?= $(abspath $(GONK_PATH)/device/gonk-build-hack/fake-jdk-tools)

define GONK_CMD # $(call GONK_CMD,cmd)
SAVED_PATH=$$(pwd) && \
cd $(GONK_PATH) && \
. build/envsetup.sh && \
lunch $(GONK_TARGET) && \
export USE_CCACHE="yes" && \
export PATH=$$PATH:$(FAKE_JDK_PATH) && \
$(1)
export B2G_PATH=$(B2G_PATH) && \
export GECKO_OBJDIR=$(GECKO_OBJDIR) && \
$(1) && \
cd $$SAVED_PATH
endef

GECKO_PATH ?= $(abspath gecko)
Expand Down Expand Up @@ -137,15 +142,15 @@ define DEP_CHECK
endef
else # STOP_DEPENDENCY_CHECK
define DEP_CHECK
($3)
(SAVED_PATH=$$(pwd) && ($3) && cd $$SAVED_PATH && touch $1)
endef
endif # STOP_DEPENDENCY_CHECK

CCACHE ?= $(shell which ccache)
ADB := $(abspath glue/gonk/out/host/linux-x86/bin/adb)

.PHONY: build
build: gecko gecko-install-hack gonk
build: gonk

ifeq (qemu,$(KERNEL))
build: kernel bootimg-hack
Expand All @@ -154,6 +159,51 @@ endif
KERNEL_DIR = boot/kernel-android-$(KERNEL)
GECKO_OBJDIR = $(GECKO_PATH)/objdir-prof-gonk

NOOP := echo > /dev/null

# Make a flag file for changes of submodules.
#
# The flag file is touched for changes of submodules.
# This function is paired with DO_FOR_FLAG function.
# If you create a flag with name 'foo', you should define a target and rule
# as following example:
#
# $(foo_done): $(foo_chg)
# $(call DO_FOR_FLAG,foo, ... commands for foo ...)
#
# The given commands would be called for the change of foo flag.
# $(foo_done) is a file that would be touch after running all
# commands. All targets that depends on given commands should put
# $(foo_done) in its prerequisite list.
#
# $(1): flag name
# $(2): the name of the directory where to put the flag.
# $(3): the name of the directory where submodules are in.
define MAKE_CHANGE_FLAG
MAKE_CHANGE_FLAG-dummy:= $(shell mkdir -p $2; $(call DEP_CHECK,$2/.$(1)-chg,$3,$(NOOP)))
$(eval MAKE_CHANGE_FLAGS.$(1).FLAG_DIR := $2)
$(eval MAKE_CHANGE_FLAGS.$(1).SUBMODULES_DIR := $3)
$(eval $(1)_chg := $(2)/.$(1)-chg)
$(eval $(1)_done := $(2)/.$(1)-build-done)
endef

FLAGS_DIR := $(GONK_PATH)/out

$(call MAKE_CHANGE_FLAG,gecko,$(FLAGS_DIR),$(GECKO_PATH))
$(call MAKE_CHANGE_FLAG,gonk,$(FLAGS_DIR),glue/gonk)
$(call MAKE_CHANGE_FLAG,kernel,$(FLAGS_DIR),$(KERNEL_PATH))
$(call MAKE_CHANGE_FLAG,gaia,$(FLAGS_DIR),gaia)

# Do commands for the change of a flag.
#
# $(1): flag name
# $(2): commands
define DO_FOR_FLAG
(rm -f $($(1)_chg) && \
$(call DEP_CHECK,$($(1)_chg),$(MAKE_CHANGE_FLAGS.$(1).SUBMODULES_DIR),$2) && \
touch $($(1)_done))
endef

define GECKO_BUILD_CMD
export MAKE_FLAGS=$(MAKE_FLAGS) && \
export CONFIGURE_ARGS="$(GECKO_CONFIGURE_ARGS)" && \
Expand All @@ -167,24 +217,38 @@ endef
.PHONY: gecko
# XXX Hard-coded for prof-android target. It would also be nice if
# client.mk understood the |package| target.
gecko:
@$(call DEP_CHECK,$(GECKO_OBJDIR)/.b2g-build-done,$(GECKO_PATH),\
$(call GECKO_BUILD_CMD) \
)
gecko: $(gecko_done)

$(gecko_done): $(gecko_chg)
@$(call DO_FOR_FLAG,gecko, \
echo "Build Gecko ......" && \
$(call GECKO_BUILD_CMD))

$(GECKO_OBJDIR)/dist/b2g.tar.gz: $(gecko_done)
@echo "Copy $@ ......" && \
cp `ls -t $(GECKO_OBJDIR)/dist/b2g-*.tar.gz | head -n1` $@

gecko-tar: $(GECKO_OBJDIR)/dist/b2g.tar.gz

.PHONY: gonk
gonk: gaia-hack
@$(call DEP_CHECK,$(GONK_PATH)/out/.b2g-build-done,glue/gonk, \
$(call GONK_CMD,$(MAKE) $(MAKE_FLAGS) $(GONK_MAKE_FLAGS)) ; \
gonk: $(gonk_done)

$(gonk_done): $(gonk_chg) $(gaia_chg) $(gecko_chg)
@$(call DO_FOR_FLAG,gonk, \
echo "Build gonk ......" && \
$(call GONK_CMD,$(MAKE) $(MAKE_FLAGS) $(GONK_MAKE_FLAGS)) && \
$(if $(filter qemu,$(KERNEL)), \
cp $(GONK_PATH)/system/core/rootdir/init.rc.gonk \
$(GONK_PATH)/out/target/product/$(GONK)/root/init.rc))
cp $(GONK_PATH)/system/core/rootdir/init.rc.gonk \
$(GONK_PATH)/out/target/product/$(GONK)/root/init.rc, \
$(NOOP)))

.PHONY: kernel
# XXX Hard-coded for nexuss4g target
# XXX Hard-coded for gonk tool support
kernel:
@$(call DEP_CHECK,$(KERNEL_PATH)/.b2g-build-done,$(KERNEL_PATH),\
kernel: $(kernel_done)

$(kernel_done): $(kernel_chg)
@$(call DO_FOR_FLAG,kernel,\
$(if $(filter galaxy-s2,$(KERNEL)), \
PATH="$$PATH:$(abspath $(TOOLCHAIN_PATH))" \
$(MAKE) -C $(KERNEL_PATH) $(MAKE_FLAGS) ARCH=arm \
Expand All @@ -204,16 +268,21 @@ clean: clean-gecko clean-gonk clean-kernel

.PHONY: clean-gecko
clean-gecko:
rm -rf $(GECKO_OBJDIR)
@echo "Clean gecko ......"
@rm -rf $(GECKO_OBJDIR)
@rm -f $(gecko_done)

.PHONY: clean-gonk
clean-gonk:
@echo "Clean gonk ......"
@$(call GONK_CMD,$(MAKE) clean)
@rm -f $(gonk_done)

.PHONY: clean-kernel
clean-kernel:
@echo "Clean kernel ......"
@PATH="$$PATH:$(abspath $(TOOLCHAIN_PATH))" $(MAKE) -C $(KERNEL_PATH) ARCH=arm CROSS_COMPILE=arm-eabi- clean
@rm -f $(KERNEL_PATH)/.b2g-build-done
@rm -f $(kernel_done)

.PHONY: mrproper
# NB: this is a VERY DANGEROUS command that will BLOW AWAY ALL
Expand All @@ -226,16 +295,20 @@ mrproper:
git reset --hard

.PHONY: config-galaxy-s2
config-galaxy-s2: config-gecko $(ADB)
config-galaxy-s2: config-gecko $(GONK_PATH)/.galaxy-s2-extract $(ADB)
@echo "KERNEL = galaxy-s2" > .config.mk && \
echo "KERNEL_PATH = ./boot/kernel-android-galaxy-s2" >> .config.mk && \
echo "GONK = galaxys2" >> .config.mk && \
export PATH=$$PATH:$$(dirname $(ADB)) && \
cp -p config/kernel-galaxy-s2 boot/kernel-android-galaxy-s2/.config && \
cd $(GONK_PATH)/device/samsung/galaxys2/ && \
echo OK

$(GONK_PATH)/.galaxy-s2-extract: $(GONK_PATH)/device/samsung/galaxys2/extract-files.sh
@cd $(GONK_PATH)/device/samsung/galaxys2/ && \
export PATH=$$PATH:$$(dirname $(ADB)) && \
echo Extracting binary blobs from device, which should be plugged in! ... && \
./extract-files.sh && \
echo OK
touch $(GONK_PATH)/.galaxy-s2-extract
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prevent config-galaxy-s2 from downloading blobs from devices every time. It survives even after |make clean| or |make config-*|.


.PHONY: config-maguro
config-maguro: config-gecko
Expand Down Expand Up @@ -361,23 +434,41 @@ $(APP_OUT_DIR):
mkdir -p $(APP_OUT_DIR)

.PHONY: gecko-install-hack
gecko-install-hack: gecko
gecko-install-hack: $(FLAGS_DIR)/.gecko-install-hack
find $(GONK_PATH)/out -iname "*.img" | xargs rm -f
@$(call GONK_CMD,make $(MAKE_FLAGS) $(GONK_MAKE_FLAGS) systemimage-nodeps)

#
# gecko-gonk-install is called by building system of gonk to build
# gecko and to make it as a module of gonk.
#
# Check glue/gonk/vendor/mozilla/gonk/Android.mk for more information.
#
.PHONY: gecko-gonk-install
gecko-gonk-install: $(FLAGS_DIR)/.gecko-install-hack

$(FLAGS_DIR)/.gecko-install-hack: $(GECKO_OBJDIR)/dist/b2g.tar.gz
echo "Install Gecko ......"
rm -rf $(OUT_DIR)/b2g
mkdir -p $(OUT_DIR)/lib
# Extract the newest tarball in the gecko objdir.
( cd $(OUT_DIR) && \
tar xvfz `ls -t $(GECKO_OBJDIR)/dist/b2g-*.tar.gz | head -n1` )
find $(GONK_PATH)/out -iname "*.img" | xargs rm -f
@$(call GONK_CMD,make $(MAKE_FLAGS) $(GONK_MAKE_FLAGS) systemimage-nodeps)

.PHONY: gaia-hack
gaia-hack: gaia
rm -rf $(OUT_DIR)/home
mkdir -p $(OUT_DIR)/home
cp -r gaia/* $(OUT_DIR)/home
rm -rf $(OUT_DIR)/b2g/defaults/profile
mkdir -p $(OUT_DIR)/b2g/defaults
cp -r gaia/profile $(OUT_DIR)/b2g/defaults
tar xvfz $(GECKO_OBJDIR)/dist/b2g.tar.gz )
touch $@

$(gaia_done): $(gaia_chg)
@$(call DO_FOR_FLAG,gaia, \
echo "Copy gaia ......" && \
rm -rf $(OUT_DIR)/home && \
mkdir -p $(OUT_DIR)/home && \
cp -r gaia/* $(OUT_DIR)/home && \
rm -rf $(OUT_DIR)/b2g/defaults/profile && \
mkdir -p $(OUT_DIR)/b2g/defaults && \
cp -r gaia/profile $(OUT_DIR)/b2g/defaults)

# Called by gaia-gonk module in glue/gonk/vendor/mozilla/gonk/Android.mk.
.PHONY: gaia-gonk-install
gaia-gonk-install: $(gaia_done)

.PHONY: install-gecko
install-gecko: gecko-install-hack $(ADB)
Expand Down
7 changes: 5 additions & 2 deletions glue/gonk/device/gonk-build-hack/AndroidProducts.mk
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ BUILD_DROIDDOC:= $(GONK_BUILD_HACK)/droiddoc-noop.mk
# invoke a java tool to check API version. We delete it to prevent
# from being loaded.
$(shell rm -f $(TOPDIR)build/core/tasks/apicheck.mk || exit 1)
$(shell cp $(TOPDIR)device/gonk-build-hack/apicheck.mk-remove-warning.txt \
$(TOPDIR)build/core/tasks/apicheck.mk.removed)
$(shell \
if [ ! -e $(TOPDIR)build/core/tasks/apicheck.mk.removed ]; then \
cp $(TOPDIR)device/gonk-build-hack/apicheck.mk-remove-warning.txt \
$(TOPDIR)build/core/tasks/apicheck.mk.removed; \
fi)

# Build system would build OTA-key for recovery image. It requires a
# tool wrote in java. This variable can stop it.
Expand Down
14 changes: 14 additions & 0 deletions glue/gonk/frameworks/policies/base/PolicyConfig.mk
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,17 @@ $(foreach p, $(ALL_PRODUCTS), \
$(eval PRODUCTS.$(p).PRODUCT_PACKAGES := \
$(filter-out $(REMOVE_MODULES), \
$(PRODUCTS.$(p).PRODUCT_PACKAGES))))

# This variable make systemimage depending on gecko-gonk module defined
# in glue/gonk/vendor/mozilla/gonk/Android.mk. Without this variable,
# system image would not be rebuilt for changes of Gecko.
#
# See definitions in glue/gonk/build/core/main.mk for
# - Default_MODULES, and
# - modules_to_install.
#
# See definitions in glue/gonk/build/core/Makefile for
# - ALL_DEFAULT_INSTALLED_MODULES passed from glue/gonk/build/core/main.mk,
# - requiste list of "systemimage" target.
#
ALL_DEFAULT_INSTALLED_MODULES += gecko-gonk gaia-gonk
40 changes: 40 additions & 0 deletions glue/gonk/vendor/mozilla/gonk/Android.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
############################################################
# Integrate Gecko to the building process of gonk.
############################################################
LOCAL_PATH:= $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := gecko-gonk
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT)/b2g
LOCAL_MODULE_TAGS := optional

#######################################
include $(BUILD_SYSTEM)/base_rules.mk
#######################################

$(LOCAL_BUILT_MODULE): libc libstdc++ libm libdl libthread_db
$(LOCAL_BUILT_MODULE): $(OUT_DIR)/.gecko-chg
$(hide) $(MAKE) -C $(B2G_PATH) gecko-gonk-install && \
mkdir -p $$(dirname $@) && \
touch $@

############################################################
# Integrate Gaia to the building process of gonk.
############################################################
include $(CLEAR_VARS)

LOCAL_MODULE := gaia-gonk
LOCAL_MODULE_CLASS := EXECUTABLES
LOCAL_MODULE_PATH := $(TARGET_OUT)/home
LOCAL_MODULE_TAGS := optional

#######################################
include $(BUILD_SYSTEM)/base_rules.mk
#######################################

$(LOCAL_BUILT_MODULE): $(OUT_DIR)/.gaia-chg
$(hide) $(MAKE) -C $(B2G_PATH) gaia-gonk-install && \
mkdir -p $$(dirname $@) && \
touch $@