blob: f79ee1d0bbf962bdb28770efef9c8510334a677a [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 Zhang8cc560f2021-12-24 20:25:08 +080010#drivers_dir="drivers drivers_aocpu"
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
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080027if [[ "$PRODUCT" == aocpu ]]; then
28 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
29else
30 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
31fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080032
Kelvin Zhang33a3a872021-12-09 15:29:20 +080033# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080034cat <<EOF > $cmake_file
35enable_language(C CXX ASM)
36
kelvin.zhangac22e652021-10-18 15:09:21 +080037EOF
38
Kelvin Zhang33a3a872021-12-09 15:29:20 +080039# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080040cat <<EOF > $kconfig_file
41EOF
42
Kelvin Zhang33a3a872021-12-09 15:29:20 +080043# filter manifest.xml of RTOS SDK
44sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
45# figure out the $relative_dir and its column
46pattern="path="
47i=0
48keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
49for keyword in $keyline; do
50 let i++
51 if [[ $keyword == $pattern* ]]; then
52 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
53 relative_dir=`dirname $repo_path`
54 break;
55 fi
56done
57
58if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080059 pattern="path="
60else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080061 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080062fi
63
Kelvin Zhang33a3a872021-12-09 15:29:20 +080064# sort manifest.xml of RTOS SDK
65sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
66
kelvin.zhangac22e652021-10-18 15:09:21 +080067while IFS= read -r line
68do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080069 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080070 for keyword in $keyline; do
71 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080072 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080073
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080074# if [[ $repo_path == $drivers_dir* ]] || [[ $repo_path == $third_party_dir* ]]; then
75 if [[ $repo_path == $third_party_dir* ]]; then
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080076 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