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 | cmake_file="$PWD/CMakeLists.txt" |
| 8 | kconfig_file="$PWD/Kconfig" |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 9 | exclude_dir="products" |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 10 | special_dirs="arch soc boards" |
| 11 | drivers_dir="drivers" |
kelvin.zhang | 4b98547 | 2021-10-27 16:02:21 +0800 | [diff] [blame^] | 12 | dir=$PWD |
| 13 | |
| 14 | if [ -n "$1" ]; then |
| 15 | file_name=$1 |
| 16 | else |
| 17 | file_name="default.xml" |
| 18 | fi |
| 19 | |
| 20 | while : ; do |
| 21 | if [[ -n $(find $dir/.repo -name $file_name 2>/dev/null) ]]; then |
| 22 | file_path=`find $dir/.repo -name $file_name` |
| 23 | break |
| 24 | fi |
| 25 | dir=`dirname $dir` |
| 26 | mountpoint -q $dir |
| 27 | [ $? -eq 0 ] && break; |
| 28 | done |
| 29 | |
| 30 | if [ ! -f $file_path ]; then |
| 31 | echo "No such file: $file_name" |
| 32 | exit 1 |
| 33 | fi |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 34 | |
| 35 | cat <<EOF > $cmake_file |
| 36 | enable_language(C CXX ASM) |
| 37 | |
| 38 | target_include_directories( |
| 39 | \${TARGET_NAME} |
| 40 | PUBLIC |
| 41 | include |
| 42 | ) |
| 43 | |
| 44 | EOF |
| 45 | |
| 46 | cat <<EOF > $kconfig_file |
| 47 | EOF |
| 48 | |
kelvin.zhang | 4b98547 | 2021-10-27 16:02:21 +0800 | [diff] [blame^] | 49 | absolute_prj_dir=$dir |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 50 | if [[ $absolute_prj_dir == $PWD/ ]] ; then |
| 51 | pattern="path=" |
| 52 | else |
kelvin.zhang | 4b98547 | 2021-10-27 16:02:21 +0800 | [diff] [blame^] | 53 | relative_prj_dir=`echo ${PWD#*${absolute_prj_dir}/}` |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 54 | pattern="path=\"${relative_prj_dir}/" |
| 55 | fi |
| 56 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 57 | while IFS= read -r line |
| 58 | do |
| 59 | keyword=`echo "$line" | grep 'path=.* name=' | awk '{print $2}'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 60 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 61 | if [ $keyword ]; then |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 62 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 63 | if [[ $repo_path == $drivers_dir* ]] ; then |
kelvin.zhang | c35b076 | 2021-10-20 15:41:46 +0800 | [diff] [blame] | 64 | category=$repo_path |
| 65 | else |
| 66 | category=`dirname $repo_path` |
| 67 | fi |
| 68 | |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 69 | if [[ $repo_path == $exclude_dir/* ]] ; then |
| 70 | continue |
| 71 | fi |
| 72 | |
| 73 | # exclude other ARCH dirs |
| 74 | case $special_dirs in |
| 75 | *"$category"*) arch=`basename $repo_path` |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 76 | if [ "$arch" == "$ARCH" ]; then |
| 77 | cmake_path="$category/\${ARCH}" |
| 78 | kconfig_path="$category/\$(ARCH)" |
| 79 | else |
| 80 | continue |
| 81 | fi;; |
| 82 | * ) cmake_path=$repo_path |
| 83 | kconfig_path=$repo_path;; |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 84 | esac |
| 85 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 86 | # Generate root CMakeLists.txt |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 87 | if [ -f $repo_path/CMakeLists.txt ]; then |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 88 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 89 | fi |
| 90 | |
| 91 | # Generate root Kconfig |
| 92 | if [ -f $repo_path/Kconfig ]; then |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 93 | if [ "$last_category" != "$category" ]; then |
| 94 | if [ $last_category ]; then |
| 95 | echo -e "endmenu\n" >> $kconfig_file |
| 96 | fi |
| 97 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 98 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 99 | |
kelvin.zhang | 53cdc1e | 2021-10-21 15:28:36 +0800 | [diff] [blame] | 100 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 101 | last_category=$category |
| 102 | fi |
| 103 | fi |
kelvin.zhang | 4b98547 | 2021-10-27 16:02:21 +0800 | [diff] [blame^] | 104 | done < "$file_path" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 105 | |
| 106 | echo "endmenu" >> $kconfig_file |