blob: a4526f1e25ed756ef005ba72311bb2ae03eb4c1d [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
38while IFS= read -r line
39do
40 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080041
kelvin.zhangac22e652021-10-18 15:09:21 +080042 if [ $keyword ]; then
43 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080044 if [[ $repo_path == $drivers_dir* ]] ; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080045 category=$repo_path
46 else
47 category=`dirname $repo_path`
48 fi
49
kelvin.zhang5ef541b2021-10-21 13:24:48 +080050 if [[ $repo_path == $exclude_dir/* ]] ; then
51 continue
52 fi
53
54 # exclude other ARCH dirs
55 case $special_dirs in
56 *"$category"*) arch=`basename $repo_path`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080057 if [ "$arch" == "$ARCH" ]; then
58 cmake_path="$category/\${ARCH}"
59 kconfig_path="$category/\$(ARCH)"
60 else
61 continue
62 fi;;
63 * ) cmake_path=$repo_path
64 kconfig_path=$repo_path;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080065 esac
66
kelvin.zhangac22e652021-10-18 15:09:21 +080067 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080068 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080069 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +080070 fi
71
72 # Generate root Kconfig
73 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080074 if [ "$last_category" != "$category" ]; then
75 if [ $last_category ]; then
76 echo -e "endmenu\n" >> $kconfig_file
77 fi
78 echo "menu \"${category^} Options\"" >> $kconfig_file
79 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080080
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080081 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +080082 last_category=$category
83 fi
84 fi
85done < "$input"
86
87echo "endmenu" >> $kconfig_file