blob: a56284c517cb7859a86e59a6b6364ee4cb926c83 [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 Zhang33a3a872021-12-09 15:29:20 +080014build_dir="build"
Kelvin Zhangaed13162022-01-11 16:31:13 +080015exclude_dir="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 Zhange87f5192021-12-30 16:59:12 +080028# Check whether the project is a repo
29repo manifest >/dev/null 2>&1
30[ "$?" -ne 0 ] && exit 0
31
Kelvin Zhang33a3a872021-12-09 15:29:20 +080032# Generate manifest.xml
33repo manifest > $RTOS_SDK_MANIFEST_FILE
34if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
35 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
36 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080037fi
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +080038if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ $kconfig_file -ot $STAMP ]; then
39 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE) | wc -m`
40 if [ $is_update -eq 0 ]; then
41 sed -i '/#define CONFIG_COMPILE_TIME/d' $RTOS_SDK_VERSION_FILE
42 echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
43 exit 0
44 else
45 echo "Update top Kconfig and CMakelists.txt."
46 fi
47fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080048
Kelvin Zhang5374de92022-01-14 10:35:43 +080049pattern="revision="
50keyline=`grep 'default .* revision' $RTOS_SDK_MANIFEST_FILE`
51for keyword in $keyline; do
52 let i++
53 if [[ $keyword == $pattern* ]]; then
54 SDK_VERSION=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
55 break;
56 fi
57done
58echo "#define CONFIG_VERSION_STRING \"$SDK_VERSION\"" > $RTOS_SDK_VERSION_FILE
59echo "#define CONFIG_BOARD_NAME \"$BOARD\"" >> $RTOS_SDK_VERSION_FILE
60echo "#define CONFIG_PRODUCT_NAME \"$PRODUCT\"" >> $RTOS_SDK_VERSION_FILE
61echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
62
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080063if [[ "$PRODUCT" == aocpu ]]; then
64 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
65else
66 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
67fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080068
Kelvin Zhang33a3a872021-12-09 15:29:20 +080069# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080070cat <<EOF > $cmake_file
71enable_language(C CXX ASM)
72
kelvin.zhangac22e652021-10-18 15:09:21 +080073EOF
74
Kelvin Zhang33a3a872021-12-09 15:29:20 +080075# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080076cat <<EOF > $kconfig_file
77EOF
78
Kelvin Zhang33a3a872021-12-09 15:29:20 +080079# filter manifest.xml of RTOS SDK
80sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
81# figure out the $relative_dir and its column
82pattern="path="
83i=0
kelvin.zhang8946de22022-01-14 21:44:47 +080084keyline=`grep 'path=".*build_system"' $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080085for keyword in $keyline; do
86 let i++
87 if [[ $keyword == $pattern* ]]; then
88 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
89 relative_dir=`dirname $repo_path`
90 break;
91 fi
92done
93
94if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080095 pattern="path="
96else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080097 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080098fi
99
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800100# sort manifest.xml of RTOS SDK
101sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
102
kelvin.zhangac22e652021-10-18 15:09:21 +0800103while IFS= read -r line
104do
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800105 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800106 for keyword in $keyline; do
107 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800108 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800109
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800110 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
111 category=`basename $repo_path | sed 's/_/ /g'`
112 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800113 else
114 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800115 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800116
Kelvin Zhangaed13162022-01-11 16:31:13 +0800117 # exclude other ARCH dirs
118 if [[ $repo_path == docs* ]] || [[ $repo_path == products* ]]; then
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800119 continue
120 fi
121
Kelvin Zhangaed13162022-01-11 16:31:13 +0800122 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800123 case $special_dirs in
124 *"$category"*) arch=`basename $repo_path`
125 if [ "$arch" == "$ARCH" ]; then
126 cmake_path="$category/\${ARCH}"
127 kconfig_path="$category/\$(ARCH)"
128 else
129 continue
130 fi;;
131 * ) cmake_path=$repo_path
132 kconfig_path=$repo_path;;
133 esac
134
135 # Generate root CMakeLists.txt
136 if [ -f $repo_path/CMakeLists.txt ]; then
137 echo "add_subdirectory($cmake_path)" >> $cmake_file
138 fi
139
140 # Generate root Kconfig
141 if [ -f $repo_path/Kconfig ]; then
142 if [ "$last_category" != "$category" ]; then
143 if [ -n "$last_category" ]; then
144 echo -e "endmenu\n" >> $kconfig_file
145 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800146
147 if [ "$category" == "wcn" ]; then
148 echo "menu \"${category^^} Options\"" >> $kconfig_file
149 else
150 echo "menu \"${category^} Options\"" >> $kconfig_file
151 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800152 fi
153
154 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
155 last_category=$category
156 fi
157 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800158 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800159 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800160done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800161
162echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800163
Kelvin Zhang55457002021-12-29 14:26:17 +0800164sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800165touch $STAMP
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +0800166
167cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE