1# Makefile for Rockchip Linux SDK 2# 3# Based on buildroot-2022.08's Makefile 4# 5# Copyright (C) 1999-2005 by Erik Andersen <andersen@codepoet.org> 6# Copyright (C) 2006-2014 by the Buildroot developers <buildroot@uclibc.org> 7# Copyright (C) 2014-2020 by the Buildroot developers <buildroot@buildroot.org> 8# Copyright (C) 2022 by Jeffy Chen <jeffy.chen@rock-chips.com> 9# 10# This program is free software; you can redistribute it and/or modify 11# it under the terms of the GNU General Public License as published by 12# the Free Software Foundation; either version 2 of the License, or 13# (at your option) any later version. 14# 15# This program is distributed in the hope that it will be useful, 16# but WITHOUT ANY WARRANTY; without even the implied warranty of 17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 18# General Public License for more details. 19# 20# You should have received a copy of the GNU General Public License 21# along with this program; if not, write to the Free Software 22# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 23# 24 25#-------------------------------------------------------------- 26# Just run 'make menuconfig', configure stuff, then run 'make'. 27# You shouldn't need to mess with anything beyond this point... 28#-------------------------------------------------------------- 29 30# Delete default rules. We don't use them. This saves a bit of time. 31.SUFFIXES: 32 33# we want bash as shell 34SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \ 35 else if [ -x /bin/bash ]; then echo /bin/bash; \ 36 else echo sh; fi; fi) 37 38# Strip quotes and then whitespaces 39qstrip = $(strip $(subst ",,$(1))) 40#")) 41 42# Needed for the foreach loops to loop over the list of hooks, so that 43# each hook call is properly separated by a newline. 44define sep 45 46 47endef 48 49# absolute path 50COMMON_DIR := $(abspath $(dir $(realpath $(lastword $(MAKEFILE_LIST))))) 51DEVICE_DIR := $(abspath $(COMMON_DIR)/..) 52SDK_DIR := $(abspath $(DEVICE_DIR)/../..) 53CHIP_DIR := $(DEVICE_DIR)/.chip 54CONFIG_DIR := $(COMMON_DIR)/configs 55CONFIG_CONFIG_IN = Config.in 56CONFIG = $(SDK_DIR)/buildroot/support/kconfig 57OUTDIR := $(SDK_DIR)/output 58BUILD_DIR := $(OUTDIR)/kconf 59SCRIPT_TARGETS := $(shell $(SDK_DIR)/build.sh make-targets) 60 61RK_CONFIG = $(OUTDIR)/.config 62 63# To put more focus on warnings, be less verbose as default 64# Use 'make V=1' to see the full commands 65ifeq ("$(origin V)", "command line") 66 KBUILD_VERBOSE = $(V) 67endif 68ifndef KBUILD_VERBOSE 69 KBUILD_VERBOSE = 0 70endif 71 72ifeq ($(KBUILD_VERBOSE),1) 73 Q = 74ifndef VERBOSE 75 VERBOSE = 1 76endif 77export VERBOSE 78else 79 Q = @ 80endif 81 82# Default to build script's default target 83.PHONY: build 84build: 85 $(Q)$(SDK_DIR)/build.sh 86 87# kconfig uses CONFIG_SHELL 88CONFIG_SHELL := $(SHELL) 89 90export SHELL CONFIG_SHELL Q KBUILD_VERBOSE 91 92HOSTCC := gcc 93HOSTCXX := g++ 94 95export HOSTCC HOSTCXX 96 97# silent mode requested? 98QUIET := $(if $(findstring s,$(filter-out --%,$(MAKEFLAGS))),-q) 99 100$(BUILD_DIR)/auto.conf: $(RK_CONFIG) 101 make -j1 $(EXTRAMAKEARGS) HOSTCC="$(HOSTCC)" HOSTCXX="$(HOSTCXX)" syncconfig 102 103$(BUILD_DIR)/%onf: 104 mkdir -p $(@D)/lxdialog 105 make CC="$(HOSTCC)" HOSTCC="$(HOSTCC)" \ 106 obj=$(@D) -C $(CONFIG) -f Makefile.br $(@F) 107 108TARGET_DEFCONFIG := $(filter %_defconfig,$(MAKECMDGOALS)) 109ifneq ($(TARGET_DEFCONFIG),) 110RK_DEFCONFIG := $(realpath $(CHIP_DIR)/$(TARGET_DEFCONFIG)) 111else 112RK_DEFCONFIG := $(shell [ -e ${RK_CONFIG} ] && \ 113 grep RK_DEFCONFIG ${RK_CONFIG} | cut -d'=' -f2) 114endif 115DEFCONFIG := $(call qstrip,$(RK_DEFCONFIG)) 116DEFCONFIG_NAME := $(notdir $(DEFCONFIG)) 117 118# Setup some default values 119RK_CHIP_FAMILY := $(notdir $(realpath $(CHIP_DIR))) 120RK_CHIP := $(shell echo ${DEFCONFIG_NAME} | \ 121 cut -d'_' -f2 | grep -E "^(px|rk|rv)") 122 123COMMON_CONFIG_ENV = \ 124 RK_DEFCONFIG='$(call qstrip,$(RK_DEFCONFIG))' \ 125 RK_CHIP_FAMILY='$(call qstrip,$(RK_CHIP_FAMILY))' \ 126 RK_CHIP='$(call qstrip,$(RK_CHIP))' \ 127 KCONFIG_AUTOCONFIG=$(BUILD_DIR)/auto.conf \ 128 KCONFIG_AUTOHEADER=$(BUILD_DIR)/autoconf.h \ 129 KCONFIG_TRISTATE=$(BUILD_DIR)/tristate.config \ 130 srctree=$(CONFIG_DIR) BR2_CONFIG=$(RK_CONFIG) 131 132menuconfig: $(BUILD_DIR)/mconf 133 $(Q)$(COMMON_CONFIG_ENV) $< $(CONFIG_CONFIG_IN) 134 135.PHONY: menuconfig 136 137oldconfig syncconfig olddefconfig: $(BUILD_DIR)/conf 138 $(Q)$(COMMON_CONFIG_ENV) $< --$@ $(CONFIG_CONFIG_IN) 139 140.PHONY: oldconfig syncconfig olddefconfig 141 142%_defconfig: $(BUILD_DIR)/conf $(CHIP_DIR)/%_defconfig 143 $(Q)$(COMMON_CONFIG_ENV) $< --defconfig=$(CHIP_DIR)/$@ $(CONFIG_CONFIG_IN) 144 145.PHONY: %_defconfig 146 147savedefconfig: $(BUILD_DIR)/conf 148 $(Q)$(COMMON_CONFIG_ENV) $< \ 149 --savedefconfig=$(if $(DEFCONFIG),$(DEFCONFIG),$(CHIP_DIR)/defconfig) \ 150 $(CONFIG_CONFIG_IN) 151 $(Q)sed '/^RK_DEFCONFIG=/d' $(if $(DEFCONFIG),$(DEFCONFIG),$(CHIP_DIR)/defconfig) 152 153.PHONY: savedefconfig 154 155.PHONY: help 156help: 157 @echo ' menuconfig - interactive curses-based configurator' 158 @echo ' oldconfig - resolve any unresolved symbols in .config' 159 @echo ' syncconfig - Same as oldconfig, but quietly, additionally update deps' 160 @echo ' olddefconfig - Same as syncconfig but sets new symbols to their default value' 161 @echo ' savedefconfig - Save current config to RK_DEFCONFIG (minimal config)' 162 @echo ' clean - Cleanup' 163 @echo 164 @echo 'from build.sh:' 165 @$(SDK_DIR)/build.sh make-usage 166 167define script_target 168$(1): 169 $(Q)$(SDK_DIR)/build.sh $$@ 170endef 171$(eval $(foreach t,$(SCRIPT_TARGETS),$(call script_target,$(t))$(sep))) 172 173.PHONY: $(SCRIPT_TARGETS) 174 175.PHONY: clean 176clean: 177ifeq ($(RK_SESSION),) 178 $(Q)$(SDK_DIR)/build.sh cleanall 179endif 180 181.PHONY: distclean 182distclean: clean 183 $(Q)rm -rf $(BUILD_DIR) $(RK_CONFIG)* 184