Buildsystemmk

Download as pdf or txt
Download as pdf or txt
You are on page 1of 42

BuildSystem.

mk
SPEAKERS

Rémy Gottschalk Charles-Henry Prunier

● SoftAtHome : 3 years - ● Archos : 3 years - ROM


Linux System for HGW cooking for Archos
and STB devices (Archos 5 IT -
GEN 10)
● Genymobile : 2 years - ● Genymobile : 2 years -
ROM cooking ROM cooking
AGENDA

01 02 03 04
How to make Device Android.mk One last bite
definition
HOW TO MAKE
source, lunch, make !
HOW TO MAKE

# source ./build/envsetup.sh
#
# head -n 15 build/envsetup.sh
function hmm() {
cat <<EOF
Invoke ". build/envsetup.sh" from your shell to add the following functions to your
environment:
- lunch: lunch <product_name>-<build_variant>
- tapas: tapas [<App1> <App2> ...] [arm|x86|mips|armv5] [eng|userdebug|user]
- croot: Changes directory to the top of the tree.
- m: Makes from the top of the tree.
- mm: Builds all of the modules in the current directory, but not their
dependencies.
- mmm: Builds all of the modules in the supplied directories, but not their
dependencies.
- mma: Builds all of the modules in the current directory, and their
dependencies.
- mmma: Builds all of the modules in the supplied directories, and their
dependencies.
- cgrep: Greps on all local C/C++ files.
- jgrep: Greps on all local Java files.
- resgrep: Greps on all local res/*.xml files.
- godir: Go to the directory containing a file.
#
HOW TO MAKE
lunch
HOW TO MAKE
make

make -j42

It’s coffee time !


DEVICE DEFINITION
What’s my target ?
DEVICE DEFINITION
vendorsetup.sh, AndroidProduct.mk

vendorsetup.sh
add_lunch_combo TARGETNAME-TYPE
Lunch entry point

TYPE = eng | userdebug | release

PRODUCT_MAKEFILES = TARGETNAME.mk AndroidProducts.mk


The first makefile
DEVICE DEFINITION
vendorsetup.sh, AndroidProduct.mk

# tail -n1 device/lge/hammerhead/vendorsetup.sh


add_lunch_combo aosp_hammerhead-userdebug
#
# tail -n3 device/lge/hammerhead/AndroidProducts.mk
PRODUCT_MAKEFILES := \
$(LOCAL_DIR)/aosp_hammerhead.mk \
$(LOCAL_DIR)/full_hammerhead.mk
DEVICE DEFINITION
BoardConfig.mk

BoardConfig.mk

A bunch of
Define your Can include other
specific
device hardware BoardConfig.mk
defines
DEVICE DEFINITION
BoardConfig.mk

# cat device/lge/hammerhead/BoardConfig.mk | grep -vP "(^$|^#.*$)"


TARGET_CPU_ABI := armeabi-v7a
TARGET_CPU_ABI2 := armeabi
TARGET_CPU_SMP := true
TARGET_ARCH := arm
TARGET_ARCH_VARIANT := armv7-a-neon
TARGET_CPU_VARIANT := krait
TARGET_NO_BOOTLOADER := true
BOARD_KERNEL_BASE := 0x00000000
BOARD_KERNEL_PAGESIZE := 2048
BOARD_KERNEL_CMDLINE := console=ttyHSL0,115200,n8 androidboot.hardware=hammerhead
user_debug=31 maxcpus=2 msm_watchdog_v2.enable=1
BOARD_MKBOOTIMG_ARGS := --ramdisk_offset 0x02900000 --tags_offset 0x02700000
MAX_EGL_CACHE_KEY_SIZE := 12*1024
MAX_EGL_CACHE_SIZE := 2048*1024
BOARD_USES_ALSA_AUDIO := true
BOARD_HAVE_BLUETOOTH := true
BOARD_HAVE_BLUETOOTH_BCM := true
BOARD_BLUETOOTH_BDROID_BUILDCFG_INCLUDE_DIR := device/lge/hammerhead/bluetooth
WPA_SUPPLICANT_VERSION := VER_0_8_X
BOARD_WLAN_DEVICE := bcmdhd
BOARD_WPA_SUPPLICANT_DRIVER := NL80211
BOARD_WPA_SUPPLICANT_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
BOARD_HOSTAPD_DRIVER := NL80211
BOARD_HOSTAPD_PRIVATE_LIB := lib_driver_cmd_$(BOARD_WLAN_DEVICE)
WIFI_DRIVER_FW_PATH_PARAM := "/sys/module/bcmdhd/parameters/firmware_path"
DEVICE DEFINITION
BoardConfig.mk

WIFI_DRIVER_FW_PATH_AP := "/vendor/firmware/fw_bcmdhd_apsta.bin"
WIFI_DRIVER_FW_PATH_STA := "/vendor/firmware/fw_bcmdhd.bin"
BOARD_USES_SECURE_SERVICES := true
TARGET_NO_RADIOIMAGE := true
TARGET_BOARD_PLATFORM := msm8974
TARGET_BOOTLOADER_BOARD_NAME := hammerhead
TARGET_BOARD_INFO_FILE := device/lge/hammerhead/board-info.txt
BOARD_VENDOR_QCOM_GPS_LOC_API_HARDWARE := $(TARGET_BOARD_PLATFORM)
TARGET_NO_RPC := true
BOARD_EGL_CFG := device/lge/hammerhead/egl.cfg
USE_OPENGL_RENDERER := true
VSYNC_EVENT_PHASE_OFFSET_NS := 7500000
SF_VSYNC_EVENT_PHASE_OFFSET_NS := 5000000
TARGET_USES_ION := true
TARGET_USERIMAGES_USE_EXT4 := true
BOARD_BOOTIMAGE_PARTITION_SIZE := 23068672
BOARD_RECOVERYIMAGE_PARTITION_SIZE := 23068672
BOARD_SYSTEMIMAGE_PARTITION_SIZE := 1073741824
BOARD_USERDATAIMAGE_PARTITION_SIZE := 13725837312
BOARD_CACHEIMAGE_PARTITION_SIZE := 734003200
BOARD_CACHEIMAGE_FILE_SYSTEM_TYPE := ext4
BOARD_FLASH_BLOCK_SIZE := 131072
BOARD_CHARGER_DISABLE_INIT_BLANK := true
BOARD_CHARGER_ENABLE_SUSPEND := true
TARGET_RECOVERY_PIXEL_FORMAT := RGBX_8888
TARGET_RECOVERY_UI_LIB := librecovery_ui_hammerhead
DEVICE DEFINITION
BoardConfig.mk

TARGET_RECOVERY_FSTAB = device/lge/hammerhead/fstab.hammerhead
TARGET_RELEASETOOLS_EXTENSIONS := device/lge/hammerhead
PDK_PLATFORM_ZIP_PRODUCT_BINARIES := device/lge/hammerhead-kernel/vmlinux.bz2
BOARD_HAL_STATIC_LIBRARIES := libdumpstate.hammerhead
BOARD_SEPOLICY_DIRS := \
device/lge/hammerhead/sepolicy
BOARD_SEPOLICY_UNION := \
device.te \
app.te \
file_contexts
HAVE_ADRENO_SOURCE:= false
OVERRIDE_RS_DRIVER:= libRSDriver_adreno.so
TARGET_FORCE_HWC_FOR_VIRTUAL_DISPLAYS := true
TARGET_TOUCHBOOST_FREQUENCY:= 1200
-include vendor/lge/hammerhead/BoardConfigVendor.mk
DEVICE DEFINITION
device.mk

device.mk

Define your No specific Heavy use of


device software naming inheritance
DEVICE DEFINITION
device.mk

INHERIT BASE DEVICE


INHERIT OVERLAY
INHERIT VENDOR STUFF
INHERIT PRODUCT VARIATION
DEVICE DEFINITION
device.mk

Name your device


PRODUCT_NAME
PRODUCT_MODEL
PRODUCT_DEVICE
PRODUCT_MANUFACTURER
PRODUCT_BRAND
DEVICE DEFINITION
device.mk

Include software
PRODUCT_PACKAGES
PRODUCT_PACKAGES_DEBUG
PRODUCT_PACKAGES_ENG
PRODUCT_PACKAGES_TESTS
PRODUCT_COPY_FILES
DEVICE DEFINITION
device.mk

Customize
PRODUCT_PROPERTY_OVERRIDES
PRODUCT_DEFAULT_PROPERTY_OVERRIDES
PRODUCT_RESTRICT_VENDOR_FILES
PRODUCT_PACKAGE_OVERLAYS
DEVICE_PACKAGE_OVERLAYS
DEVICE DEFINITION
device.mk

Some leftovers
PRODUCT_AAPT_CONFIG
PRODUCT_AAPT_PREF_CONFIG
PRODUCT_OTA_PUBLIC_KEYS
PRODUCT_EXTRA_RECOVERY_KEYS
PRODUCT_DEFAULT_DEV_CERTIFICATE
And more in build/core/product.mk
DEVICE DEFINITION
device.mk

# cat device/lge/hammerhead/device.mk | magic_summarize


LOCAL_KERNEL := $(TARGET_PREBUILT_KERNEL)
PRODUCT_COPY_FILES := \
$(LOCAL_KERNEL):kernel
PRODUCT_COPY_FILES += \
device/lge/hammerhead/init.hammerhead.rc:root/init.hammerhead.rc \
device/lge/hammerhead/fstab.hammerhead:root/fstab.hammerhead \
device/lge/hammerhead/ueventd.hammerhead.rc:root/ueventd.hammerhead.rc
# Input device files for hammerhead
PRODUCT_COPY_FILES += \
device/lge/hammerhead/gpio-keys.kl:system/usr/keylayout/gpio-keys.kl \
device/lge/hammerhead/gpio-keys.kcm:system/usr/keychars/gpio-keys.kcm \
[...] device/lge/hammerhead/thermal-engine-hammerhead.conf:system/etc/thermal-
engine.conf
PRODUCT_TAGS += dalvik.gc.type-precise
# This device is xhdpi. However the platform doesn't
# currently contain all of the bitmaps at xhdpi density so
# we do this little trick to fall back to the hdpi version
# if the xhdpi doesn't exist.
PRODUCT_AAPT_CONFIG := normal hdpi xhdpi xxhdpi
PRODUCT_AAPT_PREF_CONFIG := xxhdpi
PRODUCT_CHARACTERISTICS := nosdcard
DEVICE_PACKAGE_OVERLAYS := \
device/lge/hammerhead/overlay
DEVICE DEFINITION
device.mk

PRODUCT_PACKAGES += \
gralloc.msm8974 \
libgenlock \
hwcomposer.msm8974 \
[...]
flp.msm8974
PRODUCT_PROPERTY_OVERRIDES += \
ro.hwui.texture_cache_size=72 \
debug.qualcomm.sns.hal=w \
debug.qualcomm.sns.daemon=w \
[...]
debug.qualcomm.sns.libsensor1=w
PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
rild.libpath=/system/lib/libril-qc-qmi-1.so
# Camera configuration
PRODUCT_DEFAULT_PROPERTY_OVERRIDES += \
camera.disable_zsl_mode=1
# Input resampling configuration
PRODUCT_PROPERTY_OVERRIDES += \
ro.input.noresample=1
# setup dalvik vm configs.
$(call inherit-product, frameworks/native/build/phone-xhdpi-2048-dalvik-heap.mk)
$(call inherit-product-if-exists, hardware/qcom/msm8x74/msm8x74.mk)
$(call inherit-product-if-exists, vendor/qcom/gpu/msm8x74/msm8x74-gpu-vendor.mk)
$(call inherit-product-if-exists,
hardware/broadcom/wlan/bcmdhd/firmware/bcm4339/device-bcm.mk)
Android.mk
A piece of Android
Android.mk
Android.mk, Android.mk everywhere

Android.mk, Android.mk everywhere


Define a component

# find ./ -name Android.mk | wc -l


2242
Android.mk
Common content

Any component needs


A working directory
LOCAL_PATH := $(call my-dir)
A clean environment
include $(CLEAR_VARS)
A name
LOCAL_MODULE := mymodule
LOCAL_PACKAGE_NAME := mypackage
Android.mk
Common content

Any component needs


A type
include BUILD_something
Usually, some source files
LOCAL_SRC_FILES= files
A tag
LOCAL_MODULE_TAGS := tag
Android.mk
Component types

Many types of components


# cat build/core/config.mk
[...]
BUILD_HOST_STATIC_LIBRARY:= $(BUILD_SYSTEM)/host_static_library.mk
BUILD_HOST_SHARED_LIBRARY:= $(BUILD_SYSTEM)/host_shared_library.mk
BUILD_STATIC_LIBRARY:= $(BUILD_SYSTEM)/static_library.mk
BUILD_RAW_STATIC_LIBRARY := $(BUILD_SYSTEM)/raw_static_library.mk
BUILD_SHARED_LIBRARY:= $(BUILD_SYSTEM)/shared_library.mk
BUILD_EXECUTABLE:= $(BUILD_SYSTEM)/executable.mk
BUILD_RAW_EXECUTABLE:= $(BUILD_SYSTEM)/raw_executable.mk
BUILD_HOST_EXECUTABLE:= $(BUILD_SYSTEM)/host_executable.mk
BUILD_PACKAGE:= $(BUILD_SYSTEM)/package.mk
BUILD_PHONY_PACKAGE:= $(BUILD_SYSTEM)/phony_package.mk
BUILD_HOST_PREBUILT:= $(BUILD_SYSTEM)/host_prebuilt.mk
BUILD_PREBUILT:= $(BUILD_SYSTEM)/prebuilt.mk
BUILD_MULTI_PREBUILT:= $(BUILD_SYSTEM)/multi_prebuilt.mk
BUILD_JAVA_LIBRARY:= $(BUILD_SYSTEM)/java_library.mk
BUILD_STATIC_JAVA_LIBRARY:= $(BUILD_SYSTEM)/static_java_library.mk
BUILD_HOST_JAVA_LIBRARY:= $(BUILD_SYSTEM)/host_java_library.mk
BUILD_DROIDDOC:= $(BUILD_SYSTEM)/droiddoc.mk
BUILD_COPY_HEADERS := $(BUILD_SYSTEM)/copy_headers.mk
BUILD_NATIVE_TEST := $(BUILD_SYSTEM)/native_test.mk
BUILD_HOST_NATIVE_TEST := $(BUILD_SYSTEM)/host_native_test.mk
BUILD_NOTICE_FILE := $(BUILD_SYSTEM)/notice_files.mk
[...]
Android.mk
Keywords (linking)

Some useful keywords


For linking
LOCAL_SHARED_LIBRARY
LOCAL_STATIC_LIBRARY
LOCAL_JAVA_LIBRARY
LOCAL_STATIC_JAVA_LIBRARY
Android.mk
Keywords (signing)

Some useful keywords


For signing
LOCAL_CERTIFICATE
LOCAL_PRIVILEGED_MODULE
Android.mk
Keywords (native)

Some useful keywords


For native code
LOCAL_CFLAGS
LOCAL_CPPFLAGS
Android.mk
Keywords (java)

Some useful keywords


For java stuff
LOCAL_PROGUARD_FLAG_FILES
LOCAL_PROGUARD_ENABLED
LOCAL_AAPT_FLAGS
Android.mk
Keywords (dependency)

Some useful keywords


For dependency handling
LOCAL_REQUIRED_MODULES
LOCAL_PACKAGE_OVERRIDES
Android.mk
Keywords (full list)

Some useful keywords


And even more
Full list in build/core/clear_vars.mk
Android.mk
Functions

Many useful functions


in build/core/definitions.mk
all-java-files-under
all-files-under
all-makefiles-under
and many more
Android.mk
packages/apps/Settings/Android.mk

# cat packages/apps/Settings/Android.mk
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_JAVA_LIBRARIES := bouncycastle conscrypt telephony-common


LOCAL_STATIC_JAVA_LIBRARIES := android-support-v4 android-support-v13 jsr305

LOCAL_MODULE_TAGS := optional

LOCAL_SRC_FILES := \
$(call all-java-files-under, src) \
src/com/android/settings/EventLogTags.logtags

LOCAL_PACKAGE_NAME := Settings
LOCAL_CERTIFICATE := platform
LOCAL_PRIVILEGED_MODULE := true

LOCAL_PROGUARD_FLAG_FILES := proguard.flags

LOCAL_AAPT_FLAGS += -c zz_ZZ

include $(BUILD_PACKAGE)

# Use the folloing include to make our test apk.


include $(call all-makefiles-under,$(LOCAL_PATH))
One last bite
There’s always more
One last bite
More makefiles

More makefiles
untold module makefiles
CleanSpec.mk
Application.mk
One last bite
Even more makefiles

Even more makefiles


The build system itself
build/core/main.mk
build/core/*.mk

Base devices
build/target/**
One last bite
Other tools

Non-make stuff
Python
build/tool/releasetools/
├── build_image.py
├── img_from_target_files
└── ota_from_target_files
One last bite
Other tools

Non-make stuff
Java
build/tools/signapk
Thank You for your time !
If you have any question ?

Charles-Henry Prunier Rémy Gottschalk

0682079415
[email protected]
[email protected]
@charly_prunier
Copyrights

The following copyright have been stripped


from all the examples :

#
# Copyright (C) 2013 The Android Open-Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

You might also like