blob: 25b9411895254b65a93f9b5e2631584cded684ae [file] [log] [blame]
kelvin.zhangac22e652021-10-18 15:09:21 +08001#!/bin/bash
yang.li09520922022-01-12 15:51:51 +08002#
yang.liffa60e52022-01-11 14:38:56 +08003# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
yang.li09520922022-01-12 15:51:51 +08004#
yang.liffa60e52022-01-11 14:38:56 +08005# SPDX-License-Identifier: MIT
yang.li09520922022-01-12 15:51:51 +08006#
yang.liffa60e52022-01-11 14:38:56 +08007
kelvin.zhangf91d7b02021-10-26 16:47:17 +08008###############################################################
9# Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml.
10###############################################################
kelvin.zhangac22e652021-10-18 15:09:21 +080011
kelvin.zhangf91d7b02021-10-26 16:47:17 +080012cmake_file="$PWD/CMakeLists.txt"
13kconfig_file="$PWD/Kconfig"
Kelvin Zhang9a382242022-04-11 18:46:32 +080014build_dir="build_system"
15exclude_dirs="boot products docs"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080016special_dirs="arch soc boards"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080017
18RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +080019RTOS_SDK_MANIFEST_OLD_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest_old.xml"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080020STAMP="$kernel_BUILD_DIR/.stamp"
21
Kelvin Zhang5374de92022-01-14 10:35:43 +080022[ -n "$1" ] && BUILD_DIR=$1;
23RTOS_SDK_VERSION_FILE="$BUILD_DIR/sdk_ver.h"
24
25#COMPILE_TIME="$(shell date +%g.%V.%u" "%H:%M:%S)"
26COMPILE_TIME=`date +%F" "%T`
27
Kelvin Zhange2e04712022-02-09 17:39:35 +080028echo "#define CONFIG_BOARD_NAME \"$BOARD\"" > $RTOS_SDK_VERSION_FILE
29echo "#define CONFIG_PRODUCT_NAME \"$PRODUCT\"" >> $RTOS_SDK_VERSION_FILE
30echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
31
Kelvin Zhange87f5192021-12-30 16:59:12 +080032# Check whether the project is a repo
33repo manifest >/dev/null 2>&1
Kelvin Zhange2e04712022-02-09 17:39:35 +080034[ "$?" -ne 0 ] && echo "Non-repo source code" && exit 0
Kelvin Zhange87f5192021-12-30 16:59:12 +080035
Kelvin Zhang33a3a872021-12-09 15:29:20 +080036# Generate manifest.xml
37repo manifest > $RTOS_SDK_MANIFEST_FILE
38if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
39 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
40 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080041fi
Kelvin Zhang69dc9fb2022-02-18 16:44:04 +080042cp -f $RTOS_SDK_MANIFEST_FILE $kernel_BUILD_DIR/../manifest.xml
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080043
Kelvin Zhange2e04712022-02-09 17:39:35 +080044# Get SDK_VERSION
Kelvin Zhang5374de92022-01-14 10:35:43 +080045pattern="revision="
46keyline=`grep 'default .* revision' $RTOS_SDK_MANIFEST_FILE`
47for keyword in $keyline; do
48 let i++
49 if [[ $keyword == $pattern* ]]; then
50 SDK_VERSION=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
51 break;
52 fi
53done
Kelvin Zhange2e04712022-02-09 17:39:35 +080054echo "#define CONFIG_VERSION_STRING \"$SDK_VERSION\"" >> $RTOS_SDK_VERSION_FILE
55
56if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
57 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
58 if [ -z "$is_update" ]; then
59 exit 0
60 else
61 echo "Update top Kconfig and CMakelists.txt."
62 fi
63fi
64
65# Back up manifest.xml
66cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhang5374de92022-01-14 10:35:43 +080067
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080068if [[ "$PRODUCT" == aocpu ]]; then
69 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
70else
71 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
72fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080073
Kelvin Zhang33a3a872021-12-09 15:29:20 +080074# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080075cat <<EOF > $cmake_file
76enable_language(C CXX ASM)
77
kelvin.zhangac22e652021-10-18 15:09:21 +080078EOF
79
Kelvin Zhang33a3a872021-12-09 15:29:20 +080080# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080081cat <<EOF > $kconfig_file
82EOF
83
kelvin.zhang83a4aa32022-04-08 15:48:35 +080084# Figure out the $relative_dir and its column
Kelvin Zhang33a3a872021-12-09 15:29:20 +080085pattern="path="
86i=0
Kelvin Zhang9a382242022-04-11 18:46:32 +080087keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080088for 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`
kelvin.zhang83a4aa32022-04-08 15:48:35 +080093 # Filter current project
94 if [[ $PWD == *$relative_dir ]]; then
95 break
96 fi
Kelvin Zhang33a3a872021-12-09 15:29:20 +080097 fi
98done
99
100if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800101 pattern="path="
102else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800103 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800104fi
105
Kelvin Zhange2e04712022-02-09 17:39:35 +0800106# Sort manifest.xml of RTOS SDK
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800107sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
108
kelvin.zhangac22e652021-10-18 15:09:21 +0800109while IFS= read -r line
110do
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800111 keyline=`echo "$line" | grep "$pattern"`
112 if [ -z "$keyline" ]; then
113 continue
114 fi
115
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800116 for keyword in $keyline; do
117 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800118 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800119
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800120 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
121 category=`basename $repo_path | sed 's/_/ /g'`
122 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800123 else
124 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800125 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800126
Kelvin Zhang9a382242022-04-11 18:46:32 +0800127 # exclude some dirs
128 skip_flag=0
129 for exclude_dir in $exclude_dirs; do
130 if [[ $repo_path == $exclude_dir* ]]; then
131 skip_flag=1
132 break
133 fi
134 done
135 [ "$skip_flag" -eq 1 ] && continue
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800136
Kelvin Zhangaed13162022-01-11 16:31:13 +0800137 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800138 case $special_dirs in
139 *"$category"*) arch=`basename $repo_path`
140 if [ "$arch" == "$ARCH" ]; then
141 cmake_path="$category/\${ARCH}"
Kelvin Zhangce736e62022-03-02 14:17:40 +0800142 kconfig_path="$category/\${ARCH}"
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800143 else
144 continue
145 fi;;
146 * ) cmake_path=$repo_path
147 kconfig_path=$repo_path;;
148 esac
149
150 # Generate root CMakeLists.txt
151 if [ -f $repo_path/CMakeLists.txt ]; then
152 echo "add_subdirectory($cmake_path)" >> $cmake_file
153 fi
154
155 # Generate root Kconfig
156 if [ -f $repo_path/Kconfig ]; then
157 if [ "$last_category" != "$category" ]; then
158 if [ -n "$last_category" ]; then
159 echo -e "endmenu\n" >> $kconfig_file
160 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800161
162 if [ "$category" == "wcn" ]; then
163 echo "menu \"${category^^} Options\"" >> $kconfig_file
164 else
165 echo "menu \"${category^} Options\"" >> $kconfig_file
166 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800167 fi
168
169 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
170 last_category=$category
171 fi
172 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800173 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800174 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800175done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800176
177echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800178
Kelvin Zhang55457002021-12-29 14:26:17 +0800179sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800180touch $STAMP