blob: 9f4b51c4dbd333e775699607edaa12023d1468d9 [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`
kelvin.zhang34db9532021-10-20 16:56:43 +080035 if [ "$category" == "$category_boards" ]; then
36 repo_path=$repo_path/$BOARD
37 fi
kelvin.zhangc35b0762021-10-20 15:41:46 +080038 fi
39
kelvin.zhangac22e652021-10-18 15:09:21 +080040 # Generate root CMakeLists.txt
kelvin.zhang60107092021-10-19 18:12:39 +080041 if [ -f $repo_path/CMakeLists.txt ] && [ "$category" != "$exclude_dir" ]; then
kelvin.zhangac22e652021-10-18 15:09:21 +080042 echo "add_subdirectory($repo_path)" >> $cmake_file
43 fi
44
45 # 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
53 echo "source \"$repo_path/Kconfig\"" >> $kconfig_file
54 last_category=$category
55 fi
56 fi
57done < "$input"
58
59echo "endmenu" >> $kconfig_file