blob: 325003b46e01f843a75726e8f89b75980cb25fdd [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
xiaohu.huang7232fef2024-07-18 17:25:41 +080025# Use repo in .repo/repo dir,otherwise use in system default location
26repo_root_dir=$PWD
27while [ "$repo_root_dir" != "/" ]; do
28 if [ -d "$repo_root_dir/.repo" ]; then
29 break
30 fi
31 repo_root_dir=$(dirname "$repo_root_dir")
32done
33if [ "$repo_root_dir" == "/" ] && [ ! -d "/.repo" ]; then
34 echo ".repo not found,use system default location."
35else
36 echo ".repo at: $repo_root_dir/.repo"
37 export PATH=$repo_root_dir/.repo/repo:$PATH
38fi
39
Xueling Li255a6c12022-09-06 09:51:45 +080040# Check whether the project is a valid repo
41repo manifest 2>&1 | grep -q $build_dir
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080042if [ "$?" -ne 0 ]; then
43 echo "Non-repo source code"
bin.chen009b21e2024-04-30 15:38:32 +080044 if [ -s $DEFAULT_RTOS_SDK_MANIFEST ]; then
45 if [ -s $SOC_MANIFEST ]; then
46 echo "Use specific manifest: $SOC_MANIFEST"
47 cat $DEFAULT_RTOS_SDK_MANIFEST $SOC_MANIFEST > $RTOS_SDK_MANIFEST_FILE
fugui.zhangb6e4ec22022-12-07 14:58:40 +080048 else
49 echo "Use default manifest: $DEFAULT_RTOS_SDK_MANIFEST"
50 cp -f $DEFAULT_RTOS_SDK_MANIFEST $RTOS_SDK_MANIFEST_FILE
51 fi
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080052 else
53 echo "Default manifest.xml not found!"
54 exit 0
55 fi
56else
57 echo "Generate manifest.xml"
58 repo manifest > $RTOS_SDK_MANIFEST_FILE
59 if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
60 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
61 exit 1
62 fi
xiaohu.huang638c5712024-08-07 15:24:40 +080063 # If the name and path is same in mainfext.xml,cmd repo manifest will ignore path section
64 # and only generate name section cause they are same,so we need add path section with sed
65 sed -i -r '/name=/ { /path=/! s/(name=("[^"]+"))/& path=\2/ }' $RTOS_SDK_MANIFEST_FILE
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080066fi
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080067
Kelvin Zhange2e04712022-02-09 17:39:35 +080068# Get SDK_VERSION
xiaohu.huang22242642024-08-14 16:53:12 +080069if [ -s $DEFAULT_RTOS_SDK_MANIFEST ]; then
70 source scripts/gen_version.sh $RTOS_SDK_VERSION_FILE \
71 $RTOS_SDK_MANIFEST_FILE $DEFAULT_RTOS_SDK_MANIFEST
72else
73 source scripts/gen_version.sh $RTOS_SDK_VERSION_FILE $RTOS_SDK_MANIFEST_FILE
74fi
Kelvin Zhange2e04712022-02-09 17:39:35 +080075
76if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
77 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
78 if [ -z "$is_update" ]; then
79 exit 0
80 else
81 echo "Update top Kconfig and CMakelists.txt."
82 fi
83fi
84
85# Back up manifest.xml
86cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhang5374de92022-01-14 10:35:43 +080087
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080088if [[ "$PRODUCT" == aocpu ]]; then
89 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
shijie.xiongb0afe962024-01-11 17:23:28 +080090 sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE
91elif [[ "$PRODUCT" == wcn ]]; then
92 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
93 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080094else
95 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
shijie.xiongb0afe962024-01-11 17:23:28 +080096 sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080097fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080098
Kelvin Zhang33a3a872021-12-09 15:29:20 +080099# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +0800100cat <<EOF > $cmake_file
101enable_language(C CXX ASM)
102
kelvin.zhangac22e652021-10-18 15:09:21 +0800103EOF
104
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800105# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +0800106cat <<EOF > $kconfig_file
107EOF
108
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800109# Figure out the $relative_dir and its column
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800110[ -z "$REPO_DIR" ] && REPO_DIR=$PWD
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800111pattern="path="
112i=0
Kelvin Zhang9a382242022-04-11 18:46:32 +0800113keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800114for keyword in $keyline; do
115 let i++
116 if [[ $keyword == $pattern* ]]; then
117 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
118 relative_dir=`dirname $repo_path`
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800119 # Filter current project
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800120 if [[ $REPO_DIR == *$relative_dir ]]; then
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800121 break
122 fi
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800123 fi
124done
125
126if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800127 pattern="path="
128else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800129 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800130fi
131
Kelvin Zhangd931bc32022-11-23 10:21:55 +0800132# Sort manifest.xml based on "path" to get an reasonable order for generating Kconfig
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800133sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
134
kelvin.zhangac22e652021-10-18 15:09:21 +0800135while IFS= read -r line
136do
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800137 keyline=`echo "$line" | grep "$pattern"`
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800138 [ -z "$keyline" ] && continue
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800139
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800140 for keyword in $keyline; do
141 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800142 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800143
Kelvin Zhang22cb55e2022-06-08 20:21:00 +0800144 if [[ $repo_path == drivers* ]] || [[ $repo_path == benchmark* ]]; then
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800145 category=`basename $repo_path | sed 's/_/ /g'`
146 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800147 else
148 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800149 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800150
Kelvin Zhang9a382242022-04-11 18:46:32 +0800151 # exclude some dirs
152 skip_flag=0
153 for exclude_dir in $exclude_dirs; do
154 if [[ $repo_path == $exclude_dir* ]]; then
155 skip_flag=1
156 break
157 fi
158 done
159 [ "$skip_flag" -eq 1 ] && continue
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800160
Kelvin Zhangaed13162022-01-11 16:31:13 +0800161 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800162 case $special_dirs in
163 *"$category"*) arch=`basename $repo_path`
164 if [ "$arch" == "$ARCH" ]; then
165 cmake_path="$category/\${ARCH}"
Kelvin Zhangce736e62022-03-02 14:17:40 +0800166 kconfig_path="$category/\${ARCH}"
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800167 else
168 continue
169 fi;;
170 * ) cmake_path=$repo_path
171 kconfig_path=$repo_path;;
172 esac
173
shijie.xiongb0afe962024-01-11 17:23:28 +0800174 # multiple types of SoC states
175 if [ ! -n "$SPLIT_ARCH_DIR" ] && [[ $cmake_path == *"/riscv/"* ]]; then
176 continue
177 elif [[ $cmake_path == *"/riscv/"* ]] && [[ ! $cmake_path == *"/riscv/$SPLIT_ARCH_DIR"* ]]; then
178 continue
179 fi
180
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800181 # Generate root CMakeLists.txt
182 if [ -f $repo_path/CMakeLists.txt ]; then
183 echo "add_subdirectory($cmake_path)" >> $cmake_file
184 fi
185
186 # Generate root Kconfig
187 if [ -f $repo_path/Kconfig ]; then
188 if [ "$last_category" != "$category" ]; then
189 if [ -n "$last_category" ]; then
190 echo -e "endmenu\n" >> $kconfig_file
191 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800192
Kelvin Zhangce29a712022-06-09 17:25:22 +0800193 if [ "$category" == "wcn" -o "$category" == "soc" ]; then
Kelvin Zhang24939422022-01-06 13:52:10 +0800194 echo "menu \"${category^^} Options\"" >> $kconfig_file
195 else
196 echo "menu \"${category^} Options\"" >> $kconfig_file
197 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800198 fi
199
200 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
201 last_category=$category
202 fi
203 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800204 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800205 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800206done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800207
208echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800209
Kelvin Zhang55457002021-12-29 14:26:17 +0800210sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800211touch $STAMP