blob: 8990934fc5cc46a96111851bcd6d95fbb4029a40 [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 Zhang33a3a872021-12-09 15:29:20 +08009build_dir="build"
kelvin.zhang60107092021-10-19 18:12:39 +080010exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080011special_dirs="arch soc boards"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080012
13RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080014STAMP="$kernel_BUILD_DIR/.stamp"
15
Kelvin Zhange87f5192021-12-30 16:59:12 +080016# Check whether the project is a repo
17repo manifest >/dev/null 2>&1
18[ "$?" -ne 0 ] && exit 0
19
Kelvin Zhang24a365e2021-12-28 15:52:55 +080020if [ -s $RTOS_SDK_MANIFEST_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
21 exit 0
22fi
kelvin.zhang4b985472021-10-27 16:02:21 +080023
Kelvin Zhang33a3a872021-12-09 15:29:20 +080024# Generate manifest.xml
25repo manifest > $RTOS_SDK_MANIFEST_FILE
26if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
27 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
28 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080029fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080030
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080031if [[ "$PRODUCT" == aocpu ]]; then
32 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
33else
34 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
35fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080036
Kelvin Zhang33a3a872021-12-09 15:29:20 +080037# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080038cat <<EOF > $cmake_file
39enable_language(C CXX ASM)
40
kelvin.zhangac22e652021-10-18 15:09:21 +080041EOF
42
Kelvin Zhang33a3a872021-12-09 15:29:20 +080043# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080044cat <<EOF > $kconfig_file
45EOF
46
Kelvin Zhang33a3a872021-12-09 15:29:20 +080047# filter manifest.xml of RTOS SDK
48sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
49# figure out the $relative_dir and its column
50pattern="path="
51i=0
52keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
53for keyword in $keyline; do
54 let i++
55 if [[ $keyword == $pattern* ]]; then
56 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
57 relative_dir=`dirname $repo_path`
58 break;
59 fi
60done
61
62if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080063 pattern="path="
64else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080065 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080066fi
67
Kelvin Zhang33a3a872021-12-09 15:29:20 +080068# sort manifest.xml of RTOS SDK
69sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
70
kelvin.zhangac22e652021-10-18 15:09:21 +080071while IFS= read -r line
72do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080073 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080074 for keyword in $keyline; do
75 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080076 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080077
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080078 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
79 category=`basename $repo_path | sed 's/_/ /g'`
80 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080081 else
82 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080083 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080084
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080085 if [[ $repo_path == $exclude_dir/* ]]; then
86 continue
87 fi
88
89 # exclude other ARCH dirs
90 case $special_dirs in
91 *"$category"*) arch=`basename $repo_path`
92 if [ "$arch" == "$ARCH" ]; then
93 cmake_path="$category/\${ARCH}"
94 kconfig_path="$category/\$(ARCH)"
95 else
96 continue
97 fi;;
98 * ) cmake_path=$repo_path
99 kconfig_path=$repo_path;;
100 esac
101
102 # Generate root CMakeLists.txt
103 if [ -f $repo_path/CMakeLists.txt ]; then
104 echo "add_subdirectory($cmake_path)" >> $cmake_file
105 fi
106
107 # Generate root Kconfig
108 if [ -f $repo_path/Kconfig ]; then
109 if [ "$last_category" != "$category" ]; then
110 if [ -n "$last_category" ]; then
111 echo -e "endmenu\n" >> $kconfig_file
112 fi
113 echo "menu \"${category^} Options\"" >> $kconfig_file
114 fi
115
116 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
117 last_category=$category
118 fi
119 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800120 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800121 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800122done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800123
124echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800125
Kelvin Zhang55457002021-12-29 14:26:17 +0800126sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800127touch $STAMP