blob: 917c01f18c4cf87193d3ce762df422ddf206c49a [file] [log] [blame]
kelvin.zhangac22e652021-10-18 15:09:21 +08001#!/bin/bash
2
yang.liffa60e52022-01-11 14:38:56 +08003# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4
5# SPDX-License-Identifier: MIT
6
kelvin.zhangf91d7b02021-10-26 16:47:17 +08007###############################################################
8# Function: Auto-generate root CMakeLists.txt and Kconfig according to manifest.xml.
9###############################################################
kelvin.zhangac22e652021-10-18 15:09:21 +080010
kelvin.zhangf91d7b02021-10-26 16:47:17 +080011cmake_file="$PWD/CMakeLists.txt"
12kconfig_file="$PWD/Kconfig"
Kelvin Zhang33a3a872021-12-09 15:29:20 +080013build_dir="build"
Kelvin Zhangaed13162022-01-11 16:31:13 +080014exclude_dir="products docs"
kelvin.zhang5ef541b2021-10-21 13:24:48 +080015special_dirs="arch soc boards"
Kelvin Zhang25ccae72021-12-07 16:42:12 +080016
17RTOS_SDK_MANIFEST_FILE="$kernel_BUILD_DIR/rtos_sdk_manifest.xml"
Kelvin Zhang24a365e2021-12-28 15:52:55 +080018STAMP="$kernel_BUILD_DIR/.stamp"
19
Kelvin Zhange87f5192021-12-30 16:59:12 +080020# Check whether the project is a repo
21repo manifest >/dev/null 2>&1
22[ "$?" -ne 0 ] && exit 0
23
Kelvin Zhang875831b2022-01-07 10:48:50 +080024if [ -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 +080025 exit 0
26fi
kelvin.zhang4b985472021-10-27 16:02:21 +080027
Kelvin Zhang33a3a872021-12-09 15:29:20 +080028# Generate manifest.xml
29repo manifest > $RTOS_SDK_MANIFEST_FILE
30if [ ! -f $RTOS_SDK_MANIFEST_FILE ]; then
31 echo "Faild to save $RTOS_SDK_MANIFEST_FILE"
32 exit 1
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080033fi
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080034
Kelvin Zhang8cc560f2021-12-24 20:25:08 +080035if [[ "$PRODUCT" == aocpu ]]; then
36 sed -i '/path="drivers"/d' $RTOS_SDK_MANIFEST_FILE
37else
38 sed -i '/path="drivers_aocpu"/d' $RTOS_SDK_MANIFEST_FILE
39fi
kelvin.zhangbdb01dd2021-11-02 10:14:45 +080040
Kelvin Zhang33a3a872021-12-09 15:29:20 +080041# Write the fixed content to CMakeLists.txt
kelvin.zhangac22e652021-10-18 15:09:21 +080042cat <<EOF > $cmake_file
43enable_language(C CXX ASM)
44
kelvin.zhangac22e652021-10-18 15:09:21 +080045EOF
46
Kelvin Zhang33a3a872021-12-09 15:29:20 +080047# Clear Kconfig
kelvin.zhangac22e652021-10-18 15:09:21 +080048cat <<EOF > $kconfig_file
49EOF
50
Kelvin Zhang33a3a872021-12-09 15:29:20 +080051# filter manifest.xml of RTOS SDK
52sed -i '/rtos_sdk\//!d' $RTOS_SDK_MANIFEST_FILE
53# figure out the $relative_dir and its column
54pattern="path="
55i=0
56keyline=`grep 'path=".*build"' $RTOS_SDK_MANIFEST_FILE`
57for keyword in $keyline; do
58 let i++
59 if [[ $keyword == $pattern* ]]; then
60 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
61 relative_dir=`dirname $repo_path`
62 break;
63 fi
64done
65
66if [[ $relative_dir == . ]]; then
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080067 pattern="path="
68else
Kelvin Zhang33a3a872021-12-09 15:29:20 +080069 pattern="path=\"${relative_dir}/"
kelvin.zhang9e82d8f2021-10-26 20:26:04 +080070fi
71
Kelvin Zhang33a3a872021-12-09 15:29:20 +080072# sort manifest.xml of RTOS SDK
73sort -k $i $RTOS_SDK_MANIFEST_FILE -o $RTOS_SDK_MANIFEST_FILE
74
kelvin.zhangac22e652021-10-18 15:09:21 +080075while IFS= read -r line
76do
Kelvin Zhang25ccae72021-12-07 16:42:12 +080077 keyline=`echo "$line" | grep 'name=.* path='`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080078 for keyword in $keyline; do
79 if [[ $keyword == path=* ]]; then
Kelvin Zhang25ccae72021-12-07 16:42:12 +080080 repo_path=`echo ${keyword#*${pattern}} | sed 's/\"//g' | sed 's/\/>//g'`
kelvin.zhang5ef541b2021-10-21 13:24:48 +080081
Kelvin Zhang20fb7ec2021-12-28 10:30:55 +080082 if [[ $repo_path == drivers* ]] || [[ $repo_path == third_party* ]]; then
83 category=`basename $repo_path | sed 's/_/ /g'`
84 category=`echo $category | sed "s/ $PRODUCT//g"`
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080085 else
86 category=`dirname $repo_path`
kelvin.zhangac22e652021-10-18 15:09:21 +080087 fi
kelvin.zhang78a66712021-10-20 17:27:41 +080088
Kelvin Zhangaed13162022-01-11 16:31:13 +080089 # exclude other ARCH dirs
90 if [[ $repo_path == docs* ]] || [[ $repo_path == products* ]]; then
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080091 continue
92 fi
93
Kelvin Zhangaed13162022-01-11 16:31:13 +080094 # substitute ARCH dirs with viarable
Kelvin Zhangf441d5e2021-12-02 20:37:37 +080095 case $special_dirs in
96 *"$category"*) arch=`basename $repo_path`
97 if [ "$arch" == "$ARCH" ]; then
98 cmake_path="$category/\${ARCH}"
99 kconfig_path="$category/\$(ARCH)"
100 else
101 continue
102 fi;;
103 * ) cmake_path=$repo_path
104 kconfig_path=$repo_path;;
105 esac
106
107 # Generate root CMakeLists.txt
108 if [ -f $repo_path/CMakeLists.txt ]; then
109 echo "add_subdirectory($cmake_path)" >> $cmake_file
110 fi
111
112 # Generate root Kconfig
113 if [ -f $repo_path/Kconfig ]; then
114 if [ "$last_category" != "$category" ]; then
115 if [ -n "$last_category" ]; then
116 echo -e "endmenu\n" >> $kconfig_file
117 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800118
119 if [ "$category" == "wcn" ]; then
120 echo "menu \"${category^^} Options\"" >> $kconfig_file
121 else
122 echo "menu \"${category^} Options\"" >> $kconfig_file
123 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800124 fi
125
126 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
127 last_category=$category
128 fi
129 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800130 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800131 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800132done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800133
134echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800135
Kelvin Zhang55457002021-12-29 14:26:17 +0800136sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800137touch $STAMP