about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorCase Duckworth2024-06-05 12:51:57 -0500
committerCase Duckworth2024-06-05 12:51:57 -0500
commitfc9496f66e213dcc48f80b41dff0e0252c1846e6 (patch)
tree4e0b6fb0f0101c34b31300610724952103986aee
parentCorrect path stuff for build/ building (diff)
downloadscramble-fc9496f66e213dcc48f80b41dff0e0252c1846e6.tar.gz
scramble-fc9496f66e213dcc48f80b41dff0e0252c1846e6.zip
Improve!
-rw-r--r--Makefile25
-rw-r--r--scramble.scm74
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 @@
2 2
3NAME = scramble 3NAME = scramble
4CSC = /usr/bin/csc 4CSC = /usr/bin/csc
5CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(PWD) 5CSC_OPTIONS = -setup-mode -host -I $(BUILD) -C -I$(BUILD)
6CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries 6CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries
7CSC_OPTIONS_EXTRA = -X utf8 7CSC_OPTIONS_EXTRA = -X utf8
8CSI = /usr/bin/csi 8CSI = /usr/bin/csi
9BUILD = $(PWD)/build 9BUILD = $(PWD)/build
10TESTS = $(PWD)/tests 10TESTS = $(PWD)/tests
11TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS) 11TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS)
12TEST_ENV_EXTRA = TEST_USE_ANSI=0
13ARTEFACTS = *.build.sh *.install.sh $(NAME) *.import.scm *.so *.link *.o
12 14
13.PHONY: all test clean install uninstall 15.PHONY: all test clean install uninstall
14all: build/scramble 16all: build/scramble
15test: $(BUILD) 17test: all
16 cd $(BUILD) && $(TEST_ENV) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME) 18 cd $(BUILD) && \
19 $(TEST_ENV) $(TEST_ENV_EXTRA) \
20 $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME)
17clean: 21clean:
18 -rm -rf $(BUILD) *.build.sh *.install.sh $(NAME) *.import.scm *.so *.link *.static.o 22 -rm -rf $(BUILD) $(ARTEFACTS)
19install: 23install:
20 chicken-install -s 24 chicken-install -s
25 @-rm -rf $(ARTEFACTS)
21uninstall: 26uninstall:
22 chicken-uninstall -s 27 chicken-uninstall -s $(NAME)
23 28
24# scramble 29# scramble
25 30
26$(BUILD): 31build/scramble: scramble.scm
27 -mkdir $(BUILD) 32 @mkdir -p $(BUILD)
28build/scramble: scramble.scm $(BUILD) 33 $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) $< -o $@
29 cd $(BUILD) && \ 34 @test -f scramble.import.scm && mv scramble.import.scm $(BUILD)/ ||true
30 $(CSC) $(CSC_OPTIONS) $(CSC_OPTIONS_EXTRA) ../$< -o $(@F)
31 @if test -f scramble.import.scm;then mv scramble.import.scm $(BUILD)/;echo mv scramble.import.scm $(BUILD)/; fi
diff --git a/scramble.scm b/scramble.scm index 79d6874..8f1ac19 100644 --- a/scramble.scm +++ b/scramble.scm
@@ -14,8 +14,8 @@
14 14
15(define csc-options '("-setup-mode" 15(define csc-options '("-setup-mode"
16 "-host" 16 "-host"
17 "-I $(PWD)" 17 "-I $(BUILD)"
18 "-C -I$(PWD)")) 18 "-C -I$(BUILD)"))
19(define csc-lib-options '("-D compiling-extension" 19(define csc-lib-options '("-D compiling-extension"
20 "-emit-all-import-libraries" 20 "-emit-all-import-libraries"
21 "-dynamic" 21 "-dynamic"
@@ -119,19 +119,18 @@
119 119
120(define (rule c) 120(define (rule c)
121 (let ((deps (alist-ref c (dependency-graph)))) 121 (let ((deps (alist-ref c (dependency-graph))))
122 (sprintf "~a: ~a $(BUILD)\n\t~a\n\t~a\n\t~a" 122 (print-rule (relativize (output-of c))
123 (relativize (output-of c)) 123 (cons (relativize (source-of (car deps)))
124 (string-join (cons (relativize (source-of (car deps))) 124 (map (o relativize source-of) (cdr deps)))
125 (map (o relativize output-of) (cdr deps)))) 125 "@mkdir -p $(BUILD)"
126 "cd $(BUILD) && \\" 126 `("$(CSC) $(CSC_OPTIONS)"
127 (string-append "$(CSC) $(CSC_OPTIONS)" 127 ,(if (eq? (car (find-component c)) 'extension)
128 (if (eq? (car (find-component c)) 'extension) 128 "$CSC_LIB_OPTIONS" "")
129 " $(CSC_LIB_OPTIONS)" "") 129 "$(CSC_OPTIONS_EXTRA)"
130 " $(CSC_OPTIONS_EXTRA) ../$< -o $(@F)") 130 "$< -o $@")
131 (string-append "@if test -f " (->string c) ".import.scm;" 131 (let ((.import.scm (string-append (->string c) ".import.scm")))
132 "then mv " (->string c) ".import.scm $(BUILD)/;" 132 (list "@test -f" .import.scm "&&"
133 "echo mv " (->string c) ".import.scm $(BUILD)/;" 133 "mv" .import.scm "$(BUILD)/" "||true")))))
134 " fi"))))
135 134
136(define (relativize pn) 135(define (relativize pn)
137 (let ((ed (string-append 136 (let ((ed (string-append
@@ -143,9 +142,16 @@
143 (substring pn (string-length ed)) 142 (substring pn (string-length ed))
144 pn))) 143 pn)))
145 144
145(define (print-rule target deps . commands)
146 (define (list?->string x) (if (list? x) (string-join x) x))
147 (print target ": " (list?->string deps))
148 (for-each (lambda (c) (print "\t" (list?->string c)))
149 commands))
150
146(define (emit-makefile egg-file) 151(define (emit-makefile egg-file)
147 (parameterize ((egg (read-egg egg-file))) 152 (parameterize ((egg (read-egg egg-file)))
148 (print "# Automatically generated by scramble") (newline) 153 (print "# Automatically generated by scramble")
154 (newline)
149 (print "NAME = " (egg-name)) 155 (print "NAME = " (egg-name))
150 (print "CSC = " (find-executable "csc")) 156 (print "CSC = " (find-executable "csc"))
151 (print "CSC_OPTIONS = " (string-join csc-options)) 157 (print "CSC_OPTIONS = " (string-join csc-options))
@@ -155,21 +161,29 @@
155 (print "BUILD = $(PWD)/" (build-dir)) 161 (print "BUILD = $(PWD)/" (build-dir))
156 (print "TESTS = $(PWD)/tests") 162 (print "TESTS = $(PWD)/tests")
157 (print "TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS)") 163 (print "TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS)")
164 (print "TEST_ENV_EXTRA = TEST_USE_ANSI=0")
165 (print "ARTEFACTS = *.build.sh *.install.sh $(NAME)"
166 " *.import.scm *.so *.link *.o")
167 (newline)
168 (print-rule ".PHONY" "all test clean install uninstall")
169 (print-rule "all" (map (o relativize output-of car)
170 (dependency-graph)))
171 (print-rule "test" "all"
172 "cd $(BUILD) && \\"
173 "$(TEST_ENV) $(TEST_ENV_EXTRA) \\"
174 "$(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME)")
175 (print-rule "clean" ""
176 "-rm -rf $(BUILD) $(ARTEFACTS)")
177 (print-rule "install" ""
178 "chicken-install -s"
179 "@-rm -rf $(ARTEFACTS)")
180 (print-rule "uninstall" ""
181 "chicken-uninstall -s $(NAME)")
182 (newline)
183 (print "# " (egg-name))
158 (newline) 184 (newline)
159 (print ".PHONY: all test clean install uninstall") 185 (for-each (o rule cadr)
160 (print "all: " (string-join (map (o relativize output-of car) 186 (egg-components))))
161 (dependency-graph))))
162 (print "test: $(BUILD)"
163 "\n\t" "cd $(BUILD) && "
164 "$(TEST_ENV) $(CSI) -setup-mode -s $(TESTS)/run.scm $(NAME)")
165 (print "clean:\n\t-rm -rf $(BUILD)"
166 " *.build.sh *.install.sh $(NAME)"
167 " *.import.scm *.so *.link *.static.o")
168 (print "install:\n\tchicken-install -s")
169 (print "uninstall:\n\tchicken-uninstall -s")
170 (newline) (print "# " (egg-name)) (newline)
171 (print "$(BUILD):\n\t-mkdir $(BUILD)")
172 (for-each (o print rule cadr) (egg-components))))
173 187
174(define (main args) 188(define (main args)
175 (let ((egg-file (if (null? args) (current-directory) (car args)))) 189 (let ((egg-file (if (null? args) (current-directory) (car args))))