blob: 9cb06a5e924e920470644d07a3e8430a8487f3c0 [file] [log] [blame]
kelvin.zhangac22e652021-10-18 15:09:21 +08001#!/bin/bash
yang.li09520922022-01-12 15:51:51 +08002#
yang.liffa60e52022-01-11 14:38:56 +08003# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
yang.li09520922022-01-12 15:51:51 +08004#
yang.liffa60e52022-01-11 14:38:56 +08005# SPDX-License-Identifier: MIT
yang.li09520922022-01-12 15:51:51 +08006#
yang.liffa60e52022-01-11 14:38:56 +08007
kelvin.zhangf91d7b02021-10-26 16:47:17 +08008###############################################################
9# Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml.
10###############################################################
kelvin.zhangac22e652021-10-18 15:09:21 +080011
kelvin.zhangf91d7b02021-10-26 16:47:17 +080012cmake_file="$PWD/CMakeLists.txt"
13kconfig_file="$PWD/Kconfig"
Kelvin Zhang9a382242022-04-11 18:46:32 +080014build_dir="build_system"
15exclude_dirs="boot products docs"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080016special_dirs="arch soc boards"
Kelvin Zhangce29a712022-06-09 17:25:22 +080017toolchain_dir="arch/$ARCH/toolchain"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080018
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080019DEFAULT_RTOS_SDK_MANIFEST="$PWD/products/$PRODUCT/rtos_sdk_manifest.xml"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080020RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +080021RTOS_SDK_MANIFEST_OLD_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest_old.xml"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080022STAMP="$kernel_BUILD_DIR/.stamp"
23
Kelvin Zhang5374de92022-01-14 10:35:43 +080024[ -n "$1" ] && BUILD_DIR=$1;
25RTOS_SDK_VERSION_FILE="$BUILD_DIR/sdk_ver.h"
26
Xueling Li255a6c12022-09-06 09:51:45 +080027# Check whether the project is a valid repo
28repo manifest 2>&1 | grep -q $build_dir
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080029if [ "$?" -ne 0 ]; then
30 echo "Non-repo source code"
31 if [ -f $DEFAULT_RTOS_SDK_MANIFEST ]; then
32 echo "Use default manifest: $DEFAULT_RTOS_SDK_MANIFEST"
33 cp -f $DEFAULT_RTOS_SDK_MANIFEST $RTOS_SDK_MANIFEST_FILE
34 else
35 echo "Default manifest.xml not found!"
36 exit 0
37 fi
38else
39 echo "Generate manifest.xml"
40 repo manifest > $RTOS_SDK_MANIFEST_FILE
41 if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
42 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
43 exit 1
44 fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080045fi
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080046
Kelvin Zhange2e04712022-02-09 17:39:35 +080047# Get SDK_VERSION
xiaohu.huangf4577f72022-11-08 17:56:02 +080048source scripts/gen_version.sh $RTOS_SDK_VERSION_FILE \
49 $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhange2e04712022-02-09 17:39:35 +080050
51if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
52 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
53 if [ -z "$is_update" ]; then
54 exit 0
55 else
56 echo "Update top Kconfig and CMakelists.txt."
57 fi
58fi
59
60# Back up manifest.xml
61cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhang5374de92022-01-14 10:35:43 +080062
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080063if [[ "$PRODUCT" == aocpu ]]; then
64 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
65else
66 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
67fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080068
Kelvin Zhang33a3a872021-12-09 15:29:20 +080069# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080070cat <<EOF > $cmake_file
71enable_language(C CXX ASM)
72
kelvin.zhangac22e652021-10-18 15:09:21 +080073EOF
74
Kelvin Zhang33a3a872021-12-09 15:29:20 +080075# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080076cat <<EOF > $kconfig_file
77EOF
78
Kelvin Zhangce29a712022-06-09 17:25:22 +080079# Write the toolchain options to Kconfig
80if [ -f $toolchain_dir/Kconfig ]; then
81 category=`basename $toolchain_dir`
82 toolchain_kconfig_path="arch/\${ARCH}/toolchain"
83 echo "menu \"${category^} Options\"" > $kconfig_file
84 echo "source \"$toolchain_kconfig_path/Kconfig\"" >> $kconfig_file
85 echo -e "endmenu\n" >> $kconfig_file
86fi
87
kelvin.zhang83a4aa32022-04-08 15:48:35 +080088# Figure out the $relative_dir and its column
Kelvin Zhangecaacb32022-05-09 10:10:56 +080089[ -z "$REPO_DIR" ] && REPO_DIR=$PWD
Kelvin Zhang33a3a872021-12-09 15:29:20 +080090pattern="path="
91i=0
Kelvin Zhang9a382242022-04-11 18:46:32 +080092keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080093for keyword in $keyline; do
94 let i++
95 if [[ $keyword == $pattern* ]]; then
96 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
97 relative_dir=`dirname $repo_path`
kelvin.zhang83a4aa32022-04-08 15:48:35 +080098 # Filter current project
Kelvin Zhangecaacb32022-05-09 10:10:56 +080099 if [[ $REPO_DIR == *$relative_dir ]]; then
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800100 break
101 fi
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800102 fi
103done
104
105if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800106 pattern="path="
107else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800108 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800109fi
110
Kelvin Zhange2e04712022-02-09 17:39:35 +0800111# Sort manifest.xml of RTOS SDK
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800112sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
113
kelvin.zhangac22e652021-10-18 15:09:21 +0800114while IFS= read -r line
115do
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800116 keyline=`echo "$line" | grep "$pattern"`
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800117 [ -z "$keyline" ] && continue
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800118
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800119 for keyword in $keyline; do
120 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800121 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800122
Kelvin Zhang22cb55e2022-06-08 20:21:00 +0800123 if [[ $repo_path == drivers* ]] || [[ $repo_path == benchmark* ]]; then
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800124 category=`basename $repo_path | sed 's/_/ /g'`
125 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800126 else
127 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800128 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800129
Kelvin Zhang9a382242022-04-11 18:46:32 +0800130 # exclude some dirs
131 skip_flag=0
132 for exclude_dir in $exclude_dirs; do
133 if [[ $repo_path == $exclude_dir* ]]; then
134 skip_flag=1
135 break
136 fi
137 done
138 [ "$skip_flag" -eq 1 ] && continue
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800139
Kelvin Zhangaed13162022-01-11 16:31:13 +0800140 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800141 case $special_dirs in
142 *"$category"*) arch=`basename $repo_path`
143 if [ "$arch" == "$ARCH" ]; then
144 cmake_path="$category/\${ARCH}"
Kelvin Zhangce736e62022-03-02 14:17:40 +0800145 kconfig_path="$category/\${ARCH}"
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800146 else
147 continue
148 fi;;
149 * ) cmake_path=$repo_path
150 kconfig_path=$repo_path;;
151 esac
152
153 # Generate root CMakeLists.txt
154 if [ -f $repo_path/CMakeLists.txt ]; then
155 echo "add_subdirectory($cmake_path)" >> $cmake_file
156 fi
157
158 # Generate root Kconfig
159 if [ -f $repo_path/Kconfig ]; then
160 if [ "$last_category" != "$category" ]; then
161 if [ -n "$last_category" ]; then
162 echo -e "endmenu\n" >> $kconfig_file
163 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800164
Kelvin Zhangce29a712022-06-09 17:25:22 +0800165 if [ "$category" == "wcn" -o "$category" == "soc" ]; then
Kelvin Zhang24939422022-01-06 13:52:10 +0800166 echo "menu \"${category^^} Options\"" >> $kconfig_file
167 else
168 echo "menu \"${category^} Options\"" >> $kconfig_file
169 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800170 fi
171
172 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
173 last_category=$category
174 fi
175 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800176 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800177 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800178done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800179
180echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800181
Kelvin Zhang55457002021-12-29 14:26:17 +0800182sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800183touch $STAMP