;; Ensure proper version of Gauche is used while building Gauche from repo.
;;
;; Some files required to build Gauche must be generated by Gauche.  In the
;; release tarball, such files are pre-generated by the packaging process,
;; so users won't need to have Gauche pre-installed.
;; However, if you build from the Git repo source, you need to have working
;; Gauche on your machine to generate them.
;; As a rule, you need the latest release of Gauche, to build from the repo.
;; This small script checks that.

(use gauche.version)

(define (msg target-version)
  #"!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\
  \n\
  \n   To build Gauche from scratch, you need the latest release of Gauche\
  \n   on your machine.  You seem to have ~(gauche-version)\
  \n   Update it to ~|target-version| before proceeding.\
  \n\
  \n!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")

(define (main args)
  (if (null? (cdr args))
    (exit 1 "Usage: gosh check-build-version $BUILD_GOSH_VERSION")
    (let1 target-version (cadr args)
      (if (version<? (gauche-version) target-version)
        (exit 1 (msg target-version))
        (exit 0)))))

;; Local variables:
;; mode: scheme
;; end:
