| #!/bin/bash |
| # Copyright 2023 Gentoo Authors |
| # Distributed under the terms of the GNU General Public License v2 |
| # |
| # Generate .h containing configuration database for libsegmentation, |
| # based on provided binary: |
| #$1 : output dir |
| #$2 : output file name |
| #$3+2*n : input binary file, generated from the .star configuration file. |
| #$4+2*n : name of the variable used by libsegmentation to retrieve the |
| # database. |
| |
| out="${1}/${2}" |
| include_once_flag="$(echo -n "${2^^}" | tr -c "[:alnum:]" "_")" |
| |
| cat > "${out}" << EOF |
| // Copyright 2023 The ChromiumOS Authors |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| // Autogenerated file from feature-management that contains information needed |
| // by libsegmentation. |
| |
| #ifndef LIBSEGMENTATION_${include_once_flag}_ |
| #define LIBSEGMENTATION_${include_once_flag}_ |
| |
| namespace segmentation { |
| EOF |
| |
| i=3 |
| while [ "${i}" -lt $# ]; do |
| in=${!i} |
| i=$((i + 1)) |
| key=${!i} |
| i=$((i + 1)) |
| |
| if [ -e "${in}" ]; then |
| echo " const char ${key}[] = \"$(base64 -w 0 < "${in}")\";" >> "${out}" |
| else |
| echo " const char ${key}[] = \"\";" |
| fi |
| done |
| |
| cat >> "${out}" << EOF |
| } |
| |
| #endif |
| EOF |