blob: cce3a87cf52b19b398727e7b8a5351aeb304653f [file] [log] [blame]
kelvin.zhangac22e652021-10-18 15:09:21 +08001#!/bin/bash
2
kelvin.zhangf91d7b02021-10-26 16:47:17 +08003###############################################################
4# Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml.
5###############################################################
kelvin.zhangac22e652021-10-18 15:09:21 +08006
kelvin.zhangf91d7b02021-10-26 16:47:17 +08007cmake_file="$PWD/CMakeLists.txt"
8kconfig_file="$PWD/Kconfig"
kelvin.zhang60107092021-10-19 18:12:39 +08009exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080010special_dirs="arch soc boards"
11drivers_dir="drivers"
Kelvin Zhang32ae4992021-12-01 19:50:46 +080012third_party_dir="third_party"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080013
14RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
kelvin.zhang4b985472021-10-27 16:02:21 +080015
16if [ -n "$1" ]; then
17 file_name=$1
18else
19 file_name="default.xml"
20fi
21
Kelvin Zhang25ccae72021-12-07 16:42:12 +080022dir=$PWD
kelvin.zhang4b985472021-10-27 16:02:21 +080023while : ; do
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080024 if [[ -n $(find $dir/.repo -name $file_name) ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080025 MANIFEST_FILE=`find $dir/.repo -name $file_name`
kelvin.zhang4b985472021-10-27 16:02:21 +080026 break
27 fi
28 dir=`dirname $dir`
29 mountpoint -q $dir
30 [ $? -eq 0 ] && break;
31done
32
Kelvin Zhang25ccae72021-12-07 16:42:12 +080033if [ ! -f $MANIFEST_FILE ]; then
kelvin.zhang4b985472021-10-27 16:02:21 +080034 echo "No such file: $file_name"
35 exit 1
36fi
kelvin.zhangac22e652021-10-18 15:09:21 +080037
Kelvin Zhang25ccae72021-12-07 16:42:12 +080038if [ -f $RTOS_SDK_MANIFEST_FILE ] && [ $MANIFEST_FILE -ot $RTOS_SDK_MANIFEST_FILE ]; then
39 exit 0
40fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080041
Kelvin Zhang25ccae72021-12-07 16:42:12 +080042repo manifest -o $RTOS_SDK_MANIFEST_FILE
43sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
44
45
46if [ ! -f $cmake_file ]; then
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080047 echo "CMakeLists.txt and Kconfig Generated"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080048elif [ $RTOS_SDK_MANIFEST_FILE -nt $cmake_file ]; then
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080049 echo "CMakeLists.txt and Kconfig Updated"
50fi
51
kelvin.zhangac22e652021-10-18 15:09:21 +080052cat <<EOF > $cmake_file
53enable_language(C CXX ASM)
54
kelvin.zhangac22e652021-10-18 15:09:21 +080055EOF
56
57cat <<EOF > $kconfig_file
58EOF
59
kelvin.zhang4b985472021-10-27 16:02:21 +080060absolute_prj_dir=$dir
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080061if [[ $absolute_prj_dir == $PWD ]] ; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080062 pattern="path="
63else
kelvin.zhang4b985472021-10-27 16:02:21 +080064 relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}/}`
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080065 pattern="path=\"${relative_prj_dir}/"
66fi
67
kelvin.zhangac22e652021-10-18 15:09:21 +080068while IFS= read -r line
69do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080070 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080071 for keyword in $keyline; do
72 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080073 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080074
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080075 if [[ $repo_path == $drivers_dir* ]] || [[ $repo_path == $third_party_dir* ]]; then
76 category=`echo $repo_path | sed 's/_/ /g'`
77 else
78 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080079 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080080
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080081 if [[ $repo_path == $exclude_dir/* ]]; then
82 continue
83 fi
84
85 # exclude other ARCH dirs
86 case $special_dirs in
87 *"$category"*) arch=`basename $repo_path`
88 if [ "$arch" == "$ARCH" ]; then
89 cmake_path="$category/\${ARCH}"
90 kconfig_path="$category/\$(ARCH)"
91 else
92 continue
93 fi;;
94 * ) cmake_path=$repo_path
95 kconfig_path=$repo_path;;
96 esac
97
98 # Generate root CMakeLists.txt
99 if [ -f $repo_path/CMakeLists.txt ]; then
100 echo "add_subdirectory($cmake_path)" >> $cmake_file
101 fi
102
103 # Generate root Kconfig
104 if [ -f $repo_path/Kconfig ]; then
105 if [ "$last_category" != "$category" ]; then
106 if [ -n "$last_category" ]; then
107 echo -e "endmenu\n" >> $kconfig_file
108 fi
109 echo "menu \"${category^} Options\"" >> $kconfig_file
110 fi
111
112 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
113 last_category=$category
114 fi
115 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800116 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800117 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800118done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800119
120echo "endmenu" >> $kconfig_file