blob: fad97c5abae13ab2513adff78537978dc9dc3e05 [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.zhang4b985472021-10-27 16:02:21 +080014
Kelvin Zhang33a3a872021-12-09 15:29:20 +080015# Generate manifest.xml
16repo manifest > $RTOS_SDK_MANIFEST_FILE
17if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
18 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
19 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080020fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080021
22if [ -s $RTOS_SDK_MANIFEST_FILE ] && [ -s $kconfig_file ] && [ $RTOS_SDK_MANIFEST_FILE -ot $kconfig_file ]; then
23 exit 0
24fi
25
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080026if [[ "$PRODUCT" == aocpu ]]; then
27 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
28else
29 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
30fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080031
Kelvin Zhang33a3a872021-12-09 15:29:20 +080032# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080033cat <<EOF > $cmake_file
34enable_language(C CXX ASM)
35
kelvin.zhangac22e652021-10-18 15:09:21 +080036EOF
37
Kelvin Zhang33a3a872021-12-09 15:29:20 +080038# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080039cat <<EOF > $kconfig_file
40EOF
41
Kelvin Zhang33a3a872021-12-09 15:29:20 +080042# filter manifest.xml of RTOS SDK
43sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
44# figure out the $relative_dir and its column
45pattern="path="
46i=0
47keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
48for keyword in $keyline; do
49 let i++
50 if [[ $keyword == $pattern* ]]; then
51 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
52 relative_dir=`dirname $repo_path`
53 break;
54 fi
55done
56
57if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080058 pattern="path="
59else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080060 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080061fi
62
Kelvin Zhang33a3a872021-12-09 15:29:20 +080063# sort manifest.xml of RTOS SDK
64sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
65
kelvin.zhangac22e652021-10-18 15:09:21 +080066while IFS= read -r line
67do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080068 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080069 for keyword in $keyline; do
70 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080071 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080072
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080073 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
74 category=`basename $repo_path | sed 's/_/ /g'`
75 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080076 else
77 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080078 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080079
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080080 if [[ $repo_path == $exclude_dir/* ]]; then
81 continue
82 fi
83
84 # exclude other ARCH dirs
85 case $special_dirs in
86 *"$category"*) arch=`basename $repo_path`
87 if [ "$arch" == "$ARCH" ]; then
88 cmake_path="$category/\${ARCH}"
89 kconfig_path="$category/\$(ARCH)"
90 else
91 continue
92 fi;;
93 * ) cmake_path=$repo_path
94 kconfig_path=$repo_path;;
95 esac
96
97 # Generate root CMakeLists.txt
98 if [ -f $repo_path/CMakeLists.txt ]; then
99 echo "add_subdirectory($cmake_path)" >> $cmake_file
100 fi
101
102 # Generate root Kconfig
103 if [ -f $repo_path/Kconfig ]; then
104 if [ "$last_category" != "$category" ]; then
105 if [ -n "$last_category" ]; then
106 echo -e "endmenu\n" >> $kconfig_file
107 fi
108 echo "menu \"${category^} Options\"" >> $kconfig_file
109 fi
110
111 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
112 last_category=$category
113 fi
114 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800115 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800116 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800117done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800118
119echo "endmenu" >> $kconfig_file