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` |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame^] | 45 | if [ "$arch" == "$ARCH" ]; then |
| 46 | cmake_path="$category/\${ARCH}" |
| 47 | kconfig_path="$category/\$(ARCH)" |
| 48 | else |
| 49 | continue |
| 50 | fi;; |
| 51 | * ) cmake_path=$repo_path |
| 52 | kconfig_path=$repo_path;; |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 53 | esac |
| 54 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 55 | # Generate root CMakeLists.txt |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 56 | if [ -f $repo_path/CMakeLists.txt ]; then |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame^] | 57 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 58 | fi |
| 59 | |
| 60 | # Generate root Kconfig |
| 61 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 62 | if [ "$last_category" != "$category" ]; then |
| 63 | if [ $last_category ]; then |
| 64 | echo -e "endmenu\n" >> $kconfig_file |
| 65 | fi |
| 66 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 67 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 68 | |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame^] | 69 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 70 | last_category=$category |
| 71 | fi |
| 72 | fi |
| 73 | done < "$input" |
| 74 | |
| 75 | echo "endmenu" >> $kconfig_file |