From 37ec56fb141edbb1bab675e3d35f4ca36e5139f7 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Tue, 28 May 2024 22:42:37 -0500 Subject: Version 1 :) --- .gitignore | 1 + Makefile | 30 +++++++++++++++++++++++ scramble.egg | 8 +++++++ scramble.scm | 77 ++++++++++++++++++++++++++++++++++++++---------------------- 4 files changed, 88 insertions(+), 28 deletions(-) create mode 100644 .gitignore create mode 100644 Makefile create mode 100644 scramble.egg diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d163863 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +build/ \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2ac521f --- /dev/null +++ b/Makefile @@ -0,0 +1,30 @@ +# Automatically generated by scramble + +NAME = scramble +CSC = /usr/bin/csc +CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(PWD) +CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries +CSC_OPTIONS_EXTRA = -X utf8 +CSI = /usr/bin/csi +BUILD = $(PWD)/build +TESTS = $(PWD)/tests +TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS) + +.PHONY: all test clean install uninstall +all: /home/acdw/src/scramble/build/scramble +test: $(BUILD) + cd $(BUILD) && $(TEST_ENV) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) +clean: + -rm -rf $(BUILD) *.build.sh *.install.sh $(NAME) *.import.scm *.import.so *.link *.static.o +install: + chicken-install -s +uninstall: + chicken-uninstall -s + +# scramble + +$(BUILD): + -mkdir $(BUILD) +/home/acdw/src/scramble/build/scramble: /home/acdw/src/scramble/scramble.scm $(BUILD) + $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ + @if test -f scramble.import.scm;then mv scramble.import.scm $(BUILD)/;echo mv scramble.import.scm $(BUILD)/; fi diff --git a/scramble.egg b/scramble.egg new file mode 100644 index 0000000..28df21b --- /dev/null +++ b/scramble.egg @@ -0,0 +1,8 @@ +((author "Case Duckworth") + (synopsis "Convert an egg to a Makefile") + (dependencies (chicken "5.3.0") utf8 srfi-1) + ;; (test-dependencies test) + (component-options + (csc-options -X utf8)) + (components + (program scramble))) diff --git a/scramble.scm b/scramble.scm index e79fbe0..591ebad 100644 --- a/scramble.scm +++ b/scramble.scm @@ -1,7 +1,6 @@ -(declare (module scramble)) - (import scheme (chicken base) (chicken file) + (chicken file posix) (chicken format) (chicken pathname) (chicken process) @@ -9,22 +8,17 @@ (chicken string) (srfi 1)) -;; dependencies should be like -;; (((output jimmy.util) (source jimmy.util)) -;; ((output jimmy.read) (source jimmy.read) (source jimmy.util)) -;; ((output jimmy.emit) (source jimmy.emit) (source jimmy.util))) - (define egg (make-parameter #f)) (define build-dir (make-parameter "build")) (define csc-options '("-setup-mode" "-host" - "-D compiling-extension" - "-emit-all-import-libraries" - "-dynamic" - "-regenerate-import-libraries" "-I $(PWD)" "-C -I$(PWD)")) +(define csc-lib-options '("-D compiling-extension" + "-emit-all-import-libraries" + "-dynamic" + "-regenerate-import-libraries")) (define source-extensions ;; The possible extensions source files can take. @@ -32,10 +26,18 @@ (define (read-egg #!optional egg-file) ;; Read EGG-FILE and return the structure inside. - (unless egg-file - (set! egg-file - (receive (_ _ dirs) (decompose-directory (current-directory)) - (make-pathname (current-directory) (car (reverse dirs)) "egg")))) + (define (last-dir pn) (pathname-file pn)) + (set! egg-file + (cond + ((not egg-file) + (make-pathname (current-directory) (last-dir (current-directory)) "egg")) + ((directory? egg-file) + (assert (directory-exists? egg-file) + "Egg directory doesn't exist" egg-file) + (let ((dir egg-file)) + (make-pathname dir (last-dir dir) "egg"))) + (else egg-file))) + (assert (file-exists? egg-file) "Can't find egg file" egg-file) (assert (file-readable? egg-file) "Can't read egg file" egg-file) (cons* `(egg-directory ,(pathname-directory egg-file)) @@ -59,11 +61,11 @@ (if (list? dirs) dirs (list dirs))) file ext)))) (else - (let loop ((ext (source-extensions))) - (if (null? ext) #f - (let ((cand (make-pathname (egg-directory) c ext))) + (let loop ((exts (source-extensions))) + (if (null? exts) #f + (let ((cand (make-pathname (egg-directory) (->string c) (car exts)))) (if (file-exists? cand) cand - (loop (cdr ext))))))))) + (loop (cdr exts))))))))) (define (output-of c) ;; Return the output file of C. It's okay if it doesn't exist. @@ -71,7 +73,7 @@ (->string c) (case (car (find-component c)) ((extension) "so") - ((program))))) + ((program) "")))) (define (find-component name) (find (lambda (c) (eq? name (cadr c))) @@ -119,12 +121,18 @@ (define (rule c) (let ((deps (alist-ref c (dependency-graph)))) - (sprintf "~a: ~a $(BUILD)\n\t~a\n\t-mv ~a.import.scm $(BUILD)/" + (sprintf "~a: ~a $(BUILD)\n\t~a\n\t~a" (output-of c) (string-join (cons (source-of (car deps)) (map output-of (cdr deps)))) - "$(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@" - c))) + (string-append "$(CSC) $(CSC_OPTIONS)" + (if (eq? (car (find-component c)) 'extension) + " $(CSC_LIB_OPTIONS)" "") + " $(CSC_OPTIONS_EXTRA) $< -o $@") + (string-append "@if test -f " (->string c) ".import.scm;" + "then mv " (->string c) ".import.scm $(BUILD)/;" + "echo mv " (->string c) ".import.scm $(BUILD)/;" + " fi")))) (define (emit-makefile egg-file) (parameterize ((egg (read-egg egg-file))) @@ -132,6 +140,7 @@ (print "NAME = " (egg-name)) (print "CSC = " (find-executable "csc")) (print "CSC_OPTIONS = " (string-join csc-options)) + (print "CSC_LIB_OPTIONS = " (string-join csc-lib-options)) (print "CSC_OPTIONS_EXTRA = " (string-join (egg-csc-options))) (print "CSI = " (find-executable "csi")) (print "BUILD = $(PWD)/" (build-dir)) @@ -139,14 +148,26 @@ (print "TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS)") (newline) (print ".PHONY: all test clean install uninstall") - (print "all: " (string-join (map (o source-of car) (dependency-graph)))) - (print "test: build" + (print "all: " (string-join (map (o output-of car) (dependency-graph)))) + (print "test: $(BUILD)" "\n\t" "cd $(BUILD) && " "$(TEST_ENV) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME)") - (print "clean:\n\t-rm -rf $(BUILD)") + (print "clean:\n\t-rm -rf $(BUILD)" + " *.build.sh *.install.sh $(NAME)" + " *.import.scm *.import.so *.link *.static.o") (print "install:\n\tchicken-install -s") (print "uninstall:\n\tchicken-uninstall -s") (newline) (print "# " (egg-name)) (newline) (print "$(BUILD):\n\t-mkdir $(BUILD)") - (for-each (o print rule cadr) (egg-components)) - )) + (for-each (o print rule cadr) (egg-components)))) + +(define (main args) + (let ((egg-file (if (null? args) (current-directory) (car args)))) + ;; TODO: allow customizing build directory + (emit-makefile egg-file))) + +(cond-expand + ((or chicken-script compiling) + (import (chicken process-context)) + (main (command-line-arguments))) + (else)) -- cgit 1.4.1-21-gabe81