kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame^] | 3 | ############################################################### |
| 4 | # Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml. |
| 5 | ############################################################### |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 6 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame^] | 7 | if [ -n "$1" ]; then |
| 8 | input=$1 |
| 9 | else |
| 10 | input="$PWD/.repo/manifests/default.xml" |
| 11 | fi |
| 12 | |
| 13 | if [ ! -f $1 ]; then |
| 14 | echo "No such file: $input" |
| 15 | exit 1 |
| 16 | fi |
| 17 | |
| 18 | cmake_file="$PWD/CMakeLists.txt" |
| 19 | kconfig_file="$PWD/Kconfig" |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 20 | exclude_dir="products" |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 21 | special_dirs="arch soc boards" |
| 22 | drivers_dir="drivers" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 23 | |
| 24 | cat <<EOF > $cmake_file |
| 25 | enable_language(C CXX ASM) |
| 26 | |
| 27 | target_include_directories( |
| 28 | \${TARGET_NAME} |
| 29 | PUBLIC |
| 30 | include |
| 31 | ) |
| 32 | |
| 33 | EOF |
| 34 | |
| 35 | cat <<EOF > $kconfig_file |
| 36 | EOF |
| 37 | |
| 38 | while IFS= read -r line |
| 39 | do |
| 40 | keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 41 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 42 | if [ $keyword ]; then |
| 43 | repo_path=`echo ${keyword#*path=} | sed 's/\"//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 44 | if [[ $repo_path == $drivers_dir* ]] ; then |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame] | 45 | category=$repo_path |
| 46 | else |
| 47 | category=`dirname $repo_path` |
| 48 | fi |
| 49 | |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 50 | if [[ $repo_path == $exclude_dir/* ]] ; then |
| 51 | continue |
| 52 | fi |
| 53 | |
| 54 | # exclude other ARCH dirs |
| 55 | case $special_dirs in |
| 56 | *"$category"*) arch=`basename $repo_path` |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 57 | if [ "$arch" == "$ARCH" ]; then |
| 58 | cmake_path="$category/\${ARCH}" |
| 59 | kconfig_path="$category/\$(ARCH)" |
| 60 | else |
| 61 | continue |
| 62 | fi;; |
| 63 | * ) cmake_path=$repo_path |
| 64 | kconfig_path=$repo_path;; |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 65 | esac |
| 66 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 67 | # Generate root CMakeLists.txt |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 68 | if [ -f $repo_path/CMakeLists.txt ]; then |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 69 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 70 | fi |
| 71 | |
| 72 | # Generate root Kconfig |
| 73 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 74 | if [ "$last_category" != "$category" ]; then |
| 75 | if [ $last_category ]; then |
| 76 | echo -e "endmenu\n" >> $kconfig_file |
| 77 | fi |
| 78 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 79 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 80 | |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 81 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 82 | last_category=$category |
| 83 | fi |
| 84 | fi |
| 85 | done < "$input" |
| 86 | |
| 87 | echo "endmenu" >> $kconfig_file |