1#!/bin/sh 2# A simple script that generates loongarch-str.h and loongarch.opt 3# from genopt/loongarch-optstr. 4# 5# Copyright (C) 2021-2022 Free Software Foundation, Inc. 6# 7# This file is part of GCC. 8# 9# GCC is free software; you can redistribute it and/or modify it under 10# the terms of the GNU General Public License as published by the Free 11# Software Foundation; either version 3, or (at your option) any later 12# version. 13# 14# GCC is distributed in the hope that it will be useful, but WITHOUT 15# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 16# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public 17# License for more details. 18# 19# You should have received a copy of the GNU General Public License 20# along with GCC; see the file COPYING3. If not see 21# <http://www.gnu.org/licenses/>. 22 23cd "$(dirname "$0")" 24 25# Generate a header containing definitions from the string table. 26gen_defines() { 27 cat <<EOF 28/* Generated automatically by "genstr" from "loongarch-strings". 29 Please do not edit this file directly. 30 31 Copyright (C) 2021-2022 Free Software Foundation, Inc. 32 Contributed by Loongson Ltd. 33 34This file is part of GCC. 35 36GCC is free software; you can redistribute it and/or modify 37it under the terms of the GNU General Public License as published by 38the Free Software Foundation; either version 3, or (at your option) 39any later version. 40 41GCC is distributed in the hope that it will be useful, 42but WITHOUT ANY WARRANTY; without even the implied warranty of 43MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 44GNU General Public License for more details. 45 46You should have received a copy of the GNU General Public License 47along with GCC; see the file COPYING3. If not see 48<http://www.gnu.org/licenses/>. */ 49 50#ifndef LOONGARCH_STR_H 51#define LOONGARCH_STR_H 52EOF 53 54 sed -e '/^$/n' -e 's@#.*$@@' -e '/^$/d' \ 55 -e 's@^\([^ \t]\+\)[ \t]*\([^ \t]*\)@#define \1 "\2"@' \ 56 loongarch-strings 57 58 echo 59 echo "#endif /* LOONGARCH_STR_H */" 60} 61 62 63# Substitute all "@@<KEY>@@" to "<VALUE>" in loongarch.opt.in 64# according to the key-value pairs defined in loongarch-strings. 65 66gen_options() { 67 68 sed -e '/^$/n' -e 's@#.*$@@' -e '/^$/d' \ 69 -e 's@^\([^ \t]\+\)[ \t]*\([^ \t]*\)@\1="\2"@' \ 70 loongarch-strings | { \ 71 72 # read the definitions 73 while read -r line; do 74 eval "$line" 75 done 76 77 # print a header 78 cat << EOF 79; Generated by "genstr" from the template "loongarch.opt.in" 80; and definitions from "loongarch-strings". 81; 82; Please do not edit this file directly. 83; It will be automatically updated during a gcc build 84; if you change "loongarch.opt.in" or "loongarch-strings". 85; 86EOF 87 88 # make the substitutions 89 sed -e 's@"@\\"@g' -e 's/@@\([^@]\+\)@@/${\1}/g' loongarch.opt.in | \ 90 while read -r line; do 91 eval "echo \"$line\"" 92 done 93 } 94} 95 96main() { 97 case "$1" in 98 header) gen_defines;; 99 opt) gen_options;; 100 *) echo "Unknown Command: \"$1\". Available: header, opt"; exit 1;; 101 esac 102} 103 104main "$@" 105