kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | prj_dir=`pwd` |
| 4 | |
| 5 | input="$prj_dir/.repo/manifests/default.xml" |
| 6 | cmake_file="$prj_dir/CMakeLists.txt" |
| 7 | kconfig_file="$prj_dir/Kconfig" |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 8 | exclude_dir="products" |
kelvin.zhang | 34db953 | 2021-10-20 16:56:43 +0800 | [diff] [blame] | 9 | category_drivers="drivers" |
| 10 | category_boards="boards" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 11 | |
| 12 | cat <<EOF > $cmake_file |
| 13 | enable_language(C CXX ASM) |
| 14 | |
| 15 | target_include_directories( |
| 16 | \${TARGET_NAME} |
| 17 | PUBLIC |
| 18 | include |
| 19 | ) |
| 20 | |
| 21 | EOF |
| 22 | |
| 23 | cat <<EOF > $kconfig_file |
| 24 | EOF |
| 25 | |
| 26 | while IFS= read -r line |
| 27 | do |
| 28 | keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'` |
| 29 | if [ $keyword ]; then |
| 30 | repo_path=`echo ${keyword#*path=} | sed 's/\"//g'` |
kelvin.zhang | 34db953 | 2021-10-20 16:56:43 +0800 | [diff] [blame] | 31 | if [ "$repo_path" == "$category_drivers" ]; then |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame] | 32 | category=$repo_path |
| 33 | else |
| 34 | category=`dirname $repo_path` |
| 35 | fi |
| 36 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 37 | # Generate root CMakeLists.txt |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 38 | if [ -f $repo_path/CMakeLists.txt ] && [ "$category" != "$exclude_dir" ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 39 | echo "add_subdirectory($repo_path)" >> $cmake_file |
| 40 | fi |
| 41 | |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame^] | 42 | if [ "$category" == "$category_boards" ]; then |
| 43 | repo_path=$repo_path/$BOARD |
| 44 | fi |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 45 | # Generate root Kconfig |
| 46 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 47 | 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.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame^] | 53 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 54 | echo "source \"$repo_path/Kconfig\"" >> $kconfig_file |
| 55 | last_category=$category |
| 56 | fi |
| 57 | fi |
| 58 | done < "$input" |
| 59 | |
| 60 | echo "endmenu" >> $kconfig_file |