blob: b3c8e33a96485286cc305a26c93a82a95c501fd5 [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
65 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080066
kelvin.zhangac22e652021-10-18 15:09:21 +080067 if [ $keyword ]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080068 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'`
Kelvin Zhang32ae4992021-12-01 19:50:46 +080069 if [[ $repo_path == $drivers_dir* ]] || [[ $repo_path == $third_party_dir* ]]; then
70 category=`echo $repo_path | sed 's/_/ /g'`
kelvin.zhangc35b0762021-10-20 15:41:46 +080071 else
72 category=`dirname $repo_path`
73 fi
74
kelvin.zhang5ef541b2021-10-21 13:24:48 +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`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080082 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;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080090 esac
91
kelvin.zhangac22e652021-10-18 15:09:21 +080092 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080093 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080094 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +080095 fi
96
97 # Generate root Kconfig
98 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080099 if [ "$last_category" != "$category" ]; then
Kelvin Zhang32ae4992021-12-01 19:50:46 +0800100 if [ -n "$last_category" ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +0800101 echo -e "endmenu\n" >> $kconfig_file
102 fi
103 echo "menu \"${category^} Options\"" >> $kconfig_file
104 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800105
kelvin.zhang53cdc1e2021-10-21 15:28:36 +0800106 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +0800107 last_category=$category
108 fi
109 fi
kelvin.zhang47e4dfb2021-10-29 16:57:47 +0800110done < "$manifest_file"
kelvin.zhangac22e652021-10-18 15:09:21 +0800111
112echo "endmenu" >> $kconfig_file