blob: cf74bf3c44246fbc55ce12e6a67a8bb792f17924 [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"
10drivers_dir="drivers"
kelvin.zhang60107092021-10-19 18:12:39 +080011exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080012special_dirs="arch soc boards"
Kelvin Zhang32ae4992021-12-01 19:50:46 +080013third_party_dir="third_party"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080014
15RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
kelvin.zhang4b985472021-10-27 16:02:21 +080016
Kelvin Zhang33a3a872021-12-09 15:29:20 +080017if [ -s $RTOS_SDK_MANIFEST_FILE ] && [ -s $kconfig_file ] && [ $RTOS_SDK_MANIFEST_FILE -ot $kconfig_file ]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080018 exit 0
19fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080020
Kelvin Zhang33a3a872021-12-09 15:29:20 +080021# Generate manifest.xml
22repo manifest > $RTOS_SDK_MANIFEST_FILE
23if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
24 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
25 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080026fi
27
Kelvin Zhang33a3a872021-12-09 15:29:20 +080028# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080029cat <<EOF > $cmake_file
30enable_language(C CXX ASM)
31
kelvin.zhangac22e652021-10-18 15:09:21 +080032EOF
33
Kelvin Zhang33a3a872021-12-09 15:29:20 +080034# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080035cat <<EOF > $kconfig_file
36EOF
37
Kelvin Zhang33a3a872021-12-09 15:29:20 +080038# filter manifest.xml of RTOS SDK
39sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
40# figure out the $relative_dir and its column
41pattern="path="
42i=0
43keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
44for keyword in $keyline; do
45 let i++
46 if [[ $keyword == $pattern* ]]; then
47 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
48 relative_dir=`dirname $repo_path`
49 break;
50 fi
51done
52
53if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080054 pattern="path="
55else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080056 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080057fi
58
Kelvin Zhang33a3a872021-12-09 15:29:20 +080059# sort manifest.xml of RTOS SDK
60sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
61
kelvin.zhangac22e652021-10-18 15:09:21 +080062while IFS= read -r line
63do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080064 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080065 for keyword in $keyline; do
66 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080067 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080068
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080069 if [[ $repo_path == $drivers_dir* ]] || [[ $repo_path == $third_party_dir* ]]; then
70 category=`echo $repo_path | sed 's/_/ /g'`
71 else
72 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080073 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080074
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080075 if [[ $repo_path == $exclude_dir/* ]]; then
76 continue
77 fi
78
79 # exclude other ARCH dirs
80 case $special_dirs in
81 *"$category"*) arch=`basename $repo_path`
82 if [ "$arch" == "$ARCH" ]; then
83 cmake_path="$category/\${ARCH}"
84 kconfig_path="$category/\$(ARCH)"
85 else
86 continue
87 fi;;
88 * ) cmake_path=$repo_path
89 kconfig_path=$repo_path;;
90 esac
91
92 # Generate root CMakeLists.txt
93 if [ -f $repo_path/CMakeLists.txt ]; then
94 echo "add_subdirectory($cmake_path)" >> $cmake_file
95 fi
96
97 # Generate root Kconfig
98 if [ -f $repo_path/Kconfig ]; then
99 if [ "$last_category" != "$category" ]; then
100 if [ -n "$last_category" ]; then
101 echo -e "endmenu\n" >> $kconfig_file
102 fi
103 echo "menu \"${category^} Options\"" >> $kconfig_file
104 fi
105
106 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
107 last_category=$category
108 fi
109 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800110 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800111 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800112done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800113
114echo "endmenu" >> $kconfig_file