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 | |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame^] | 38 | absolute_prj_dir=`echo ${input%.repo*}` |
| 39 | if [[ $absolute_prj_dir == $PWD/ ]] ; then |
| 40 | pattern="path=" |
| 41 | else |
| 42 | relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}}` |
| 43 | pattern="path=\"${relative_prj_dir}/" |
| 44 | fi |
| 45 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 46 | while IFS= read -r line |
| 47 | do |
| 48 | keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 49 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 50 | if [ $keyword ]; then |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame^] | 51 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 52 | if [[ $repo_path == $drivers_dir* ]] ; then |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame] | 53 | category=$repo_path |
| 54 | else |
| 55 | category=`dirname $repo_path` |
| 56 | fi |
| 57 | |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 58 | if [[ $repo_path == $exclude_dir/* ]] ; then |
| 59 | continue |
| 60 | fi |
| 61 | |
| 62 | # exclude other ARCH dirs |
| 63 | case $special_dirs in |
| 64 | *"$category"*) arch=`basename $repo_path` |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 65 | if [ "$arch" == "$ARCH" ]; then |
| 66 | cmake_path="$category/\${ARCH}" |
| 67 | kconfig_path="$category/\$(ARCH)" |
| 68 | else |
| 69 | continue |
| 70 | fi;; |
| 71 | * ) cmake_path=$repo_path |
| 72 | kconfig_path=$repo_path;; |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 73 | esac |
| 74 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 75 | # Generate root CMakeLists.txt |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 76 | if [ -f $repo_path/CMakeLists.txt ]; then |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 77 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 78 | fi |
| 79 | |
| 80 | # Generate root Kconfig |
| 81 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 82 | if [ "$last_category" != "$category" ]; then |
| 83 | if [ $last_category ]; then |
| 84 | echo -e "endmenu\n" >> $kconfig_file |
| 85 | fi |
| 86 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 87 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 88 | |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 89 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 90 | last_category=$category |
| 91 | fi |
| 92 | fi |
| 93 | done < "$input" |
| 94 | |
| 95 | echo "endmenu" >> $kconfig_file |