From cd70c63a40c586eaeae83fa3a1c7b40f4eae5796 Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Thu, 8 Nov 2018 14:46:46 +0100 Subject: [PATCH] mescc: Exit if library cannot be found. * module/mescc/mescc.scm (arch-find): Exit upon failure. --- module/mescc/mescc.scm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/module/mescc/mescc.scm b/module/mescc/mescc.scm index e3d93a1e..875530d4 100644 --- a/module/mescc/mescc.scm +++ b/module/mescc/mescc.scm @@ -205,7 +205,9 @@ ((equal? machine "64") "2") (else "1"))) (base-address (option-ref options 'base-address "0x1000000")) - (elf-footer (or elf-footer (arch-find options (string-append"elf" machine "-footer-single-main.hex2")))) + (elf-footer (or elf-footer + (arch-find options (string-append + "elf" machine "-footer-single-main.hex2")))) (command `(,hex2 "--LittleEndian" "--Architecture" ,architecture @@ -246,8 +248,15 @@ (define (replace-suffix file-name suffix) (let* ((parts (string-split file-name #\.)) - (base (if (pair? (cdr parts)) (drop-right parts 1)))) - (string-append (string-join base ".") suffix))) + (base (if (pair? (cdr parts)) (drop-right parts 1))) + (old-suffix (last parts)) + (program-prefix (cond ((string-prefix? "x86-mes-" old-suffix) ".x86-mes-") + ((string-prefix? "x86_64-mes-" old-suffix) ".x86_64-mes-") + (else ".")))) + (if (string-null? suffix) + (if (string-null? program-prefix) (string-join base ".") + (string-append (string-drop program-prefix 1) (string-join base "."))) + (string-append (string-join base ".") program-prefix (string-drop suffix 1))))) (define (find-library options ext o) (arch-find options (string-append "lib" o ext))) @@ -265,11 +274,13 @@ (filter-map (multi-opt 'library-dir) options))) (arch-file-name (string-append arch "/" file-name)) (verbose? (option-ref options 'verbose #f))) - (when verbose? - (stderr "arch-find=~s\n" arch-file-name) - (stderr " path=~s\n" path) - (stderr " => ~s\n" (search-path path arch-file-name))) - (search-path path arch-file-name))) + (let ((file (search-path path arch-file-name))) + (when verbose? + (stderr "arch-find=~s\n" arch-file-name) + (stderr " path=~s\n" path) + (stderr " => ~s\n" file)) + (or file + (error (format #f "mescc: file not found: ~s" arch-file-name)))))) (define (prefix-file options file-name) (let ((prefix (option-ref options 'prefix "")))