blob: 36465cb39603e75578f71d28917897b4b6d04034 [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.zhang4b985472021-10-27 16:02:21 +080012dir=$PWD
13
14if [ -n "$1" ]; then
15 file_name=$1
16else
17 file_name="default.xml"
18fi
19
20while : ; do
21 if [[ -n $(find $dir/.repo -name $file_name 2>/dev/null) ]]; then
22 file_path=`find $dir/.repo -name $file_name`
23 break
24 fi
25 dir=`dirname $dir`
26 mountpoint -q $dir
27 [ $? -eq 0 ] && break;
28done
29
30if [ ! -f $file_path ]; then
31 echo "No such file: $file_name"
32 exit 1
33fi
kelvin.zhangac22e652021-10-18 15:09:21 +080034
35cat <<EOF > $cmake_file
36enable_language(C CXX ASM)
37
38target_include_directories(
39 \${TARGET_NAME}
40 PUBLIC
41 include
42)
43
44EOF
45
46cat <<EOF > $kconfig_file
47EOF
48
kelvin.zhang4b985472021-10-27 16:02:21 +080049absolute_prj_dir=$dir
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080050if [[ $absolute_prj_dir == $PWD/ ]] ; then
51 pattern="path="
52else
kelvin.zhang4b985472021-10-27 16:02:21 +080053 relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}/}`
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080054 pattern="path=\"${relative_prj_dir}/"
55fi
56
kelvin.zhangac22e652021-10-18 15:09:21 +080057while IFS= read -r line
58do
59 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080060
kelvin.zhangac22e652021-10-18 15:09:21 +080061 if [ $keyword ]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080062 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080063 if [[ $repo_path == $drivers_dir* ]] ; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080064 category=$repo_path
65 else
66 category=`dirname $repo_path`
67 fi
68
kelvin.zhang5ef541b2021-10-21 13:24:48 +080069 if [[ $repo_path == $exclude_dir/* ]] ; then
70 continue
71 fi
72
73 # exclude other ARCH dirs
74 case $special_dirs in
75 *"$category"*) arch=`basename $repo_path`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080076 if [ "$arch" == "$ARCH" ]; then
77 cmake_path="$category/\${ARCH}"
78 kconfig_path="$category/\$(ARCH)"
79 else
80 continue
81 fi;;
82 * ) cmake_path=$repo_path
83 kconfig_path=$repo_path;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080084 esac
85
kelvin.zhangac22e652021-10-18 15:09:21 +080086 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080087 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080088 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +080089 fi
90
91 # Generate root Kconfig
92 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080093 if [ "$last_category" != "$category" ]; then
94 if [ $last_category ]; then
95 echo -e "endmenu\n" >> $kconfig_file
96 fi
97 echo "menu \"${category^} Options\"" >> $kconfig_file
98 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080099
kelvin.zhang53cdc1e2021-10-21 15:28:36 +0800100 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +0800101 last_category=$category
102 fi
103 fi
kelvin.zhang4b985472021-10-27 16:02:21 +0800104done < "$file_path"
kelvin.zhangac22e652021-10-18 15:09:21 +0800105
106echo "endmenu" >> $kconfig_file