3 if [ -n "$BUILD_DEBUG" ]; then
6 PREFIX=${PREFIX-@PREFIX@}
7 if [ "@PREFIX@" = @PREFIX""@ -o ! -d "$PREFIX/share/mes/module" ]
9 MES_PREFIX=${MES_PREFIX-$(cd $(dirname $0)/.. && pwd)}
11 MES_PREFIX=${MES_PREFIX-$PREFIX/share/mes}
14 mes_p=$(command -v mes)
15 if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
16 GODIR=${GODIR-@GODIR@}
17 GUILEDIR=${GUILEDIR-@GUILEDIR@}
18 [ "$GODIR" = @"GODIR"@ ] && GODIR=$(dirname $0)/../guile
19 [ "$GUILEDIR" = @"GUILEDIR"@ ] && GUILEDIR=$(dirname $0)/../guile
20 export GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
21 GUILE_LOAD_COMPILED_PATH=$GODIR:$GUILE_LOAD_COMPILED_PATH
22 exec ${GUILE-guile} -L $GUILEDIR -e '(mescc)' -s "$0" "$@"
24 MES=${MES-$(dirname $0)/mes}
25 exec ${MES-mes} -e '(mescc)' -s $0 "$@"
29 ;;; Mes --- Maxwell Equations of Software
30 ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
32 ;;; This file is part of Mes.
34 ;;; Mes is free software; you can redistribute it and/or modify it
35 ;;; under the terms of the GNU General Public License as published by
36 ;;; the Free Software Foundation; either version 3 of the License, or (at
37 ;;; your option) any later version.
39 ;;; Mes is distributed in the hope that it will be useful, but
40 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
41 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
42 ;;; GNU General Public License for more details.
44 ;;; You should have received a copy of the GNU General Public License
45 ;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
47 (define-module (mescc)
48 #:use-module (ice-9 getopt-long)
49 #:use-module (mes misc)
50 #:use-module (mescc mescc)
53 (define %prefix (or (getenv "MES_PREFIX")
54 (if (string-prefix? "@PREFIX" "@PREFIX@")
56 "@PREFIX@/share/mes")))
58 (define %version (if (string-prefix? "@VERSION" "@VERSION@") "git"
63 (define (set-port-encoding! port encoding) #t)
64 (mes-use-module (mes guile))
65 (mes-use-module (mes misc))
66 (mes-use-module (mes getopt-long))
67 (mes-use-module (mes display))
68 (mes-use-module (mescc mescc)))
70 (define-macro (mes-use-module . rest) #t)))
72 (format (current-error-port) "mescc[~a]...\n" %scheme)
74 (define (parse-opts args)
76 '((assemble (single-char #\c))
77 (compile (single-char #\S))
78 (define (single-char #\D) (value #t))
79 (debug-info (single-char #\g))
80 (help (single-char #\h))
81 (include (single-char #\I) (value #t))
82 (library-dir (single-char #\L) (value #t))
83 (library (single-char #\l) (value #t))
84 (preprocess (single-char #\E))
85 (output (single-char #\o) (value #t))
86 (version (single-char #\V))
87 (verbose (single-char #\v))
88 (write (single-char #\w) (value #t))))
89 (options (getopt-long args option-spec))
90 (help? (option-ref options 'help #f))
91 (files (option-ref options '() '()))
92 (usage? (and (not help?) (null? files)))
93 (version? (option-ref options 'version #f)))
96 (format (current-output-port) "mescc (mes) ~a\n" %version))
97 (and (or help? usage?)
98 (format (or (and usage? (current-error-port)) (current-output-port)) "\
99 Usage: mescc [OPTION]... FILE...
100 -c preprocess, compile and assemble only; do not link
101 -D DEFINE[=VALUE] define DEFINE [VALUE=1]
102 -E preprocess only; do not compile, assemble or link
103 -g add debug info [GDB, objdump] TODO: hex2 footer
104 -h, --help display this help and exit
105 -I DIR append DIR to include path
106 -L DIR append DIR to library path
107 -l LIBNAME link with LIBNAME
108 -o FILE write output to FILE
109 -S preprocess and compile only; do not assemble or link
110 -v, --version display version and exit
111 -w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
113 Environment variables:
115 MES=BINARY run on mes-executable BINARY {mes,guile}
116 MES_DEBUG=LEVEL show debug output with verbosity LEVEL {0..5}
117 NYACC_TRACE=1 show Nyacc progress
119 (exit (or (and usage? 2) 0)))
123 (let* ((options (parse-opts args))
124 (options (acons 'prefix %prefix options))
125 (preprocess? (option-ref options 'preprocess #f))
126 (compile? (option-ref options 'compile #f))
127 (assemble? (option-ref options 'assemble #f))
128 (verbose? (option-ref options 'verbose (getenv "MES_DEBUG"))))
130 (setenv "NYACC_TRACE" "yes")
131 (format (current-error-port) "options=~s\n" options))
132 (cond (preprocess? (mescc:preprocess options))
133 (compile? (mescc:compile options))
134 (assemble? (mescc:assemble options))
135 (else (mescc:link options)))))