preprocess-sql.sh (1965B)
1 #!/bin/sh 2 3 # This file is part of TALER 4 # Copyright (C) 2026 Taler Systems SA 5 # 6 # TALER is free software; you can redistribute it and/or modify it under the 7 # terms of the GNU General Public License as published by the Free Software 8 # Foundation; either version 3, or (at your option) any later version. 9 # 10 # TALER is distributed in the hope that it will be useful, but WITHOUT ANY 11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details. 13 # 14 # You should have received a copy of the GNU General Public License along with 15 # TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 16 17 set -eu 18 19 if [ $# -lt 1 ]; then 20 echo "Usage: $0 SQLFILES..." >&2 21 exit 1 22 fi 23 24 cat <<'EOF' 25 -- 26 -- This file is part of TALER 27 -- Copyright (C) 2014--2026 Taler Systems SA 28 -- 29 -- TALER is free software; you can redistribute it and/or modify it under the 30 -- terms of the GNU General Public License as published by the Free Software 31 -- Foundation; either version 3, or (at your option) any later version. 32 -- 33 -- TALER is distributed in the hope that it will be useful, but WITHOUT ANY 34 -- WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR 35 -- A PARTICULAR PURPOSE. See the GNU General Public License for more details. 36 -- 37 -- You should have received a copy of the GNU General Public License along with 38 -- TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> 39 -- 40 EOF 41 42 echo "-- generated by" "$(basename "$0")" 43 for n in "$@" 44 do 45 echo "-- generated from" "$(basename "$n")" 46 done 47 echo "--" 48 49 # Pre-process with cpp and remove SQL comments and empty lines 50 preprocessed=$(mktemp "${TMPDIR:-/tmp}/merchant-sql.XXXXXX") 51 trap 'rm -f "$preprocessed"' 0 52 trap 'exit 1' HUP INT TERM 53 54 gcc -I "$(dirname "$1")" \ 55 -E -P -undef - \ 56 < "$1" \ 57 > "$preprocessed" \ 58 2>/dev/null 59 60 awk '{ 61 sub(/--.*/, "") 62 if (NF) 63 print 64 }' "$preprocessed"