1#!/bin/sh 2# Copyright (C) 2021-2022 Intel Corporation. 3# SPDX-License-Identifier: BSD-3-Clause 4 5base_dir=$1 6board_xml=$2 7scenario_xml=$3 8out=$4 9unified_xml=$5 10scenario=$(xmllint --xpath "string(//@scenario)" --xinclude $unified_xml) 11year=$(date +'%Y') 12 13apply_patch () { 14 echo "Applying patch ${1}:" 15 patch -p1 < ${1} 16 if [ $? -ne 0 ]; then 17 echo "Applying patch ${1} failed." 18 exit 1 19 fi 20} 21 22tool_dir=${base_dir}/../misc/config_tools 23diffconfig_list=${out}/.diffconfig 24 25python3 ${tool_dir}/board_config/board_cfg_gen.py --board ${board_xml} --scenario ${scenario_xml} --out ${out} && 26python3 ${tool_dir}/acpi_gen/asl_gen.py --board ${board_xml} --scenario ${scenario_xml} --out ${out} 27exitcode=$? 28if [ $exitcode -ne 0 ]; then 29 exit $exitcode 30fi 31 32if ! which xsltproc ; then 33 echo "xsltproc cannot be found, please install it and make sure it is in your PATH." 34 exit 1 35fi 36 37transform() { 38 echo "Generating ${1}:" 39 xsltproc -o ${out}/scenarios/${scenario}/${1} --xinclude --xincludestyle ${tool_dir}/xforms/${1}.xsl ${unified_xml} 40 if [ $? -ne 0 ]; then 41 echo "Failed to generate ${1} with xsltproc!" 42 exit 1 43 fi 44 sed -i -e "s/YEAR/$year/" ${out}/scenarios/${scenario}/${1} 45 echo "${1} was generated using xsltproc successfully." 46} 47 48transform_board() { 49 echo "Generating ${1}:" 50 xsltproc -o ${out}/boards/${1} --xinclude --xincludestyle ${tool_dir}/xforms/${1}.xsl ${unified_xml} 51 if [ $? -ne 0 ]; then 52 echo "Failed to generate ${1} with xsltproc!" 53 exit 1 54 fi 55 sed -i -e "s/YEAR/$year/" ${out}/boards/${1} 56 echo "${1} was generated using xsltproc successfully." 57} 58 59transform vm_configurations.c 60transform vm_configurations.h 61transform pt_intx.c 62transform ivshmem_cfg.h 63transform misc_cfg.h 64transform pci_dev.c 65transform_board board_info.h 66 67if which clang-format ; then 68 find ${out}/scenarios/${scenario} -iname *.h -o -iname *.c \ 69 | xargs clang-format --style=file -i --fallback-style=none 70else 71 echo "clang-format cannot be found. The generated files under ${out}/scenarios/${scenario} are not formatted." 72 echo "clang-format is a tool to format the C code automatically and improve the code readability." 73 echo "Please install clang-format and format the generated files if those need to be included and reviewed." 74fi 75 76if [ -f ${diffconfig_list} ]; then 77 cd ${out} && 78 cat ${diffconfig_list} | while read line; do 79 if [ -f ${line} ]; then 80 apply_patch ${line} 81 elif [ -d ${line} ]; then 82 find ${line} -maxdepth 1 -name '*.patch' | while read f; do 83 apply_patch ${f} 84 done 85 else 86 echo "${line}: No such file or directory" 87 exit 1 88 fi 89 done 90fi 91