blob: c1a95b27750eab3ca407268a7bbad171260b82cc [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"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080019STAMP="$kernel_BUILD_DIR/.stamp"
20
Kelvin Zhange87f5192021-12-30 16:59:12 +080021# Check whether the project is a repo
22repo manifest >/dev/null 2>&1
23[ "$?" -ne 0 ] && exit 0
24
Kelvin Zhang875831b2022-01-07 10:48:50 +080025if [ -s $RTOS_SDK_MANIFEST_FILE ] && [ -s $kconfig_file ] && [ $PWD/Makefile -ot $kconfig_file ] && [ $kconfig_file -ot $STAMP ]; then
Kelvin Zhang24a365e2021-12-28 15:52:55 +080026 exit 0
27fi
kelvin.zhang4b985472021-10-27 16:02:21 +080028
Kelvin Zhang33a3a872021-12-09 15:29:20 +080029# Generate manifest.xml
30repo manifest > $RTOS_SDK_MANIFEST_FILE
31if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
32 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
33 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080034fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080035
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080036if [[ "$PRODUCT" == aocpu ]]; then
37 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
38else
39 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
40fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080041
Kelvin Zhang33a3a872021-12-09 15:29:20 +080042# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080043cat <<EOF > $cmake_file
44enable_language(C CXX ASM)
45
kelvin.zhangac22e652021-10-18 15:09:21 +080046EOF
47
Kelvin Zhang33a3a872021-12-09 15:29:20 +080048# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080049cat <<EOF > $kconfig_file
50EOF
51
Kelvin Zhang33a3a872021-12-09 15:29:20 +080052# filter manifest.xml of RTOS SDK
53sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
54# figure out the $relative_dir and its column
55pattern="path="
56i=0
57keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
58for keyword in $keyline; do
59 let i++
60 if [[ $keyword == $pattern* ]]; then
61 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
62 relative_dir=`dirname $repo_path`
63 break;
64 fi
65done
66
67if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080068 pattern="path="
69else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080070 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080071fi
72
Kelvin Zhang33a3a872021-12-09 15:29:20 +080073# sort manifest.xml of RTOS SDK
74sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
75
kelvin.zhangac22e652021-10-18 15:09:21 +080076while IFS= read -r line
77do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080078 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080079 for keyword in $keyline; do
80 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080081 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080082
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080083 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
84 category=`basename $repo_path | sed 's/_/ /g'`
85 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080086 else
87 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080088 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080089
Kelvin Zhangaed13162022-01-11 16:31:13 +080090 # exclude other ARCH dirs
91 if [[ $repo_path == docs* ]] || [[ $repo_path == products* ]]; then
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080092 continue
93 fi
94
Kelvin Zhangaed13162022-01-11 16:31:13 +080095 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080096 case $special_dirs in
97 *"$category"*) arch=`basename $repo_path`
98 if [ "$arch" == "$ARCH" ]; then
99 cmake_path="$category/\${ARCH}"
100 kconfig_path="$category/\$(ARCH)"
101 else
102 continue
103 fi;;
104 * ) cmake_path=$repo_path
105 kconfig_path=$repo_path;;
106 esac
107
108 # Generate root CMakeLists.txt
109 if [ -f $repo_path/CMakeLists.txt ]; then
110 echo "add_subdirectory($cmake_path)" >> $cmake_file
111 fi
112
113 # Generate root Kconfig
114 if [ -f $repo_path/Kconfig ]; then
115 if [ "$last_category" != "$category" ]; then
116 if [ -n "$last_category" ]; then
117 echo -e "endmenu\n" >> $kconfig_file
118 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800119
120 if [ "$category" == "wcn" ]; then
121 echo "menu \"${category^^} Options\"" >> $kconfig_file
122 else
123 echo "menu \"${category^} Options\"" >> $kconfig_file
124 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800125 fi
126
127 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
128 last_category=$category
129 fi
130 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800131 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800132 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800133done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800134
135echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800136
Kelvin Zhang55457002021-12-29 14:26:17 +0800137sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800138touch $STAMP