blob: da9ac18bfa311503fdf5b2126304e31b36dfbc38 [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
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080018DEFAULT_RTOS_SDK_MANIFEST="$PWD/products/$PRODUCT/rtos_sdk_manifest.xml"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080019RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +080020RTOS_SDK_MANIFEST_OLD_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest_old.xml"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080021STAMP="$kernel_BUILD_DIR/.stamp"
22
Kelvin Zhang5374de92022-01-14 10:35:43 +080023[ -n "$1" ] && BUILD_DIR=$1;
24RTOS_SDK_VERSION_FILE="$BUILD_DIR/sdk_ver.h"
25
26#COMPILE_TIME="$(shell date +%g.%V.%u" "%H:%M:%S)"
27COMPILE_TIME=`date +%F" "%T`
28
Kelvin Zhange2e04712022-02-09 17:39:35 +080029echo "#define CONFIG_BOARD_NAME \"$BOARD\"" > $RTOS_SDK_VERSION_FILE
30echo "#define CONFIG_PRODUCT_NAME \"$PRODUCT\"" >> $RTOS_SDK_VERSION_FILE
31echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
32
Kelvin Zhange87f5192021-12-30 16:59:12 +080033# Check whether the project is a repo
34repo manifest >/dev/null 2>&1
Kelvin Zhang3290b1c2022-05-06 16:41:02 +080035if [ "$?" -ne 0 ]; then
36 echo "Non-repo source code"
37 if [ -f $DEFAULT_RTOS_SDK_MANIFEST ]; then
38 echo "Use default manifest: $DEFAULT_RTOS_SDK_MANIFEST"
39 cp -f $DEFAULT_RTOS_SDK_MANIFEST $RTOS_SDK_MANIFEST_FILE
40 else
41 echo "Default manifest.xml not found!"
42 exit 0
43 fi
44else
45 echo "Generate manifest.xml"
46 repo manifest > $RTOS_SDK_MANIFEST_FILE
47 if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
48 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
49 exit 1
50 fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080051fi
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080052
Kelvin Zhange2e04712022-02-09 17:39:35 +080053# Get SDK_VERSION
Kelvin Zhang5374de92022-01-14 10:35:43 +080054pattern="revision="
55keyline=`grep 'default .* revision' $RTOS_SDK_MANIFEST_FILE`
56for keyword in $keyline; do
57 let i++
58 if [[ $keyword == $pattern* ]]; then
59 SDK_VERSION=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
60 break;
61 fi
62done
Kelvin Zhange2e04712022-02-09 17:39:35 +080063echo "#define CONFIG_VERSION_STRING \"$SDK_VERSION\"" >> $RTOS_SDK_VERSION_FILE
64
65if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
66 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
67 if [ -z "$is_update" ]; then
68 exit 0
69 else
70 echo "Update top Kconfig and CMakelists.txt."
71 fi
72fi
73
74# Back up manifest.xml
75cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
Kelvin Zhang5374de92022-01-14 10:35:43 +080076
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080077if [[ "$PRODUCT" == aocpu ]]; then
78 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
79else
80 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
81fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080082
Kelvin Zhang33a3a872021-12-09 15:29:20 +080083# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080084cat <<EOF > $cmake_file
85enable_language(C CXX ASM)
86
kelvin.zhangac22e652021-10-18 15:09:21 +080087EOF
88
Kelvin Zhang33a3a872021-12-09 15:29:20 +080089# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080090cat <<EOF > $kconfig_file
91EOF
92
kelvin.zhang83a4aa32022-04-08 15:48:35 +080093# Figure out the $relative_dir and its column
Kelvin Zhangecaacb32022-05-09 10:10:56 +080094[ -z "$REPO_DIR" ] && REPO_DIR=$PWD
Kelvin Zhang33a3a872021-12-09 15:29:20 +080095pattern="path="
96i=0
Kelvin Zhang9a382242022-04-11 18:46:32 +080097keyline=`grep "path=\".*$build_dir\"" $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080098for keyword in $keyline; do
99 let i++
100 if [[ $keyword == $pattern* ]]; then
101 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
102 relative_dir=`dirname $repo_path`
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800103 # Filter current project
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800104 if [[ $REPO_DIR == *$relative_dir ]]; then
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800105 break
106 fi
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800107 fi
108done
109
110if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800111 pattern="path="
112else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800113 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800114fi
115
Kelvin Zhange2e04712022-02-09 17:39:35 +0800116# Sort manifest.xml of RTOS SDK
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800117sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
118
kelvin.zhangac22e652021-10-18 15:09:21 +0800119while IFS= read -r line
120do
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800121 keyline=`echo "$line" | grep "$pattern"`
Kelvin Zhangecaacb32022-05-09 10:10:56 +0800122 [ -z "$keyline" ] && continue
kelvin.zhang83a4aa32022-04-08 15:48:35 +0800123
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800124 for keyword in $keyline; do
125 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800126 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800127
Kelvin Zhang22cb55e2022-06-08 20:21:00 +0800128 if [[ $repo_path == drivers* ]] || [[ $repo_path == benchmark* ]]; then
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800129 category=`basename $repo_path | sed 's/_/ /g'`
130 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800131 else
132 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800133 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800134
Kelvin Zhang9a382242022-04-11 18:46:32 +0800135 # exclude some dirs
136 skip_flag=0
137 for exclude_dir in $exclude_dirs; do
138 if [[ $repo_path == $exclude_dir* ]]; then
139 skip_flag=1
140 break
141 fi
142 done
143 [ "$skip_flag" -eq 1 ] && continue
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800144
Kelvin Zhangaed13162022-01-11 16:31:13 +0800145 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800146 case $special_dirs in
147 *"$category"*) arch=`basename $repo_path`
148 if [ "$arch" == "$ARCH" ]; then
149 cmake_path="$category/\${ARCH}"
Kelvin Zhangce736e62022-03-02 14:17:40 +0800150 kconfig_path="$category/\${ARCH}"
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800151 else
152 continue
153 fi;;
154 * ) cmake_path=$repo_path
155 kconfig_path=$repo_path;;
156 esac
157
158 # Generate root CMakeLists.txt
159 if [ -f $repo_path/CMakeLists.txt ]; then
160 echo "add_subdirectory($cmake_path)" >> $cmake_file
161 fi
162
163 # Generate root Kconfig
164 if [ -f $repo_path/Kconfig ]; then
165 if [ "$last_category" != "$category" ]; then
166 if [ -n "$last_category" ]; then
167 echo -e "endmenu\n" >> $kconfig_file
168 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800169
170 if [ "$category" == "wcn" ]; then
171 echo "menu \"${category^^} Options\"" >> $kconfig_file
172 else
173 echo "menu \"${category^} Options\"" >> $kconfig_file
174 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800175 fi
176
177 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
178 last_category=$category
179 fi
180 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800181 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800182 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800183done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800184
185echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800186
Kelvin Zhang55457002021-12-29 14:26:17 +0800187sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800188touch $STAMP