kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
yang.li | ffa60e5 | 2022-01-11 14:38:56 +0800 | [diff] [blame^] | 3 | # Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 4 | |
| 5 | # SPDX-License-Identifier: MIT |
| 6 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame] | 7 | ############################################################### |
| 8 | # Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml. |
| 9 | ############################################################### |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 10 | |
kelvin.zhang | f91d7b0 | 2021-10-26 16:47:17 +0800 | [diff] [blame] | 11 | cmake_file="$PWD/CMakeLists.txt" |
| 12 | kconfig_file="$PWD/Kconfig" |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 13 | build_dir="build" |
kelvin.zhang | 6010709 | 2021-10-19 18:12:39 +0800 | [diff] [blame] | 14 | exclude_dir="products" |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 15 | special_dirs="arch soc boards" |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 16 | |
| 17 | RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml" |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 18 | STAMP="$kernel_BUILD_DIR/.stamp" |
| 19 | |
Kelvin Zhang | e87f519 | 2021-12-30 16:59:12 +0800 | [diff] [blame] | 20 | # Check whether the project is a repo |
| 21 | repo manifest >/dev/null 2>&1 |
| 22 | [ "$?" -ne 0 ] && exit 0 |
| 23 | |
Kelvin Zhang | 875831b | 2022-01-07 10:48:50 +0800 | [diff] [blame] | 24 | if [ -s $RTOS_SDK_MANIFEST_FILE ] && [ -s $kconfig_file ] && [ $PWD/Makefile -ot $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 25 | exit 0 |
| 26 | fi |
kelvin.zhang | 4b98547 | 2021-10-27 16:02:21 +0800 | [diff] [blame] | 27 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 28 | # Generate manifest.xml |
| 29 | repo manifest > $RTOS_SDK_MANIFEST_FILE |
| 30 | if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then |
| 31 | echo "Faild to save $RTOS_SDK_MANIFEST_FILE" |
| 32 | exit 1 |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 33 | fi |
Kelvin Zhang | 20fb7ec | 2021-12-28 10:30:55 +0800 | [diff] [blame] | 34 | |
Kelvin Zhang | 8cc560f | 2021-12-24 20:25:08 +0800 | [diff] [blame] | 35 | if [[ "$PRODUCT" == aocpu ]]; then |
| 36 | sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE |
| 37 | else |
| 38 | sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE |
| 39 | fi |
kelvin.zhang | bdb01dd | 2021-11-02 10:14:45 +0800 | [diff] [blame] | 40 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 41 | # Write the fixed content to CMakeLists.txt |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 42 | cat <<EOF > $cmake_file |
| 43 | enable_language(C CXX ASM) |
| 44 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 45 | EOF |
| 46 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 47 | # Clear Kconfig |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 48 | cat <<EOF > $kconfig_file |
| 49 | EOF |
| 50 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 51 | # filter manifest.xml of RTOS SDK |
| 52 | sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE |
| 53 | # figure out the $relative_dir and its column |
| 54 | pattern="path=" |
| 55 | i=0 |
| 56 | keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE` |
| 57 | for keyword in $keyline; do |
| 58 | let i++ |
| 59 | if [[ $keyword == $pattern* ]]; then |
| 60 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
| 61 | relative_dir=`dirname $repo_path` |
| 62 | break; |
| 63 | fi |
| 64 | done |
| 65 | |
| 66 | if [[ $relative_dir == . ]]; then |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 67 | pattern="path=" |
| 68 | else |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 69 | pattern="path=\"${relative_dir}/" |
kelvin.zhang | 9e82d8f | 2021-10-26 20:26:04 +0800 | [diff] [blame] | 70 | fi |
| 71 | |
Kelvin Zhang | 33a3a87 | 2021-12-09 15:29:20 +0800 | [diff] [blame] | 72 | # sort manifest.xml of RTOS SDK |
| 73 | sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE |
| 74 | |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 75 | while IFS= read -r line |
| 76 | do |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 77 | keyline=`echo "$line" | grep 'name=.* path='` |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 78 | for keyword in $keyline; do |
| 79 | if [[ $keyword == path=* ]]; then |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 80 | repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'` |
kelvin.zhang | 5ef541b | 2021-10-21 13:24:48 +0800 | [diff] [blame] | 81 | |
Kelvin Zhang | 20fb7ec | 2021-12-28 10:30:55 +0800 | [diff] [blame] | 82 | if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then |
| 83 | category=`basename $repo_path | sed 's/_/ /g'` |
| 84 | category=`echo $category | sed "s/ $PRODUCT//g"` |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 85 | else |
| 86 | category=`dirname $repo_path` |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 87 | fi |
kelvin.zhang | 78a6671 | 2021-10-20 17:27:41 +0800 | [diff] [blame] | 88 | |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 89 | if [[ $repo_path == $exclude_dir/* ]]; then |
| 90 | continue |
| 91 | fi |
| 92 | |
| 93 | # exclude other ARCH dirs |
| 94 | case $special_dirs in |
| 95 | *"$category"*) arch=`basename $repo_path` |
| 96 | if [ "$arch" == "$ARCH" ]; then |
| 97 | cmake_path="$category/\${ARCH}" |
| 98 | kconfig_path="$category/\$(ARCH)" |
| 99 | else |
| 100 | continue |
| 101 | fi;; |
| 102 | * ) cmake_path=$repo_path |
| 103 | kconfig_path=$repo_path;; |
| 104 | esac |
| 105 | |
| 106 | # Generate root CMakeLists.txt |
| 107 | if [ -f $repo_path/CMakeLists.txt ]; then |
| 108 | echo "add_subdirectory($cmake_path)" >> $cmake_file |
| 109 | fi |
| 110 | |
| 111 | # Generate root Kconfig |
| 112 | if [ -f $repo_path/Kconfig ]; then |
| 113 | if [ "$last_category" != "$category" ]; then |
| 114 | if [ -n "$last_category" ]; then |
| 115 | echo -e "endmenu\n" >> $kconfig_file |
| 116 | fi |
Kelvin Zhang | 2493942 | 2022-01-06 13:52:10 +0800 | [diff] [blame] | 117 | |
| 118 | if [ "$category" == "wcn" ]; then |
| 119 | echo "menu \"${category^^} Options\"" >> $kconfig_file |
| 120 | else |
| 121 | echo "menu \"${category^} Options\"" >> $kconfig_file |
| 122 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 123 | fi |
| 124 | |
| 125 | echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file |
| 126 | last_category=$category |
| 127 | fi |
| 128 | break; |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 129 | fi |
Kelvin Zhang | f441d5e | 2021-12-02 20:37:37 +0800 | [diff] [blame] | 130 | done |
Kelvin Zhang | 25ccae7 | 2021-12-07 16:42:12 +0800 | [diff] [blame] | 131 | done < "$RTOS_SDK_MANIFEST_FILE" |
kelvin.zhang | ac22e65 | 2021-10-18 15:09:21 +0800 | [diff] [blame] | 132 | |
| 133 | echo "endmenu" >> $kconfig_file |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 134 | |
Kelvin Zhang | 5545700 | 2021-12-29 14:26:17 +0800 | [diff] [blame] | 135 | sleep 1 |
Kelvin Zhang | 24a365e | 2021-12-28 15:52:55 +0800 | [diff] [blame] | 136 | touch $STAMP |