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