blob: 43cd18d7903c12316425186856bbba6a8e3c008b [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
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080038
Kelvin Zhang83f12de2022-01-21 09:57:45 +080039if [ -s $RTOS_SDK_MANIFEST_OLD_FILE ] && [ -s $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
Kelvin Zhang017fb4c2022-01-20 19:48:36 +080040 is_update=`comm -3 <(sort $RTOS_SDK_MANIFEST_FILE) <(sort $RTOS_SDK_MANIFEST_OLD_FILE)`
41 if [ -z "$is_update" ]; then
Xiaohu.Huang02b7f9f2022-01-20 18:42:07 +080042 sed -i '/#define CONFIG_COMPILE_TIME/d' $RTOS_SDK_VERSION_FILE
43 echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
44 exit 0
45 else
46 echo "Update top Kconfig and CMakelists.txt."
47 fi
48fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080049
Kelvin Zhang83f12de2022-01-21 09:57:45 +080050# Back up manifest.xml
51cp -arf $RTOS_SDK_MANIFEST_FILE $RTOS_SDK_MANIFEST_OLD_FILE
52
Kelvin Zhang5374de92022-01-14 10:35:43 +080053pattern="revision="
54keyline=`grep 'default .* revision' $RTOS_SDK_MANIFEST_FILE`
55for keyword in $keyline; do
56 let i++
57 if [[ $keyword == $pattern* ]]; then
58 SDK_VERSION=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
59 break;
60 fi
61done
62echo "#define CONFIG_VERSION_STRING \"$SDK_VERSION\"" > $RTOS_SDK_VERSION_FILE
63echo "#define CONFIG_BOARD_NAME \"$BOARD\"" >> $RTOS_SDK_VERSION_FILE
64echo "#define CONFIG_PRODUCT_NAME \"$PRODUCT\"" >> $RTOS_SDK_VERSION_FILE
65echo "#define CONFIG_COMPILE_TIME \"$COMPILE_TIME\"" >> $RTOS_SDK_VERSION_FILE
66
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080067if [[ "$PRODUCT" == aocpu ]]; then
68 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
69else
70 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
71fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080072
Kelvin Zhang33a3a872021-12-09 15:29:20 +080073# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080074cat <<EOF > $cmake_file
75enable_language(C CXX ASM)
76
kelvin.zhangac22e652021-10-18 15:09:21 +080077EOF
78
Kelvin Zhang33a3a872021-12-09 15:29:20 +080079# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080080cat <<EOF > $kconfig_file
81EOF
82
Kelvin Zhang33a3a872021-12-09 15:29:20 +080083# filter manifest.xml of RTOS SDK
84sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
85# figure out the $relative_dir and its column
86pattern="path="
87i=0
kelvin.zhang8946de22022-01-14 21:44:47 +080088keyline=`grep 'path=".*build_system"' $RTOS_SDK_MANIFEST_FILE`
Kelvin Zhang33a3a872021-12-09 15:29:20 +080089for keyword in $keyline; do
90 let i++
91 if [[ $keyword == $pattern* ]]; then
92 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
93 relative_dir=`dirname $repo_path`
94 break;
95 fi
96done
97
98if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080099 pattern="path="
100else
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800101 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +0800102fi
103
Kelvin Zhang33a3a872021-12-09 15:29:20 +0800104# sort manifest.xml of RTOS SDK
105sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
106
kelvin.zhangac22e652021-10-18 15:09:21 +0800107while IFS= read -r line
108do
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800109 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800110 for keyword in $keyline; do
111 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800112 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +0800113
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +0800114 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
115 category=`basename $repo_path | sed 's/_/ /g'`
116 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800117 else
118 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +0800119 fi
kelvin.zhang78a66712021-10-20 17:27:41 +0800120
Kelvin Zhangaed13162022-01-11 16:31:13 +0800121 # exclude other ARCH dirs
122 if [[ $repo_path == docs* ]] || [[ $repo_path == products* ]]; then
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800123 continue
124 fi
125
Kelvin Zhangaed13162022-01-11 16:31:13 +0800126 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800127 case $special_dirs in
128 *"$category"*) arch=`basename $repo_path`
129 if [ "$arch" == "$ARCH" ]; then
130 cmake_path="$category/\${ARCH}"
131 kconfig_path="$category/\$(ARCH)"
132 else
133 continue
134 fi;;
135 * ) cmake_path=$repo_path
136 kconfig_path=$repo_path;;
137 esac
138
139 # Generate root CMakeLists.txt
140 if [ -f $repo_path/CMakeLists.txt ]; then
141 echo "add_subdirectory($cmake_path)" >> $cmake_file
142 fi
143
144 # Generate root Kconfig
145 if [ -f $repo_path/Kconfig ]; then
146 if [ "$last_category" != "$category" ]; then
147 if [ -n "$last_category" ]; then
148 echo -e "endmenu\n" >> $kconfig_file
149 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800150
151 if [ "$category" == "wcn" ]; then
152 echo "menu \"${category^^} Options\"" >> $kconfig_file
153 else
154 echo "menu \"${category^} Options\"" >> $kconfig_file
155 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800156 fi
157
158 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
159 last_category=$category
160 fi
161 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800162 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800163 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800164done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800165
166echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800167
Kelvin Zhang55457002021-12-29 14:26:17 +0800168sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800169touch $STAMP