Skip to content

Instantly share code, notes, and snippets.

@Pinjontall94
Created May 2, 2025 21:25
Show Gist options
  • Select an option

  • Save Pinjontall94/f87efa8731690b9b715556ddc5b0b430 to your computer and use it in GitHub Desktop.

Select an option

Save Pinjontall94/f87efa8731690b9b715556ddc5b0b430 to your computer and use it in GitHub Desktop.
sconfig.scm (Guile autoconf generator)
; SPDX-FileCopyrightText: 2025 Sammi Johnson <[email protected]>
;
; SPDX-License-Identifier: AGPL-3.0-or-later
;; Guile Autoconf Generator
(define-module (sconfig))
;; Autoconf config constructor
(define (<ac> proj-name version email)
(let metaconfig ((ac-options-alist (list (list 'init proj-name version email))))
(cond ((= msg 'config) (set! metaconfig (ac/config metaconfig))) ;; ac-config (-> metaconfig metaconfig)
((= msg 'programs (set! metconfig (ac/programs metaconfig))))
((= msg 'output) (ac->autoconf-file-string ac))
(#t (error (format #t "unrecognized message ~A~%" msg)))))
metaconfig)
(define (program-in-path? executable)
(let ((path (parse-path (getenv "PATH"))))
(if (access? executable X_OK)
#t
(access? (or (search-path path executable) "") X_OK))))
;; Program list test runner
(define (ac-test metaconfig program-list)
(map (lambda (prog)
(if (program-in-path? prog) #t #f))
metaconfig))
(define-public (sconfig/metaconfig proj-name proj-version proj-email)
(let ((ac (<ac> (list 'init (list proj-name proj-version proj-email)))))
(and
(ac 'config (list 'srcdir "project.scm"
'aux-dir "build-aux"
'macro-dirs "m4"
'files (list "Makefile"
(list "pre-inst-env" "chmod +x pre-inst-env")
(list "scripts/project" "chmod +x scripts/project"))))
(ac 'programs (list 'guile-pkg (list "3.0")
'guile-progs)))))
;; (define %program-list (list "guild"))
(define (sconfig/generate-configure-ac metaconfig program-list)
(if (sconfig/test)
(with-output-to-file "configure.ac" (ac 'output))))
;;; Usage:
;;; scheme@(guile-user)> (sconfig/generate-configure-ac (sconfig/metaconfig "my-project" "0.0.1" "[email protected]") '("guild"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment