blob: 8e33448bf9b898446235a9bfca8e70ad6a578c6a [file] [log] [blame]
Kelvin Zhangc18bac62022-03-14 10:31:57 +08001#!/bin/bash
2#
3# Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
4#
5# SPDX-License-Identifier: MIT
6#
7
8###############################################################
9# Function: generate build combination.
10###############################################################
11
12# $1: "arch soc board product"
13check_project()
14{
15 LINE_NR=`sed -n '$=' $BUILD_COMBINATION`
16 i=0
17 while IFS= read -r LINE; do
18 [[ "$1" == "$LINE" ]] && break
19 i=$((i+1))
20 done < $BUILD_COMBINATION
21 [ $i -ge $LINE_NR ] && $i && return 1
22
23 return 0
24}
25
26# $1: arch
27# $2: soc
28# $3: board
29# $4: product
30check_build_combination()
31{
Kelvin Zhangaacf4342022-11-15 14:25:09 +080032 [ $# -ne 4 ] && return -1
33
Kelvin Zhangc18bac62022-03-14 10:31:57 +080034 i=0
35 for arch in ${ARCHS[*]}; do
36 [[ "$1" == "$arch" ]] && break
37 i=$((i+1))
38 done
39 [ $i -ge ${#ARCHS[*]} ] && return 1
40
41 i=0
42 for soc in ${SOCS[*]};do
43 [[ "$2" == "$soc" ]] && break
44 i=$((i+1))
45 done
46 [ "$i" -ge ${#SOCS[*]} ] && return 2
47
48 i=0
49 for board in ${BOARDS[*]};do
50 [[ "$3" == "$board" ]] && break
51 i=$((i+1))
52 done
53 [ "$i" -ge ${#BOARDS[*]} ] && return 3
54
55 i=0
56 for product in ${PRODUCTS[*]};do
57 [[ "$4" == "$product" ]] && break
58 i=$((i+1))
59 done
60 [ "$i" -ge ${#PRODUCTS[*]} ] && return 4
61
62 return 0
63}
64
65unset ARCHS SOCS BOARDS PRODUCTS
66
67ARCHS=($(find $PWD/arch -mindepth 1 -maxdepth 1 -type d ! -name ".*" | xargs basename -a | sort -n))
68SOCS=($(find $PWD/soc -mindepth 2 -maxdepth 2 -type d ! -name ".*" | xargs basename -a | sort -n))
69BOARDS=($(find $PWD/boards -mindepth 2 -maxdepth 2 -type d ! -name ".*" | xargs basename -a | sort -n))
70PRODUCTS=($(find $PWD/products -mindepth 1 -maxdepth 1 -type d ! -name ".*" | xargs basename -a | sort -n))
71
Kelvin Zhangc18bac62022-03-14 10:31:57 +080072export BUILD_COMBINATION="$PWD/output/build_combination.txt"
73
74if [ ! -d "$PWD/output" ]; then
75 mkdir -p $PWD/output
76fi
Kelvin Zhangaacf4342022-11-15 14:25:09 +080077
78for arch in ${ARCHS[*]}; do
79 BUILD_COMBINATION_INPUT="$PWD/boards/$arch/build_combination.in"
80 if [ $BUILD_COMBINATION -ot $BUILD_COMBINATION_INPUT ]; then
81 :> $BUILD_COMBINATION
82 fi
83done
84
85if [ ! -s "$BUILD_COMBINATION" ]; then
86 for arch in ${ARCHS[*]}; do
87 BUILD_COMBINATION_INPUT="$PWD/boards/$arch/build_combination.in"
88 while IFS= read -r LINE; do
89 a=`echo "$LINE"|awk '{print $1}'`
90 s=`echo "$LINE"|awk '{print $2}'`
91 b=`echo "$LINE"|awk '{print $3}'`
92 p=`echo "$LINE"|awk '{print $4}'`
93 check_build_combination $a $s $b $p
94 [ "$?" -eq 0 ] && echo $LINE >> $BUILD_COMBINATION
95 done < $BUILD_COMBINATION_INPUT
96 done
Kelvin Zhangc18bac62022-03-14 10:31:57 +080097fi