blob: 3bd5603f76ac48c96fa91035768309066f61a23d [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.zhang60107092021-10-19 18:12:39 +080014exclude_dir="products"
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 Zhangf441d5e2021-12-02 20:37:37 +080089 if [[ $repo_path == $exclude_dir/* ]]; then
90 continue
91 fi
92
93 # exclude other ARCH dirs
94 case $special_dirs in
95 *"$category"*) arch=`basename $repo_path`
96 if [ "$arch" == "$ARCH" ]; then
97 cmake_path="$category/\${ARCH}"
98 kconfig_path="$category/\$(ARCH)"
99 else
100 continue
101 fi;;
102 * ) cmake_path=$repo_path
103 kconfig_path=$repo_path;;
104 esac
105
106 # Generate root CMakeLists.txt
107 if [ -f $repo_path/CMakeLists.txt ]; then
108 echo "add_subdirectory($cmake_path)" >> $cmake_file
109 fi
110
111 # Generate root Kconfig
112 if [ -f $repo_path/Kconfig ]; then
113 if [ "$last_category" != "$category" ]; then
114 if [ -n "$last_category" ]; then
115 echo -e "endmenu\n" >> $kconfig_file
116 fi
Kelvin Zhang24939422022-01-06 13:52:10 +0800117
118 if [ "$category" == "wcn" ]; then
119 echo "menu \"${category^^} Options\"" >> $kconfig_file
120 else
121 echo "menu \"${category^} Options\"" >> $kconfig_file
122 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800123 fi
124
125 echo "source \"$kconfig_path/Kconfig\"" >> $kconfig_file
126 last_category=$category
127 fi
128 break;
kelvin.zhangac22e652021-10-18 15:09:21 +0800129 fi
Kelvin Zhangf441d5e2021-12-02 20:37:37 +0800130 done
Kelvin Zhang25ccae72021-12-07 16:42:12 +0800131done < "$RTOS_SDK_MANIFEST_FILE"
kelvin.zhangac22e652021-10-18 15:09:21 +0800132
133echo "endmenu" >> $kconfig_file
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800134
Kelvin Zhang55457002021-12-29 14:26:17 +0800135sleep 1
Kelvin Zhang24a365e2021-12-28 15:52:55 +0800136touch $STAMP