blob: 42fd4249b480dac9ecd33d750743232826489665 [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 +08007if [ -n "$1" ]; then
8 input=$1
9else
10 input="$PWD/.repo/manifests/default.xml"
11fi
12
13if [ ! -f $1 ]; then
14 echo "No such file: $input"
15 exit 1
16fi
17
18cmake_file="$PWD/CMakeLists.txt"
19kconfig_file="$PWD/Kconfig"
kelvin.zhang60107092021-10-19 18:12:39 +080020exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080021special_dirs="arch soc boards"
22drivers_dir="drivers"
kelvin.zhangac22e652021-10-18 15:09:21 +080023
24cat <<EOF > $cmake_file
25enable_language(C CXX ASM)
26
27target_include_directories(
28 \${TARGET_NAME}
29 PUBLIC
30 include
31)
32
33EOF
34
35cat <<EOF > $kconfig_file
36EOF
37
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080038absolute_prj_dir=`echo ${input%.repo*}`
39if [[ $absolute_prj_dir == $PWD/ ]] ; then
40 pattern="path="
41else
42 relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}}`
43 pattern="path=\"${relative_prj_dir}/"
44fi
45
kelvin.zhangac22e652021-10-18 15:09:21 +080046while IFS= read -r line
47do
48 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080049
kelvin.zhangac22e652021-10-18 15:09:21 +080050 if [ $keyword ]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080051 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080052 if [[ $repo_path == $drivers_dir* ]] ; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080053 category=$repo_path
54 else
55 category=`dirname $repo_path`
56 fi
57
kelvin.zhang5ef541b2021-10-21 13:24:48 +080058 if [[ $repo_path == $exclude_dir/* ]] ; then
59 continue
60 fi
61
62 # exclude other ARCH dirs
63 case $special_dirs in
64 *"$category"*) arch=`basename $repo_path`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080065 if [ "$arch" == "$ARCH" ]; then
66 cmake_path="$category/\${ARCH}"
67 kconfig_path="$category/\$(ARCH)"
68 else
69 continue
70 fi;;
71 * ) cmake_path=$repo_path
72 kconfig_path=$repo_path;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080073 esac
74
kelvin.zhangac22e652021-10-18 15:09:21 +080075 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080076 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080077 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +080078 fi
79
80 # Generate root Kconfig
81 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080082 if [ "$last_category" != "$category" ]; then
83 if [ $last_category ]; then
84 echo -e "endmenu\n" >> $kconfig_file
85 fi
86 echo "menu \"${category^} Options\"" >> $kconfig_file
87 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080088
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080089 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +080090 last_category=$category
91 fi
92 fi
93done < "$input"
94
95echo "endmenu" >> $kconfig_file