blob: 097d9186235a0df9315d277dd7e0592202f2a7fe [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.zhangbdb01dd2021-11-02 10:14:45 +08007if [ -f $dir/CMakeLists.txt ] && [ $manifest_file -ot $dir/CMakeLists.txt ]; then
8 exit 0
9fi
10
kelvin.zhangf91d7b02021-10-26 16:47:17 +080011cmake_file="$PWD/CMakeLists.txt"
12kconfig_file="$PWD/Kconfig"
kelvin.zhang60107092021-10-19 18:12:39 +080013exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080014special_dirs="arch soc boards"
15drivers_dir="drivers"
kelvin.zhang4b985472021-10-27 16:02:21 +080016dir=$PWD
17
18if [ -n "$1" ]; then
19 file_name=$1
20else
21 file_name="default.xml"
22fi
23
24while : ; do
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080025 if [[ -n $(find $dir/.repo -name $file_name) ]]; then
26 manifest_file=`find $dir/.repo -name $file_name`
kelvin.zhang4b985472021-10-27 16:02:21 +080027 break
28 fi
29 dir=`dirname $dir`
30 mountpoint -q $dir
31 [ $? -eq 0 ] && break;
32done
33
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080034if [ ! -f $manifest_file ]; then
kelvin.zhang4b985472021-10-27 16:02:21 +080035 echo "No such file: $file_name"
36 exit 1
37fi
kelvin.zhangac22e652021-10-18 15:09:21 +080038
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080039
40if [ ! -f $dir/CMakeLists.txt ]; then
41 echo "CMakeLists.txt and Kconfig Generated"
42elif [ $manifest_file -nt $dir/CMakeLists.txt ]; then
43 echo "CMakeLists.txt and Kconfig Updated"
44fi
45
kelvin.zhangac22e652021-10-18 15:09:21 +080046cat <<EOF > $cmake_file
47enable_language(C CXX ASM)
48
49target_include_directories(
50 \${TARGET_NAME}
51 PUBLIC
52 include
53)
54
55EOF
56
57cat <<EOF > $kconfig_file
58EOF
59
kelvin.zhang4b985472021-10-27 16:02:21 +080060absolute_prj_dir=$dir
kelvin.zhang47e4dfb2021-10-29 16:57:47 +080061if [[ $absolute_prj_dir == $PWD ]] ; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080062 pattern="path="
63else
kelvin.zhang4b985472021-10-27 16:02:21 +080064 relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}/}`
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080065 pattern="path=\"${relative_prj_dir}/"
66fi
67
kelvin.zhangac22e652021-10-18 15:09:21 +080068while IFS= read -r line
69do
70 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080071
kelvin.zhangac22e652021-10-18 15:09:21 +080072 if [ $keyword ]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080073 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080074 if [[ $repo_path == $drivers_dir* ]] ; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080075 category=$repo_path
76 else
77 category=`dirname $repo_path`
78 fi
79
kelvin.zhang5ef541b2021-10-21 13:24:48 +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`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080087 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;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080095 esac
96
kelvin.zhangac22e652021-10-18 15:09:21 +080097 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080098 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080099 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +0800100 fi
101
102 # Generate root Kconfig
103 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +0800104 if [ "$last_category" != "$category" ]; then
105 if [ $last_category ]; then
106 echo -e "endmenu\n" >> $kconfig_file
107 fi
108 echo "menu \"${category^} Options\"" >> $kconfig_file
109 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800110
kelvin.zhang53cdc1e2021-10-21 15:28:36 +0800111 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +0800112 last_category=$category
113 fi
114 fi
kelvin.zhang47e4dfb2021-10-29 16:57:47 +0800115done < "$manifest_file"
kelvin.zhangac22e652021-10-18 15:09:21 +0800116
117echo "endmenu" >> $kconfig_file