blob: e271cf76b5b4642d3095c92716ccf2247950388d [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 Zhang25ccae72021-12-07 16:42:12 +080017
bin.chen009b21e2024-04-30 15:38:32 +080018SOC_MANIFEST="$PWD/soc/$ARCH/$SOC/rtos_sdk_manifest.xml"
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"
Kelvin Zhang11a72382024-05-13 14:10:58 +080023RTOS_SDK_VERSION_FILE="$kernel_BUILD_DIR/sdk_ver.h"
Kelvin Zhang5374de92022-01-14 10:35:43 +080024
Xueling Li255a6c12022-09-06 09:51:45 +080025# Check whether the project is a valid repo
26repo manifest 2>&1 | grep -q $build_dir
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080027if [ "$?" -ne 0 ]; then
28 echo "Non-repo source code"
bin.chen009b21e2024-04-30 15:38:32 +080029 if [ -s $DEFAULT_RTOS_SDK_MANIFEST ]; then
30 if [ -s $SOC_MANIFEST ]; then
31 echo "Use specific manifest: $SOC_MANIFEST"
32 cat $DEFAULT_RTOS_SDK_MANIFEST $SOC_MANIFEST > $RTOS_SDK_MANIFEST_FILE
fugui.zhangb6e4ec22022-12-07 14:58:40 +080033 else
34 echo "Use default manifest: $DEFAULT_RTOS_SDK_MANIFEST"
35 cp -f $DEFAULT_RTOS_SDK_MANIFEST $RTOS_SDK_MANIFEST_FILE
36 fi
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080037 else
38 echo "Default manifest.xml not found!"
39 exit 0
40 fi
41else
42 echo "Generate manifest.xml"
43 repo manifest > $RTOS_SDK_MANIFEST_FILE
44 if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
45 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
46 exit 1
47 fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080048fi
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080049
Kelvin Zhange2e04712022-02-09 17:39:35 +080050# Get SDK_VERSION
xiaohu.huangf4577f72022-11-08 17:56:02 +080051source scripts/gen_version.sh $RTOS_SDK_VERSION_FILE \
52 $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhange2e04712022-02-09 17:39:35 +080053
54if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
55 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
56 if [ -z "$is_update" ]; then
57 exit 0
58 else
59 echo "Update top Kconfig and CMakelists.txt."
60 fi
61fi
62
63# Back up manifest.xml
64cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhang5374de92022-01-14 10:35:43 +080065
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080066if [[ "$PRODUCT" == aocpu ]]; then
67 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
shijie.xiongb0afe962024-01-11 17:23:28 +080068 sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE
69elif [[ "$PRODUCT" == wcn ]]; then
70 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
71 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080072else
73 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
shijie.xiongb0afe962024-01-11 17:23:28 +080074 sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080075fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080076
Kelvin Zhang33a3a872021-12-09 15:29:20 +080077# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080078cat <<EOF > $cmake_file
79enable_language(C CXX ASM)
80
kelvin.zhangac22e652021-10-18 15:09:21 +080081EOF
82
Kelvin Zhang33a3a872021-12-09 15:29:20 +080083# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080084cat <<EOF > $kconfig_file
85EOF
86
kelvin.zhang83a4aa32022-04-08 15:48:35 +080087# Figure out the $relative_dir and its column
Kelvin Zhangecaacb32022-05-09 10:10:56 +080088[ -z "$REPO_DIR" ] && REPO_DIR=$PWD
Kelvin Zhang33a3a872021-12-09 15:29:20 +080089pattern="path="
90i=0
Kelvin Zhang9a382242022-04-11 18:46:32 +080091keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080092for keyword in $keyline; do
93 let i++
94 if [[ $keyword == $pattern* ]]; then
95 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
96 relative_dir=`dirname $repo_path`
kelvin.zhang83a4aa32022-04-08 15:48:35 +080097 # Filter current project
Kelvin Zhangecaacb32022-05-09 10:10:56 +080098 if [[ $REPO_DIR == *$relative_dir ]]; then
kelvin.zhang83a4aa32022-04-08 15:48:35 +080099 break
100 fi
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800101 fi
102done
103
104if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800105 pattern="path="
106else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800107 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800108fi
109
Kelvin Zhangd931bc32022-11-23 10:21:55 +0800110# Sort manifest.xml based on "path" to get an reasonable order for generating Kconfig
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800111sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
112
kelvin.zhangac22e652021-10-18 15:09:21 +0800113while IFS= read -r line
114do
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800115 keyline=`echo "$line" | grep "$pattern"`
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800116 [ -z "$keyline" ] && continue
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800117
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800118 for keyword in $keyline; do
119 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800120 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800121
Kelvin Zhang22cb55e2022-06-08 20:21:00 +0800122 if [[ $repo_path == drivers* ]] || [[ $repo_path == benchmark* ]]; then
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800123 category=`basename $repo_path | sed 's/_/ /g'`
124 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800125 else
126 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800127 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800128
Kelvin Zhang9a382242022-04-11 18:46:32 +0800129 # exclude some dirs
130 skip_flag=0
131 for exclude_dir in $exclude_dirs; do
132 if [[ $repo_path == $exclude_dir* ]]; then
133 skip_flag=1
134 break
135 fi
136 done
137 [ "$skip_flag" -eq 1 ] && continue
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800138
Kelvin Zhangaed13162022-01-11 16:31:13 +0800139 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800140 case $special_dirs in
141 *"$category"*) arch=`basename $repo_path`
142 if [ "$arch" == "$ARCH" ]; then
143 cmake_path="$category/\${ARCH}"
Kelvin Zhangce736e62022-03-02 14:17:40 +0800144 kconfig_path="$category/\${ARCH}"
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800145 else
146 continue
147 fi;;
148 * ) cmake_path=$repo_path
149 kconfig_path=$repo_path;;
150 esac
151
shijie.xiongb0afe962024-01-11 17:23:28 +0800152 # multiple types of SoC states
153 if [ ! -n "$SPLIT_ARCH_DIR" ] && [[ $cmake_path == *"/riscv/"* ]]; then
154 continue
155 elif [[ $cmake_path == *"/riscv/"* ]] && [[ ! $cmake_path == *"/riscv/$SPLIT_ARCH_DIR"* ]]; then
156 continue
157 fi
158
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800159 # Generate root CMakeLists.txt
160 if [ -f $repo_path/CMakeLists.txt ]; then
161 echo "add_subdirectory($cmake_path)" >> $cmake_file
162 fi
163
164 # Generate root Kconfig
165 if [ -f $repo_path/Kconfig ]; then
166 if [ "$last_category" != "$category" ]; then
167 if [ -n "$last_category" ]; then
168 echo -e "endmenu\n" >> $kconfig_file
169 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800170
Kelvin Zhangce29a712022-06-09 17:25:22 +0800171 if [ "$category" == "wcn" -o "$category" == "soc" ]; then
Kelvin Zhang24939422022-01-06 13:52:10 +0800172 echo "menu \"${category^^} Options\"" >> $kconfig_file
173 else
174 echo "menu \"${category^} Options\"" >> $kconfig_file
175 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800176 fi
177
178 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
179 last_category=$category
180 fi
181 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800182 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800183 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800184done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800185
186echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800187
Kelvin Zhang55457002021-12-29 14:26:17 +0800188sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800189touch $STAMP