diff options
author | Case Duckworth | 2024-06-05 12:51:57 -0500 |
---|---|---|
committer | Case Duckworth | 2024-06-05 12:51:57 -0500 |
commit | fc9496f66e213dcc48f80b41dff0e0252c1846e6 (patch) | |
tree | 4e0b6fb0f0101c34b31300610724952103986aee | |
parent | Correct path stuff for build/ building (diff) | |
download | scramble-fc9496f66e213dcc48f80b41dff0e0252c1846e6.tar.gz scramble-fc9496f66e213dcc48f80b41dff0e0252c1846e6.zip |
Improve!
-rw-r--r-- | Makefile | 25 | ||||
-rw-r--r-- | 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 @@ | |||
2 | 2 | ||
3 | NAME = scramble | 3 | NAME = scramble |
4 | CSC = /usr/bin/csc | 4 | CSC = /usr/bin/csc |
5 | CSC_OPTIONS = -setup-mode -host -I $(PWD) -C -I$(PWD) | 5 | CSC_OPTIONS = -setup-mode -host -I $(BUILD) -C -I$(BUILD) |
6 | CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries | 6 | CSC_LIB_OPTIONS = -D compiling-extension -emit-all-import-libraries -dynamic -regenerate-import-libraries |
7 | CSC_OPTIONS_EXTRA = -X utf8 | 7 | CSC_OPTIONS_EXTRA = -X utf8 |
8 | CSI = /usr/bin/csi | 8 | CSI = /usr/bin/csi |
9 | BUILD = $(PWD)/build | 9 | BUILD = $(PWD)/build |
10 | TESTS = $(PWD)/tests | 10 | TESTS = $(PWD)/tests |
11 | TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS) | 11 | TEST_ENV = env BUILD=$(BUILD) TESTS=$(TESTS) |
12 | TEST_ENV_EXTRA = TEST_USE_ANSI=0 | ||
13 | ARTEFACTS = *.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 |
14 | all: build/scramble | 16 | all: build/scramble |
15 | test: $(BUILD) | 17 | test: 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) | ||
17 | clean: | 21 | clean: |
18 | -rm -rf $(BUILD) *.build.sh *.install.sh $(NAME) *.import.scm *.so *.link *.static.o | 22 | -rm -rf $(BUILD) $(ARTEFACTS) |
19 | install: | 23 | install: |
20 | chicken-install -s | 24 | chicken-install -s |
25 | @-rm -rf $(ARTEFACTS) | ||
21 | uninstall: | 26 | uninstall: |
22 | chicken-uninstall -s | 27 | chicken-uninstall -s $(NAME) |
23 | 28 | ||
24 | # scramble | 29 | # scramble |
25 | 30 | ||
26 | $(BUILD): | 31 | build/scramble: scramble.scm |
27 | -mkdir $(BUILD) | 32 | @mkdir -p $(BUILD) |
28 | build/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)))) |