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 | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame^] | 9 | category_pattern="drivers" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 10 | |
| 11 | cat <<EOF > $cmake_file |
| 12 | enable_language(C CXX ASM) |
| 13 | |
| 14 | target_include_directories( |
| 15 | \${TARGET_NAME} |
| 16 | PUBLIC |
| 17 | include |
| 18 | ) |
| 19 | |
| 20 | EOF |
| 21 | |
| 22 | cat <<EOF > $kconfig_file |
| 23 | EOF |
| 24 | |
| 25 | while IFS= read -r line |
| 26 | do |
| 27 | keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'` |
| 28 | if [ $keyword ]; then |
| 29 | repo_path=`echo ${keyword#*path=} | sed 's/\"//g'` |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame^] | 30 | if [ "$repo_path" == "$category_pattern" ]; then |
| 31 | category=$repo_path |
| 32 | else |
| 33 | category=`dirname $repo_path` |
| 34 | fi |
| 35 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 36 | # Generate root CMakeLists.txt |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 37 | if [ -f $repo_path/CMakeLists.txt ] && [ "$category" != "$exclude_dir" ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 38 | echo "add_subdirectory($repo_path)" >> $cmake_file |
| 39 | fi |
| 40 | |
| 41 | # Generate root Kconfig |
| 42 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 43 | if [ "$last_category" != "$category" ]; then |
| 44 | if [ $last_category ]; then |
| 45 | echo -e "endmenu\n" >> $kconfig_file |
| 46 | fi |
| 47 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 48 | fi |
| 49 | echo "source \"$repo_path/Kconfig\"" >> $kconfig_file |
| 50 | last_category=$category |
| 51 | fi |
| 52 | fi |
| 53 | done < "$input" |
| 54 | |
| 55 | echo "endmenu" >> $kconfig_file |