blob: 8b8d22a934e6b390a9ed4b8dc8515ec359011461 [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.zhang4b985472021-10-27 16:02:21 +080013dir=$PWD
14
15if [ -n "$1" ]; then
16 file_name=$1
17else
18 file_name="default.xml"
19fi
20
21while : ; do
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080022 if [[ -n $(find $dir/.repo -name $file_name) ]]; then
23 manifest_file=`find $dir/.repo -name $file_name`
kelvin.zhang4b985472021-10-27 16:02:21 +080024 break
25 fi
26 dir=`dirname $dir`
27 mountpoint -q $dir
28 [ $? -eq 0 ] && break;
29done
30
Kelvin Zhang9d2e8eb2021-11-19 16:48:38 +080031if [ -f $dir/CMakeLists.txt ] && [ $manifest_file -ot $dir/CMakeLists.txt ]; then
32 exit 0
33fi
34
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080035if [ ! -f $manifest_file ]; then
kelvin.zhang4b985472021-10-27 16:02:21 +080036 echo "No such file: $file_name"
37 exit 1
38fi
kelvin.zhangac22e652021-10-18 15:09:21 +080039
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080040
41if [ ! -f $dir/CMakeLists.txt ]; then
42 echo "CMakeLists.txt and Kconfig Generated"
43elif [ $manifest_file -nt $dir/CMakeLists.txt ]; then
44 echo "CMakeLists.txt and Kconfig Updated"
45fi
46
kelvin.zhangac22e652021-10-18 15:09:21 +080047cat <<EOF > $cmake_file
48enable_language(C CXX ASM)
49
kelvin.zhangac22e652021-10-18 15:09:21 +080050EOF
51
52cat <<EOF > $kconfig_file
53EOF
54
kelvin.zhang4b985472021-10-27 16:02:21 +080055absolute_prj_dir=$dir
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080056if [[ $absolute_prj_dir == $PWD ]] ; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080057 pattern="path="
58else
kelvin.zhang4b985472021-10-27 16:02:21 +080059 relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}/}`
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080060 pattern="path=\"${relative_prj_dir}/"
61fi
62
kelvin.zhangac22e652021-10-18 15:09:21 +080063while IFS= read -r line
64do
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080065 keyline=`echo "$line" | grep 'path=.* name='`
66 for keyword in $keyline; do
67 if [[ $keyword == path=* ]]; then
68 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080069
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080070 if [[ $repo_path == $drivers_dir* ]] || [[ $repo_path == $third_party_dir* ]]; then
71 category=`echo $repo_path | sed 's/_/ /g'`
72 else
73 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080074 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080075
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080076 if [[ $repo_path == $exclude_dir/* ]]; then
77 continue
78 fi
79
80 # exclude other ARCH dirs
81 case $special_dirs in
82 *"$category"*) arch=`basename $repo_path`
83 if [ "$arch" == "$ARCH" ]; then
84 cmake_path="$category/\${ARCH}"
85 kconfig_path="$category/\$(ARCH)"
86 else
87 continue
88 fi;;
89 * ) cmake_path=$repo_path
90 kconfig_path=$repo_path;;
91 esac
92
93 # Generate root CMakeLists.txt
94 if [ -f $repo_path/CMakeLists.txt ]; then
95 echo "add_subdirectory($cmake_path)" >> $cmake_file
96 fi
97
98 # Generate root Kconfig
99 if [ -f $repo_path/Kconfig ]; then
100 if [ "$last_category" != "$category" ]; then
101 if [ -n "$last_category" ]; then
102 echo -e "endmenu\n" >> $kconfig_file
103 fi
104 echo "menu \"${category^} Options\"" >> $kconfig_file
105 fi
106
107 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
108 last_category=$category
109 fi
110 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800111 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800112 done
kelvin.zhang47e4dfb2021-10-29 16:57:47 +0800113done < "$manifest_file"
kelvin.zhangac22e652021-10-18 15:09:21 +0800114
115echo "endmenu" >> $kconfig_file