kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 1 | #!/bin/bash |
yang.li | 0952092 | 2022-01-12 15:51:51 +0800 | [diff] [blame] | 2 | # |
yang.li | ffa60e5 | 2022-01-11 14:38:56 +0800 | [diff] [blame] | 3 | # Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
yang.li | 0952092 | 2022-01-12 15:51:51 +0800 | [diff] [blame] | 4 | # |
yang.li | ffa60e5 | 2022-01-11 14:38:56 +0800 | [diff] [blame] | 5 | # SPDX-License-Identifier: MIT |
yang.li | 0952092 | 2022-01-12 15:51:51 +0800 | [diff] [blame] | 6 | # |
yang.li | ffa60e5 | 2022-01-11 14:38:56 +0800 | [diff] [blame] | 7 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame] | 8 | ############################################################### |
| 9 | # Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml. |
| 10 | ############################################################### |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 11 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame] | 12 | cmake_file="$PWD/CMakeLists.txt" |
| 13 | kconfig_file="$PWD/Kconfig" |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 14 | build_dir="build" |
Kelvin Zhang | aed1316 | 2022-01-11 16:31:13 +0800 | [diff] [blame] | 15 | exclude_dir="products docs" |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 16 | special_dirs="arch soc boards" |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 17 | |
| 18 | RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml" |
Xiaohu.Huang | 02b7f9f | 2022-01-20 18:42:07 +0800 | [diff] [blame] | 19 | RTOS_SDK_MANIFEST_OLD_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest_old.xml" |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 20 | STAMP="$kernel_BUILD_DIR/.stamp" |
| 21 | |
Kelvin Zhang | 5374de9 | 2022-01-14 10:35:43 +0800 | [diff] [blame] | 22 | [ -n "$1" ] && BUILD_DIR=$1; |
| 23 | RTOS_SDK_VERSION_FILE="$BUILD_DIR/sdk_ver.h" |
| 24 | |
| 25 | #COMPILE_TIME="$(shell date +%g.%V.%u" "%H:%M:%S)" |
| 26 | COMPILE_TIME=`date +%F" "%T` |
| 27 | |
Kelvin Zhang | e87f519 | 2021-12-30 16:59:12 +0800 | [diff] [blame] | 28 | # Check whether the project is a repo |
| 29 | repo manifest >/dev/null 2>&1 |
| 30 | [ "$?" -ne 0 ] && exit 0 |
| 31 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 32 | # Generate manifest.xml |
| 33 | repo manifest > $RTOS_SDK_MANIFEST_FILE |
| 34 | if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then |
| 35 | echo "Faild to save $RTOS_SDK_MANIFEST_FILE" |
| 36 | exit 1 |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 37 | fi |
Kelvin Zhang | 017fb4c | 2022-01-20 19:48:36 +0800 | [diff] [blame^] | 38 | |
| 39 | cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE |
| 40 | |
| 41 | if [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then |
| 42 | is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)` |
| 43 | if [ -z "$is_update" ]; then |
Xiaohu.Huang | 02b7f9f | 2022-01-20 18:42:07 +0800 | [diff] [blame] | 44 | sed -i '/#define CONFIG_COMPILE_TIME/d' $RTOS_SDK_VERSION_FILE |
| 45 | echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE |
| 46 | exit 0 |
| 47 | else |
| 48 | echo "Update top Kconfig and CMakelists.txt." |
| 49 | fi |
| 50 | fi |
Kelvin Zhang | 20fb7ec | 2021-12-28 10:30:55 +0800 | [diff] [blame] | 51 | |
Kelvin Zhang | 5374de9 | 2022-01-14 10:35:43 +0800 | [diff] [blame] | 52 | pattern="revision=" |
| 53 | keyline=`grep 'default .* revision' $RTOS_SDK_MANIFEST_FILE` |
| 54 | for keyword in $keyline; do |
| 55 | let i++ |
| 56 | if [[ $keyword == $pattern* ]]; then |
| 57 | SDK_VERSION=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
| 58 | break; |
| 59 | fi |
| 60 | done |
| 61 | echo "#define CONFIG_VERSION_STRING \"$SDK_VERSION\"" > $RTOS_SDK_VERSION_FILE |
| 62 | echo "#define CONFIG_BOARD_NAME \"$BOARD\"" >> $RTOS_SDK_VERSION_FILE |
| 63 | echo "#define CONFIG_PRODUCT_NAME \"$PRODUCT\"" >> $RTOS_SDK_VERSION_FILE |
| 64 | echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE |
| 65 | |
Kelvin Zhang | 8cc560f | 2021-12-24 20:25:08 +0800 | [diff] [blame] | 66 | if [[ "$PRODUCT" == aocpu ]]; then |
| 67 | sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE |
| 68 | else |
| 69 | sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE |
| 70 | fi |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 71 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 72 | # Write the fixed content to CMakeLists.txt |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 73 | cat <<EOF > $cmake_file |
| 74 | enable_language(C CXX ASM) |
| 75 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 76 | EOF |
| 77 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 78 | # Clear Kconfig |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 79 | cat <<EOF > $kconfig_file |
| 80 | EOF |
| 81 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 82 | # filter manifest.xml of RTOS SDK |
| 83 | sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE |
| 84 | # figure out the $relative_dir and its column |
| 85 | pattern="path=" |
| 86 | i=0 |
kelvin.zhang | 8946de2 | 2022-01-14 21:44:47 +0800 | [diff] [blame] | 87 | keyline=`grep 'path=".*build_system"' $RTOS_SDK_MANIFEST_FILE` |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 88 | for keyword in $keyline; do |
| 89 | let i++ |
| 90 | if [[ $keyword == $pattern* ]]; then |
| 91 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
| 92 | relative_dir=`dirname $repo_path` |
| 93 | break; |
| 94 | fi |
| 95 | done |
| 96 | |
| 97 | if [[ $relative_dir == . ]]; then |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 98 | pattern="path=" |
| 99 | else |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 100 | pattern="path=\"${relative_dir}/" |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 101 | fi |
| 102 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 103 | # sort manifest.xml of RTOS SDK |
| 104 | sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE |
| 105 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 106 | while IFS= read -r line |
| 107 | do |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 108 | keyline=`echo "$line" | grep 'name=.* path='` |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 109 | for keyword in $keyline; do |
| 110 | if [[ $keyword == path=* ]]; then |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 111 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 112 | |
Kelvin Zhang | 20fb7ec | 2021-12-28 10:30:55 +0800 | [diff] [blame] | 113 | if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then |
| 114 | category=`basename $repo_path | sed 's/_/ /g'` |
| 115 | category=`echo $category | sed "s/ $PRODUCT//g"` |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 116 | else |
| 117 | category=`dirname $repo_path` |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 118 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 119 | |
Kelvin Zhang | aed1316 | 2022-01-11 16:31:13 +0800 | [diff] [blame] | 120 | # exclude other ARCH dirs |
| 121 | if [[ $repo_path == docs* ]] || [[ $repo_path == products* ]]; then |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 122 | continue |
| 123 | fi |
| 124 | |
Kelvin Zhang | aed1316 | 2022-01-11 16:31:13 +0800 | [diff] [blame] | 125 | # substitute ARCH dirs with viarable |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 126 | case $special_dirs in |
| 127 | *"$category"*) arch=`basename $repo_path` |
| 128 | if [ "$arch" == "$ARCH" ]; then |
| 129 | cmake_path="$category/\${ARCH}" |
| 130 | kconfig_path="$category/\$(ARCH)" |
| 131 | else |
| 132 | continue |
| 133 | fi;; |
| 134 | * ) cmake_path=$repo_path |
| 135 | kconfig_path=$repo_path;; |
| 136 | esac |
| 137 | |
| 138 | # Generate root CMakeLists.txt |
| 139 | if [ -f $repo_path/CMakeLists.txt ]; then |
| 140 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
| 141 | fi |
| 142 | |
| 143 | # Generate root Kconfig |
| 144 | if [ -f $repo_path/Kconfig ]; then |
| 145 | if [ "$last_category" != "$category" ]; then |
| 146 | if [ -n "$last_category" ]; then |
| 147 | echo -e "endmenu\n" >> $kconfig_file |
| 148 | fi |
Kelvin Zhang | 2493942 | 2022-01-06 13:52:10 +0800 | [diff] [blame] | 149 | |
| 150 | if [ "$category" == "wcn" ]; then |
| 151 | echo "menu \"${category^^} Options\"" >> $kconfig_file |
| 152 | else |
| 153 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 154 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 155 | fi |
| 156 | |
| 157 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
| 158 | last_category=$category |
| 159 | fi |
| 160 | break; |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 161 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 162 | done |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 163 | done < "$RTOS_SDK_MANIFEST_FILE" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 164 | |
| 165 | echo "endmenu" >> $kconfig_file |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 166 | |
Kelvin Zhang | 5545700 | 2021-12-29 14:26:17 +0800 | [diff] [blame] | 167 | sleep 1 |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 168 | touch $STAMP |