From fc9496f66e213dcc48f80b41dff0e0252c1846e6 Mon Sep 17 00:00:00 2001 From: Case Duckworth Date: Wed, 5 Jun 2024 12:51:57 -0500 Subject: Improve! --- Makefile | 25 +++++++++++--------- scramble.scm | 74 ++++++++++++++++++++++++++++++++++++------------------------ 2 files changed, 58 insertions(+), 41 deletions(-) diff --git a/Makefile b/Makefile index 7ecdf53..9d87ce2 100644 --- a/Makefile +++ b/Makefile @@ -2,30 +2,33 @@ NAME = scramble CSC = /usr/bin/csc -CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(PWD) +CSC_OPTIONS = -setup-mode -host -I $(BUILD) -C -I$(BUILD) 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) +TEST_ENV_EXTRA = TEST_USE_ANSI=0 +ARTEFACTS = *.build.sh *.install.sh $(NAME) *.import.scm *.so *.link *.o .PHONY: all test clean install uninstall all: build/scramble -test: $(BUILD) - cd $(BUILD) && $(TEST_ENV) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) +test: all + cd $(BUILD) && \ + $(TEST_ENV) $(TEST_ENV_EXTRA) \ + $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) clean: - -rm -rf $(BUILD) *.build.sh *.install.sh $(NAME) *.import.scm *.so *.link *.static.o + -rm -rf $(BUILD) $(ARTEFACTS) install: chicken-install -s + @-rm -rf $(ARTEFACTS) uninstall: - chicken-uninstall -s + chicken-uninstall -s $(NAME) # scramble -$(BUILD): - -mkdir $(BUILD) -build/scramble: scramble.scm $(BUILD) - cd $(BUILD) && \ - $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F) - @if test -f scramble.import.scm;then mv scramble.import.scm $(BUILD)/;echo mv scramble.import.scm $(BUILD)/; fi +build/scramble: scramble.scm + @mkdir -p $(BUILD) + $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@ + @test -f scramble.import.scm && mv scramble.import.scm $(BUILD)/ ||true diff --git a/scramble.scm b/scramble.scm index 79d6874..8f1ac19 100644 --- a/scramble.scm +++ b/scramble.scm @@ -14,8 +14,8 @@ (define csc-options '("-setup-mode" "-host" - "-I $(PWD)" - "-C -I$(PWD)")) + "-I $(BUILD)" + "-C -I$(BUILD)")) (define csc-lib-options '("-D compiling-extension" "-emit-all-import-libraries" "-dynamic" @@ -119,19 +119,18 @@ (define (rule c) (let ((deps (alist-ref c (dependency-graph)))) - (sprintf "~a: ~a $(BUILD)\n\t~a\n\t~a\n\t~a" - (relativize (output-of c)) - (string-join (cons (relativize (source-of (car deps))) - (map (o relativize output-of) (cdr deps)))) - "cd $(BUILD) && \\" - (string-append "$(CSC) $(CSC_OPTIONS)" - (if (eq? (car (find-component c)) 'extension) - " $(CSC_LIB_OPTIONS)" "") - " $(CSC_OPTIONS_EXTRA) ../$< -o $(@F)") - (string-append "@if test -f " (->string c) ".import.scm;" - "then mv " (->string c) ".import.scm $(BUILD)/;" - "echo mv " (->string c) ".import.scm $(BUILD)/;" - " fi")))) + (print-rule (relativize (output-of c)) + (cons (relativize (source-of (car deps))) + (map (o relativize source-of) (cdr deps))) + "@mkdir -p $(BUILD)" + `("$(CSC) $(CSC_OPTIONS)" + ,(if (eq? (car (find-component c)) 'extension) + "$CSC_LIB_OPTIONS" "") + "$(CSC_OPTIONS_EXTRA)" + "$< -o $@") + (let ((.import.scm (string-append (->string c) ".import.scm"))) + (list "@test -f" .import.scm "&&" + "mv" .import.scm "$(BUILD)/" "||true"))))) (define (relativize pn) (let ((ed (string-append @@ -143,9 +142,16 @@ (substring pn (string-length ed)) pn))) +(define (print-rule target deps . commands) + (define (list?->string x) (if (list? x) (string-join x) x)) + (print target ": " (list?->string deps)) + (for-each (lambda (c) (print "\t" (list?->string c))) + commands)) + (define (emit-makefile egg-file) (parameterize ((egg (read-egg egg-file))) - (print "# Automatically generated by scramble") (newline) + (print "# Automatically generated by scramble") + (newline) (print "NAME = " (egg-name)) (print "CSC = " (find-executable "csc")) (print "CSC_OPTIONS = " (string-join csc-options)) @@ -155,21 +161,29 @@ (print "BUILD = $(PWD)/" (build-dir)) (print "TESTS = $(PWD)/tests") (print "TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS)") + (print "TEST_ENV_EXTRA = TEST_USE_ANSI=0") + (print "ARTEFACTS = *.build.sh *.install.sh $(NAME)" + " *.import.scm *.so *.link *.o") + (newline) + (print-rule ".PHONY" "all test clean install uninstall") + (print-rule "all" (map (o relativize output-of car) + (dependency-graph))) + (print-rule "test" "all" + "cd $(BUILD) && \\" + "$(TEST_ENV) $(TEST_ENV_EXTRA) \\" + "$(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME)") + (print-rule "clean" "" + "-rm -rf $(BUILD) $(ARTEFACTS)") + (print-rule "install" "" + "chicken-install -s" + "@-rm -rf $(ARTEFACTS)") + (print-rule "uninstall" "" + "chicken-uninstall -s $(NAME)") + (newline) + (print "# " (egg-name)) (newline) - (print ".PHONY: all test clean install uninstall") - (print "all: " (string-join (map (o relativize 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)" - " *.build.sh *.install.sh $(NAME)" - " *.import.scm *.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 rule cadr) + (egg-components)))) (define (main args) (let ((egg-file (if (null? args) (current-directory) (car args)))) -- cgit 1.4.1-21-gabe81