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 | 9a38224 | 2022-04-11 18:46:32 +0800 | [diff] [blame] | 14 | build_dir="build_system" |
| 15 | exclude_dirs="boot 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 | |
bin.chen | 009b21e | 2024-04-30 15:38:32 +0800 | [diff] [blame] | 18 | SOC_MANIFEST="$PWD/soc/$ARCH/$SOC/rtos_sdk_manifest.xml" |
Kelvin Zhang | 3290b1c | 2022-05-06 16:41:02 +0800 | [diff] [blame] | 19 | DEFAULT_RTOS_SDK_MANIFEST="$PWD/products/$PRODUCT/rtos_sdk_manifest.xml" |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 20 | RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml" |
Xiaohu.Huang | 02b7f9f | 2022-01-20 18:42:07 +0800 | [diff] [blame] | 21 | 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] | 22 | STAMP="$kernel_BUILD_DIR/.stamp" |
Kelvin Zhang | 11a7238 | 2024-05-13 14:10:58 +0800 | [diff] [blame] | 23 | RTOS_SDK_VERSION_FILE="$kernel_BUILD_DIR/sdk_ver.h" |
Kelvin Zhang | 5374de9 | 2022-01-14 10:35:43 +0800 | [diff] [blame] | 24 | |
Xueling Li | 255a6c1 | 2022-09-06 09:51:45 +0800 | [diff] [blame] | 25 | # Check whether the project is a valid repo |
| 26 | repo manifest 2>&1 | grep -q $build_dir |
Kelvin Zhang | 3290b1c | 2022-05-06 16:41:02 +0800 | [diff] [blame] | 27 | if [ "$?" -ne 0 ]; then |
| 28 | echo "Non-repo source code" |
bin.chen | 009b21e | 2024-04-30 15:38:32 +0800 | [diff] [blame] | 29 | if [ -s $DEFAULT_RTOS_SDK_MANIFEST ]; then |
| 30 | if [ -s $SOC_MANIFEST ]; then |
| 31 | echo "Use specific manifest: $SOC_MANIFEST" |
| 32 | cat $DEFAULT_RTOS_SDK_MANIFEST $SOC_MANIFEST > $RTOS_SDK_MANIFEST_FILE |
fugui.zhang | b6e4ec2 | 2022-12-07 14:58:40 +0800 | [diff] [blame] | 33 | else |
| 34 | echo "Use default manifest: $DEFAULT_RTOS_SDK_MANIFEST" |
| 35 | cp -f $DEFAULT_RTOS_SDK_MANIFEST $RTOS_SDK_MANIFEST_FILE |
| 36 | fi |
Kelvin Zhang | 3290b1c | 2022-05-06 16:41:02 +0800 | [diff] [blame] | 37 | else |
| 38 | echo "Default manifest.xml not found!" |
| 39 | exit 0 |
| 40 | fi |
| 41 | else |
| 42 | echo "Generate manifest.xml" |
| 43 | repo manifest > $RTOS_SDK_MANIFEST_FILE |
| 44 | if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then |
| 45 | echo "Faild to save $RTOS_SDK_MANIFEST_FILE" |
| 46 | exit 1 |
| 47 | fi |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 48 | fi |
Kelvin Zhang | 017fb4c | 2022-01-20 19:48:36 +0800 | [diff] [blame] | 49 | |
Kelvin Zhang | e2e0471 | 2022-02-09 17:39:35 +0800 | [diff] [blame] | 50 | # Get SDK_VERSION |
xiaohu.huang | f4577f7 | 2022-11-08 17:56:02 +0800 | [diff] [blame] | 51 | source scripts/gen_version.sh $RTOS_SDK_VERSION_FILE \ |
| 52 | $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE |
Kelvin Zhang | e2e0471 | 2022-02-09 17:39:35 +0800 | [diff] [blame] | 53 | |
| 54 | if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then |
| 55 | is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)` |
| 56 | if [ -z "$is_update" ]; then |
| 57 | exit 0 |
| 58 | else |
| 59 | echo "Update top Kconfig and CMakelists.txt." |
| 60 | fi |
| 61 | fi |
| 62 | |
| 63 | # Back up manifest.xml |
| 64 | cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE |
Kelvin Zhang | 5374de9 | 2022-01-14 10:35:43 +0800 | [diff] [blame] | 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 |
shijie.xiong | b0afe96 | 2024-01-11 17:23:28 +0800 | [diff] [blame] | 68 | sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE |
| 69 | elif [[ "$PRODUCT" == wcn ]]; then |
| 70 | sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE |
| 71 | sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE |
Kelvin Zhang | 8cc560f | 2021-12-24 20:25:08 +0800 | [diff] [blame] | 72 | else |
| 73 | sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE |
shijie.xiong | b0afe96 | 2024-01-11 17:23:28 +0800 | [diff] [blame] | 74 | sed -i '/path="drivers_wcncpu"/d' $RTOS_SDK_MANIFEST_FILE |
Kelvin Zhang | 8cc560f | 2021-12-24 20:25:08 +0800 | [diff] [blame] | 75 | fi |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 76 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 77 | # Write the fixed content to CMakeLists.txt |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 78 | cat <<EOF > $cmake_file |
| 79 | enable_language(C CXX ASM) |
| 80 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 81 | EOF |
| 82 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 83 | # Clear Kconfig |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 84 | cat <<EOF > $kconfig_file |
| 85 | EOF |
| 86 | |
kelvin.zhang | 83a4aa3 | 2022-04-08 15:48:35 +0800 | [diff] [blame] | 87 | # Figure out the $relative_dir and its column |
Kelvin Zhang | ecaacb3 | 2022-05-09 10:10:56 +0800 | [diff] [blame] | 88 | [ -z "$REPO_DIR" ] && REPO_DIR=$PWD |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 89 | pattern="path=" |
| 90 | i=0 |
Kelvin Zhang | 9a38224 | 2022-04-11 18:46:32 +0800 | [diff] [blame] | 91 | keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE` |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 92 | for keyword in $keyline; do |
| 93 | let i++ |
| 94 | if [[ $keyword == $pattern* ]]; then |
| 95 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
| 96 | relative_dir=`dirname $repo_path` |
kelvin.zhang | 83a4aa3 | 2022-04-08 15:48:35 +0800 | [diff] [blame] | 97 | # Filter current project |
Kelvin Zhang | ecaacb3 | 2022-05-09 10:10:56 +0800 | [diff] [blame] | 98 | if [[ $REPO_DIR == *$relative_dir ]]; then |
kelvin.zhang | 83a4aa3 | 2022-04-08 15:48:35 +0800 | [diff] [blame] | 99 | break |
| 100 | fi |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 101 | fi |
| 102 | done |
| 103 | |
| 104 | if [[ $relative_dir == . ]]; then |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 105 | pattern="path=" |
| 106 | else |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 107 | pattern="path=\"${relative_dir}/" |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 108 | fi |
| 109 | |
Kelvin Zhang | d931bc3 | 2022-11-23 10:21:55 +0800 | [diff] [blame] | 110 | # Sort manifest.xml based on "path" to get an reasonable order for generating Kconfig |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 111 | sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE |
| 112 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 113 | while IFS= read -r line |
| 114 | do |
kelvin.zhang | 83a4aa3 | 2022-04-08 15:48:35 +0800 | [diff] [blame] | 115 | keyline=`echo "$line" | grep "$pattern"` |
Kelvin Zhang | ecaacb3 | 2022-05-09 10:10:56 +0800 | [diff] [blame] | 116 | [ -z "$keyline" ] && continue |
kelvin.zhang | 83a4aa3 | 2022-04-08 15:48:35 +0800 | [diff] [blame] | 117 | |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 118 | for keyword in $keyline; do |
| 119 | if [[ $keyword == path=* ]]; then |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 120 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 121 | |
Kelvin Zhang | 22cb55e | 2022-06-08 20:21:00 +0800 | [diff] [blame] | 122 | if [[ $repo_path == drivers* ]] || [[ $repo_path == benchmark* ]]; then |
Kelvin Zhang | 20fb7ec | 2021-12-28 10:30:55 +0800 | [diff] [blame] | 123 | category=`basename $repo_path | sed 's/_/ /g'` |
| 124 | category=`echo $category | sed "s/ $PRODUCT//g"` |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 125 | else |
| 126 | category=`dirname $repo_path` |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 127 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 128 | |
Kelvin Zhang | 9a38224 | 2022-04-11 18:46:32 +0800 | [diff] [blame] | 129 | # exclude some dirs |
| 130 | skip_flag=0 |
| 131 | for exclude_dir in $exclude_dirs; do |
| 132 | if [[ $repo_path == $exclude_dir* ]]; then |
| 133 | skip_flag=1 |
| 134 | break |
| 135 | fi |
| 136 | done |
| 137 | [ "$skip_flag" -eq 1 ] && continue |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 138 | |
Kelvin Zhang | aed1316 | 2022-01-11 16:31:13 +0800 | [diff] [blame] | 139 | # substitute ARCH dirs with viarable |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 140 | case $special_dirs in |
| 141 | *"$category"*) arch=`basename $repo_path` |
| 142 | if [ "$arch" == "$ARCH" ]; then |
| 143 | cmake_path="$category/\${ARCH}" |
Kelvin Zhang | ce736e6 | 2022-03-02 14:17:40 +0800 | [diff] [blame] | 144 | kconfig_path="$category/\${ARCH}" |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 145 | else |
| 146 | continue |
| 147 | fi;; |
| 148 | * ) cmake_path=$repo_path |
| 149 | kconfig_path=$repo_path;; |
| 150 | esac |
| 151 | |
shijie.xiong | b0afe96 | 2024-01-11 17:23:28 +0800 | [diff] [blame] | 152 | # multiple types of SoC states |
| 153 | if [ ! -n "$SPLIT_ARCH_DIR" ] && [[ $cmake_path == *"/riscv/"* ]]; then |
| 154 | continue |
| 155 | elif [[ $cmake_path == *"/riscv/"* ]] && [[ ! $cmake_path == *"/riscv/$SPLIT_ARCH_DIR"* ]]; then |
| 156 | continue |
| 157 | fi |
| 158 | |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 159 | # Generate root CMakeLists.txt |
| 160 | if [ -f $repo_path/CMakeLists.txt ]; then |
| 161 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
| 162 | fi |
| 163 | |
| 164 | # Generate root Kconfig |
| 165 | if [ -f $repo_path/Kconfig ]; then |
| 166 | if [ "$last_category" != "$category" ]; then |
| 167 | if [ -n "$last_category" ]; then |
| 168 | echo -e "endmenu\n" >> $kconfig_file |
| 169 | fi |
Kelvin Zhang | 2493942 | 2022-01-06 13:52:10 +0800 | [diff] [blame] | 170 | |
Kelvin Zhang | ce29a71 | 2022-06-09 17:25:22 +0800 | [diff] [blame] | 171 | if [ "$category" == "wcn" -o "$category" == "soc" ]; then |
Kelvin Zhang | 2493942 | 2022-01-06 13:52:10 +0800 | [diff] [blame] | 172 | echo "menu \"${category^^} Options\"" >> $kconfig_file |
| 173 | else |
| 174 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 175 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 176 | fi |
| 177 | |
| 178 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
| 179 | last_category=$category |
| 180 | fi |
| 181 | break; |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 182 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 183 | done |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 184 | done < "$RTOS_SDK_MANIFEST_FILE" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 185 | |
| 186 | echo "endmenu" >> $kconfig_file |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 187 | |
Kelvin Zhang | 5545700 | 2021-12-29 14:26:17 +0800 | [diff] [blame] | 188 | sleep 1 |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 189 | touch $STAMP |