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 | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame^] | 9 | special_dirs="arch soc boards" |
| 10 | drivers_dir="drivers" |
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}'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame^] | 29 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 30 | if [ $keyword ]; then |
| 31 | repo_path=`echo ${keyword#*path=} | sed 's/\"//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame^] | 32 | if [[ $repo_path == $drivers_dir* ]] ; then |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame] | 33 | category=$repo_path |
| 34 | else |
| 35 | category=`dirname $repo_path` |
| 36 | fi |
| 37 | |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame^] | 38 | 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` |
| 45 | if [ "$arch" != "$ARCH" ]; then continue; fi;; |
| 46 | esac |
| 47 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 48 | # Generate root CMakeLists.txt |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame^] | 49 | if [ -f $repo_path/CMakeLists.txt ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 50 | echo "add_subdirectory($repo_path)" >> $cmake_file |
| 51 | fi |
| 52 | |
| 53 | # Generate root Kconfig |
| 54 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 55 | if [ "$last_category" != "$category" ]; then |
| 56 | if [ $last_category ]; then |
| 57 | echo -e "endmenu\n" >> $kconfig_file |
| 58 | fi |
| 59 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 60 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 61 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 62 | echo "source \"$repo_path/Kconfig\"" >> $kconfig_file |
| 63 | last_category=$category |
| 64 | fi |
| 65 | fi |
| 66 | done < "$input" |
| 67 | |
| 68 | echo "endmenu" >> $kconfig_file |