blob: 62606cd9d2733d404f911f7470128fbce63ea07c [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.zhang34db9532021-10-20 16:56:43 +08009category_drivers="drivers"
10category_boards="boards"
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}'`
29 if [ $keyword ]; then
30 repo_path=`echo ${keyword#*path=} | sed 's/\"//g'`
kelvin.zhang34db9532021-10-20 16:56:43 +080031 if [ "$repo_path" == "$category_drivers" ]; then
kelvin.zhangc35b0762021-10-20 15:41:46 +080032 category=$repo_path
33 else
34 category=`dirname $repo_path`
35 fi
36
kelvin.zhangac22e652021-10-18 15:09:21 +080037 # Generate root CMakeLists.txt
kelvin.zhang60107092021-10-19 18:12:39 +080038 if [ -f $repo_path/CMakeLists.txt ] && [ "$category" != "$exclude_dir" ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080039 echo "add_subdirectory($repo_path)" >> $cmake_file
40 fi
41
kelvin.zhang78a66712021-10-20 17:27:41 +080042 if [ "$category" == "$category_boards" ]; then
43 repo_path=$repo_path/$BOARD
44 fi
kelvin.zhangac22e652021-10-18 15:09:21 +080045 # Generate root Kconfig
46 if [ -f $repo_path/Kconfig ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080047 if [ "$last_category" != "$category" ]; then
48 if [ $last_category ]; then
49 echo -e "endmenu\n" >> $kconfig_file
50 fi
51 echo "menu \"${category^} Options\"" >> $kconfig_file
52 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080053
kelvin.zhangac22e652021-10-18 15:09:21 +080054 echo "source \"$repo_path/Kconfig\"" >> $kconfig_file
55 last_category=$category
56 fi
57 fi
58done < "$input"
59
60echo "endmenu" >> $kconfig_file