blob: dd48a78b763a9de596b180d2a150dc133790cb51 [file] [log] [blame]
kelvin.zhangac22e652021-10-18 15:09:21 +08001#!/bin/bash
2
3prj_dir=`pwd`
4
5input="$prj_dir/.repo/manifests/default.xml"
6cmake_file="$prj_dir/CMakeLists.txt"
7kconfig_file="$prj_dir/Kconfig"
kelvin.zhang60107092021-10-19 18:12:39 +08008exclude_dir="products"
kelvin.zhang5ef541b2021-10-21 13:24:48 +08009special_dirs="arch soc boards"
10drivers_dir="drivers"
kelvin.zhangac22e652021-10-18 15:09:21 +080011
12cat <<EOF > $cmake_file
13enable_language(C CXX ASM)
14
15target_include_directories(
16 \${TARGET_NAME}
17 PUBLIC
18 include
19)
20
21EOF
22
23cat <<EOF > $kconfig_file
24EOF
25
26while IFS= read -r line
27do
28 keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080029
kelvin.zhangac22e652021-10-18 15:09:21 +080030 if [ $keyword ]; then
31 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080032 if [[ $repo_path == $drivers_dir* ]] ; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080033 category=$repo_path
34 else
35 category=`dirname $repo_path`
36 fi
37
kelvin.zhang5ef541b2021-10-21 13:24:48 +080038 if [[ $repo_path == $exclude_dir/* ]] ; then
39 continue
40 fi
41
42 # exclude other ARCH dirs
43 case $special_dirs in
44 *"$category"*) arch=`basename $repo_path`
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080045 if [ "$arch" == "$ARCH" ]; then
46 cmake_path="$category/\${ARCH}"
47 kconfig_path="$category/\$(ARCH)"
48 else
49 continue
50 fi;;
51 * ) cmake_path=$repo_path
52 kconfig_path=$repo_path;;
kelvin.zhang5ef541b2021-10-21 13:24:48 +080053 esac
54
kelvin.zhangac22e652021-10-18 15:09:21 +080055 # Generate root CMakeLists.txt
kelvin.zhang5ef541b2021-10-21 13:24:48 +080056 if [ -f $repo_path/CMakeLists.txt ]; then
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080057 echo "add_subdirectory($cmake_path)" >> $cmake_file
kelvin.zhangac22e652021-10-18 15:09:21 +080058 fi
59
60 # Generate root Kconfig
61 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080062 if [ "$last_category" != "$category" ]; then
63 if [ $last_category ]; then
64 echo -e "endmenu\n" >> $kconfig_file
65 fi
66 echo "menu \"${category^} Options\"" >> $kconfig_file
67 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080068
kelvin.zhang53cdc1e2021-10-21 15:28:36 +080069 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
kelvin.zhangac22e652021-10-18 15:09:21 +080070 last_category=$category
71 fi
72 fi
73done < "$input"
74
75echo "endmenu" >> $kconfig_file