2016-10-12 21:40:11 +00:00
|
|
|
#! /bin/sh
|
|
|
|
# -*-scheme-*-
|
2018-05-25 06:05:02 +00:00
|
|
|
if [ -n "$BUILD_DEBUG" ]; then
|
|
|
|
set -x
|
|
|
|
fi
|
2018-07-09 08:46:28 +00:00
|
|
|
prefix=${prefix-@prefix@}
|
|
|
|
if [ "@prefix@" = @prefix""@ -o ! -d "$prefix/share/mes/module" ]
|
2018-05-25 06:05:02 +00:00
|
|
|
then
|
2018-07-21 05:15:52 +00:00
|
|
|
MES_PREFIX=${MES_PREFIX-$(cd $(dirname $0)/.. && pwd)/mes}
|
2018-05-29 18:07:46 +00:00
|
|
|
else
|
2018-07-09 08:46:28 +00:00
|
|
|
MES_PREFIX=${MES_PREFIX-$prefix/share/mes}
|
2018-05-25 06:05:02 +00:00
|
|
|
fi
|
2018-05-29 18:07:46 +00:00
|
|
|
export MES_PREFIX
|
2018-05-03 18:32:06 +00:00
|
|
|
mes_p=$(command -v mes)
|
2018-07-21 05:15:52 +00:00
|
|
|
|
|
|
|
guile_site_dir=${guile_site_dir-@guile_site_dir@}
|
|
|
|
[ "$guile_site_dir" = @"guile_site_dir"@ ] && guile_site_dir=$(dirname $0)/../module
|
|
|
|
GUILE_LOAD_PATH=$guile_site_dir:$GUILE_LOAD_PATH
|
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
if [ '(' -z "$mes_p" -a -z "$MES" ')' -o "$MES" = "guile" -o "$MES" = "mes.guile" ]; then
|
2018-07-09 08:46:28 +00:00
|
|
|
guile_site_ccache_dir=${guile_site_ccache_dir-@guile_site_ccache_dir@}
|
2018-07-21 05:15:52 +00:00
|
|
|
[ "$guile_site_ccache_dir" = @"guile_site_ccache_dir"@ ] && guile_site_ccache_dir=$(dirname $0)/../module
|
|
|
|
GUILE_LOAD_COMPILED_PATH=$guile_site_ccache_dir:$GUILE_LOAD_COMPILED_PATH
|
2018-07-09 08:46:28 +00:00
|
|
|
GUILE_AUTO_COMPILE=${GUILE_AUTO_COMPILE-0}
|
|
|
|
export GUILE_AUTO_COMPILE
|
|
|
|
exec ${GUILE-guile} -L $guile_site_dir -e '(mescc)' -s "$0" "$@"
|
2018-04-27 21:47:31 +00:00
|
|
|
else
|
|
|
|
MES=${MES-$(dirname $0)/mes}
|
2018-05-04 08:12:34 +00:00
|
|
|
exec ${MES-mes} -e '(mescc)' -s $0 "$@"
|
2017-12-09 21:38:51 +00:00
|
|
|
fi
|
2016-10-12 21:40:11 +00:00
|
|
|
!#
|
|
|
|
|
|
|
|
;;; Mes --- Maxwell Equations of Software
|
2017-11-21 18:22:26 +00:00
|
|
|
;;; Copyright © 2016,2017,2018 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
|
2016-10-12 21:40:11 +00:00
|
|
|
;;;
|
2016-12-18 14:44:09 +00:00
|
|
|
;;; This file is part of Mes.
|
2016-10-12 21:40:11 +00:00
|
|
|
;;;
|
|
|
|
;;; Mes is free software; you can redistribute it and/or modify it
|
|
|
|
;;; under the terms of the GNU General Public License as published by
|
|
|
|
;;; the Free Software Foundation; either version 3 of the License, or (at
|
|
|
|
;;; your option) any later version.
|
|
|
|
;;;
|
|
|
|
;;; Mes is distributed in the hope that it will be useful, but
|
|
|
|
;;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
;;; GNU General Public License for more details.
|
|
|
|
;;;
|
|
|
|
;;; You should have received a copy of the GNU General Public License
|
|
|
|
;;; along with Mes. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
(define-module (mescc)
|
|
|
|
#:use-module (ice-9 getopt-long)
|
2018-05-25 06:05:02 +00:00
|
|
|
#:use-module (mes misc)
|
|
|
|
#:use-module (mescc mescc)
|
2018-04-27 21:47:31 +00:00
|
|
|
#:export (main))
|
2016-10-12 21:40:11 +00:00
|
|
|
|
2018-05-29 18:07:46 +00:00
|
|
|
(define %prefix (or (getenv "MES_PREFIX")
|
2018-07-09 08:46:28 +00:00
|
|
|
(if (string-prefix? "@prefix" "@prefix@")
|
2018-05-29 18:07:46 +00:00
|
|
|
""
|
2018-07-09 08:46:28 +00:00
|
|
|
"@prefix@/share/mes")))
|
2016-10-12 21:40:11 +00:00
|
|
|
|
2018-05-25 06:05:02 +00:00
|
|
|
(define %version (if (string-prefix? "@VERSION" "@VERSION@") "git"
|
|
|
|
"@VERSION@"))
|
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
(cond-expand
|
|
|
|
(mes
|
2018-05-25 06:05:02 +00:00
|
|
|
(define (set-port-encoding! port encoding) #t)
|
|
|
|
(mes-use-module (mes guile))
|
|
|
|
(mes-use-module (mes misc))
|
|
|
|
(mes-use-module (mes getopt-long))
|
|
|
|
(mes-use-module (mes display))
|
|
|
|
(mes-use-module (mescc mescc)))
|
2018-04-27 21:47:31 +00:00
|
|
|
(guile
|
2018-05-25 06:05:02 +00:00
|
|
|
(define-macro (mes-use-module . rest) #t)))
|
2016-12-31 08:03:07 +00:00
|
|
|
|
2018-04-27 21:47:31 +00:00
|
|
|
(format (current-error-port) "mescc[~a]...\n" %scheme)
|
2017-04-02 16:50:07 +00:00
|
|
|
|
2017-05-17 11:56:25 +00:00
|
|
|
(define (parse-opts args)
|
|
|
|
(let* ((option-spec
|
2018-05-25 06:05:02 +00:00
|
|
|
'((assemble (single-char #\c))
|
|
|
|
(compile (single-char #\S))
|
2018-01-02 06:05:41 +00:00
|
|
|
(define (single-char #\D) (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(debug-info (single-char #\g))
|
2017-05-17 11:56:25 +00:00
|
|
|
(help (single-char #\h))
|
2018-01-02 06:05:41 +00:00
|
|
|
(include (single-char #\I) (value #t))
|
2018-05-29 18:07:46 +00:00
|
|
|
(library-dir (single-char #\L) (value #t))
|
2018-05-25 06:05:02 +00:00
|
|
|
(library (single-char #\l) (value #t))
|
|
|
|
(preprocess (single-char #\E))
|
|
|
|
(output (single-char #\o) (value #t))
|
2018-04-27 21:47:31 +00:00
|
|
|
(version (single-char #\V))
|
2018-05-25 06:05:02 +00:00
|
|
|
(verbose (single-char #\v))
|
2018-04-27 21:47:31 +00:00
|
|
|
(write (single-char #\w) (value #t))))
|
2017-05-22 17:22:18 +00:00
|
|
|
(options (getopt-long args option-spec))
|
|
|
|
(help? (option-ref options 'help #f))
|
|
|
|
(files (option-ref options '() '()))
|
|
|
|
(usage? (and (not help?) (null? files)))
|
2017-05-17 11:56:25 +00:00
|
|
|
(version? (option-ref options 'version #f)))
|
|
|
|
(or
|
|
|
|
(and version?
|
2018-04-27 21:47:31 +00:00
|
|
|
(format (current-output-port) "mescc (mes) ~a\n" %version))
|
2017-05-17 11:56:25 +00:00
|
|
|
(and (or help? usage?)
|
|
|
|
(format (or (and usage? (current-error-port)) (current-output-port)) "\
|
2018-04-27 21:47:31 +00:00
|
|
|
Usage: mescc [OPTION]... FILE...
|
2018-05-25 06:05:02 +00:00
|
|
|
-c preprocess, compile and assemble only; do not link
|
|
|
|
-D DEFINE[=VALUE] define DEFINE [VALUE=1]
|
2017-05-22 17:22:18 +00:00
|
|
|
-E preprocess only; do not compile, assemble or link
|
2017-06-25 07:33:55 +00:00
|
|
|
-g add debug info [GDB, objdump] TODO: hex2 footer
|
2017-05-17 11:56:25 +00:00
|
|
|
-h, --help display this help and exit
|
|
|
|
-I DIR append DIR to include path
|
2018-05-29 18:07:46 +00:00
|
|
|
-L DIR append DIR to library path
|
2018-05-25 06:05:02 +00:00
|
|
|
-l LIBNAME link with LIBNAME
|
2017-05-17 11:56:25 +00:00
|
|
|
-o FILE write output to FILE
|
2018-05-25 06:05:02 +00:00
|
|
|
-S preprocess and compile only; do not assemble or link
|
2017-05-17 11:56:25 +00:00
|
|
|
-v, --version display version and exit
|
2018-04-27 21:47:31 +00:00
|
|
|
-w,--write=TYPE dump Nyacc AST using TYPE {pretty-print,write}
|
|
|
|
|
|
|
|
Environment variables:
|
|
|
|
|
|
|
|
MES=BINARY run on mes-executable BINARY {mes,guile}
|
|
|
|
MES_DEBUG=LEVEL show debug output with verbosity LEVEL {0..5}
|
|
|
|
NYACC_TRACE=1 show Nyacc progress
|
2017-05-17 11:56:25 +00:00
|
|
|
")
|
|
|
|
(exit (or (and usage? 2) 0)))
|
|
|
|
options)))
|
|
|
|
|
|
|
|
(define (main args)
|
2018-04-22 09:51:28 +00:00
|
|
|
(let* ((options (parse-opts args))
|
2018-05-25 06:05:02 +00:00
|
|
|
(options (acons 'prefix %prefix options))
|
|
|
|
(preprocess? (option-ref options 'preprocess #f))
|
|
|
|
(compile? (option-ref options 'compile #f))
|
|
|
|
(assemble? (option-ref options 'assemble #f))
|
|
|
|
(verbose? (option-ref options 'verbose (getenv "MES_DEBUG"))))
|
|
|
|
(when verbose?
|
2018-04-27 21:47:31 +00:00
|
|
|
(setenv "NYACC_TRACE" "yes")
|
2018-05-25 06:05:02 +00:00
|
|
|
(format (current-error-port) "options=~s\n" options))
|
|
|
|
(cond (preprocess? (mescc:preprocess options))
|
|
|
|
(compile? (mescc:compile options))
|
|
|
|
(assemble? (mescc:assemble options))
|
|
|
|
(else (mescc:link options)))))
|
2018-04-09 05:12:38 +00:00
|
|
|
'done
|