6 prefix=${prefix-@prefix@}
7 MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
9 mes_p=$(command -v mes)
10 mescc=$(command -v $0)
12 guile_site_dir=${guile_site_dir-@guile_site_dir@}
13 GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH
15 if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
16 guile_site_ccache_dir=${guile_site_ccache_dir-@guile_site_ccache_dir@}
17 GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH
18 GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
19 export GUILE_AUTO_COMPILE
20 exec ${GUILE-guile} -L $guile_site_dir -e '(mescc)' -s "$mescc" "$@"
22 MES=${MES-$(dirname $0)/mes}
23 exec ${MES-mes} -e '(mescc)' -s "$mescc" "$@"
27 ;;; GNU Mes --- Maxwell Equations of Software
28 ;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
30 ;;; This file is part of GNU Mes.
32 ;;; GNU Mes is free software; you can redistribute it and/or modify it
33 ;;; under the terms of the GNU General Public License as published by
34 ;;; the Free Software Foundation; either version 3 of the License, or (at
35 ;;; your option) any later version.
37 ;;; GNU Mes is distributed in the hope that it will be useful, but
38 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
39 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
40 ;;; GNU General Public License for more details.
42 ;;; You should have received a copy of the GNU General Public License
43 ;;; along with GNU Mes. If not, see <http://www.gnu.org/licenses/>.
45 (define-module (mescc)
46 #:use-module (ice-9 getopt-long)
47 #:use-module (mes misc)
48 #:use-module (mescc mescc)
51 (define %prefix (or (getenv "MES_PREFIX")
52 (if (string-prefix? "@prefix" "@prefix@")
54 "@prefix@/share/mes")))
56 (define %version (if (string-prefix? "@VERSION" "@VERSION@") "git"
61 (define (set-port-encoding! port encoding) #t)
62 (mes-use-module (mes guile))
63 (mes-use-module (mes misc))
64 (mes-use-module (mes getopt-long))
65 (mes-use-module (mes display))
66 (mes-use-module (mescc mescc)))
68 (define-macro (mes-use-module . rest) #t)))
70 (when (and=> (getenv "V") (lambda (v) (> (string->number v) 1)))
71 (format (current-error-port) "mescc[~a]...\n" %scheme))
73 (define (parse-opts args)
75 '((assemble (single-char #\c))
76 (base-address (value #t))
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 (machine (single-char #\m) (value #t))
85 (preprocess (single-char #\E))
86 (output (single-char #\o) (value #t))
87 (version (single-char #\V))
88 (verbose (single-char #\v))
89 (write (single-char #\w) (value #t))))
90 (options (getopt-long args option-spec))
91 (help? (option-ref options 'help #f))
92 (files (option-ref options '() '()))
93 (usage? (and (not help?) (null? files)))
94 (version? (option-ref options 'version #f)))
97 (format (current-output-port) "mescc (GNU Mes) ~a\n" %version))
98 (and (or help? usage?)
99 (format (or (and usage? (current-error-port)) (current-output-port)) "\
100 Usage: mescc [OPTION]... FILE...
101 -c preprocess, compile and assemble only; do not link
102 --base-address=ADRRESS
103 use BaseAddress ADDRESS [0x1000000]
104 -D DEFINE[=VALUE] define DEFINE [VALUE=1]
105 -E preprocess only; do not compile, assemble or link
106 -g add debug info [GDB, objdump] TODO: hex2 footer
107 -h, --help display this help and exit
108 -I DIR append DIR to include path
109 -L DIR append DIR to library path
110 -l LIBNAME link with LIBNAME
111 -m BITS compile for BITS bits [32]
112 -o FILE write output to FILE
113 -S preprocess and compile only; do not assemble or link
114 -v, --version display version and exit
115 -w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
117 Environment variables:
119 MES=BINARY run on mes-executable BINARY {mes,guile}
120 MES_DEBUG=LEVEL show debug output with verbosity LEVEL {0..5}
121 NYACC_TRACE=1 show Nyacc progress
123 (exit (or (and usage? 2) 0)))
127 (let* ((options (parse-opts args))
128 (options (acons 'prefix %prefix options))
129 (preprocess? (option-ref options 'preprocess #f))
130 (compile? (option-ref options 'compile #f))
131 (assemble? (option-ref options 'assemble #f))
132 (verbose? (option-ref options 'verbose (getenv "MES_DEBUG"))))
134 (setenv "NYACC_TRACE" "yes")
135 (format (current-error-port) "options=~s\n" options))
136 (cond (preprocess? (mescc:preprocess options))
137 (compile? (mescc:compile options))
138 (assemble? (mescc:assemble options))
139 (else (mescc:link options)))))