Skip to content
This repository was archived by the owner on Sep 13, 2019. It is now read-only.

Commit b1b9d2e

Browse files
committed
cs: initial cut at building on Windows
Add a "csbuild.bat" script that can build a "RacketCS.exe" executable. It's not yet right, because there should be a DLL the same as for "Racket.exe", but it's a start. Also, the makefiles that work with GNU `make` and `nmake` at the same time seem fragile, and it will be better to move the relevant build rules into Racket scripts.
1 parent ed4d9c5 commit b1b9d2e

28 files changed

+673
-58
lines changed

racket/src/cs/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# This makefile is used to a limited degree with nmake, but it mostly
2+
# intended for use as a GNU makefile.
3+
14
RACKET = ../../bin/racket
25
SCHEME = scheme
36

@@ -64,7 +67,7 @@ $(BUILDDIR)main.so: $(MAIN_DEPS) main.sps $(COMPILE_FILE_DEPS)
6467
$(COMPILE_FILE) main.sps $(MAIN_DEPS)
6568

6669
strip:
67-
${SCHEME} --script strip.ss $(MAIN_DEPS) $(BUILDDIR)racket.so
70+
$(SCHEME) --script strip.ss $(MAIN_DEPS) $(BUILDDIR)racket.so
6871

6972
rktl:
7073
$(MAKE) thread-rktl

racket/src/cs/absify.rkt

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,39 @@
11
#lang racket/base
2-
(require racket/path)
2+
(require racket/cmdline
3+
racket/path)
34

4-
(define arg0 (vector-ref (current-command-line-arguments) 0))
5-
(define exec? (equal? arg0 "--exec"))
5+
(define same-up? #f)
6+
(define exec? #f)
67

7-
(define p-arg-k (if exec? 1 0))
8-
9-
(define p
10-
(if exec?
11-
(let ([p (vector-ref (current-command-line-arguments) 1)])
12-
(if (path-element? (string->path p))
13-
(or (find-executable-path p)
14-
p)
15-
p))
16-
arg0))
17-
18-
(display (simplify-path (path->complete-path p)))
8+
(define-values (orig-p extras)
9+
(command-line
10+
#:once-each
11+
[("--same-up") "Leave path alone if it starts \"..\""
12+
(set! same-up? #t)]
13+
[("--exec") "Find executable path"
14+
(set! exec? #t)]
15+
#:args
16+
(path . extra)
17+
(values path extra)))
1918

19+
(cond
20+
[(and same-up?
21+
(eq? (car (explode-path orig-p)) 'up))
22+
(display orig-p)]
23+
[else
24+
(define p
25+
(if exec?
26+
(let ([p orig-p])
27+
(if (path-element? (string->path p))
28+
(or (find-executable-path p)
29+
p)
30+
p))
31+
orig-p))
32+
33+
(display (simplify-path (path->complete-path p)))])
34+
2035
;; In case there are extra arguments to an executable, preserve them
21-
(for ([e (in-vector (current-command-line-arguments) (add1 p-arg-k))])
36+
(for ([e (in-list extras)])
2237
(display " ")
2338
(display e))
2439

racket/src/cs/c/boot.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
#include <unistd.h>
1+
#ifndef _MSC_VER
2+
# include <unistd.h>
3+
#endif
24
#include <stdio.h>
35
#include <fcntl.h>
46
#include <string.h>
@@ -78,7 +80,7 @@ void racket_boot(int argc, char **argv, char *self, long segment_offset,
7880
Sregister_boot_file(path_append(fw_path, "petite.boot"));
7981
Sregister_boot_file(path_append(fw_path, "scheme.boot"));
8082
#else
81-
fd = open(self, O_RDONLY);
83+
fd = open(self, O_RDONLY | O_BINARY);
8284

8385
{
8486
int fd1, fd2;
@@ -87,7 +89,7 @@ void racket_boot(int argc, char **argv, char *self, long segment_offset,
8789
lseek(fd1, pos1, SEEK_SET);
8890
Sregister_boot_file_fd("petite", fd1);
8991

90-
fd2 = open(self, O_RDONLY);
92+
fd2 = open(self, O_RDONLY | O_BINARY);
9193
lseek(fd2, pos2, SEEK_SET);
9294
Sregister_boot_file_fd("scheme", fd2);
9395
}

racket/src/cs/c/main.c

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
#include <unistd.h>
1+
#ifndef _MSC_VER
2+
# include <unistd.h>
3+
#endif
24
#include <stdio.h>
35
#include <string.h>
46
#include <stdlib.h>
7+
#ifdef _MSC_VER
8+
# include <Windows.h>
9+
# define DOS_FILE_SYSTEM
10+
static int scheme_utf8_encode(unsigned int *path, int zero_offset, int len,
11+
char *dest, int dest_len, int get_utf16);
12+
#endif
513
#include "boot.h"
614

715
#define MZ_CHEZ_SCHEME
@@ -63,6 +71,27 @@ static char *get_self_path()
6371
}
6472
#endif
6573

74+
#ifdef _MSC_VER
75+
static char *get_self_path()
76+
{
77+
wchar_t *p = get_self_executable_path();
78+
char *r;
79+
int len;
80+
81+
len = WideCharToMultiByte(CP_UTF8, 0, p, -1, NULL, 0, NULL, NULL);
82+
r = malloc(len);
83+
len = WideCharToMultiByte(CP_UTF8, 0, p, -1, r, len, NULL, NULL);
84+
85+
return r;
86+
}
87+
88+
static int scheme_utf8_encode(unsigned int *path, int zero_offset, int len,
89+
char *dest, int dest_len, int get_utf16)
90+
{
91+
return WideCharToMultiByte(CP_UTF8, 0, (wchar_t *)path, len, dest, dest_len, NULL, NULL);
92+
}
93+
#endif
94+
6695
#ifdef NO_GET_SEGMENT_OFFSET
6796
static long get_segment_offset()
6897
{

racket/src/cs/io.sls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161

162162
(define loaded-librktio
163163
(or (foreign-entry? "rktio_init")
164-
(load-shared-object (string-append "../../lib/librktio"
164+
(load-shared-object (string-append (string-append (current-directory) "/../../lib/librktio")
165165
(utf8->string (system-type 'so-suffix))))))
166166

167167
(define (rktio-lookup name)

racket/src/expander/Makefile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
# redirect to a different build dierctory by setting `BUILDDIR` and
44
# other variables.
55

6+
# Beware that this makefile is used both for GNU make and for nmake!
7+
68
RACKET = ../../bin/racket
79
RACO = $(RACKET) -N raco -l- raco
810

@@ -43,12 +45,23 @@ DIRECT_DEP = compiled/main_rkt.zo
4345
$(GENERATED_RKTL): $(DIRECT_DEP)
4446
$(RACKET) bootstrap-run.rkt -c $(BUILDDIR)compiled/cache-src $(KNOT) $(DIRECT) $(PURE) -k $(TREE) -s -x -o $(BUILDDIR)compiled/expander.rktl
4547

48+
# The next two lines make both GNU make and nmake happy, and they
49+
# cause nmake to not see the `-include`. The trick is that nmake
50+
# doesn't recognize backslash as a comment continuation.
51+
# \
52+
!if 0
53+
4654
# Dependencies in "expander.d" are created via the "cs" makefile, which
4755
# sets `RACKET` to be a bootstrapping load; the result doubles as
4856
# dependencies both for bootstrapping "bootstrap-run.rkt" and for the
4957
# generated flattened expander
5058
-include $(BUILDDIR)expander.d
5159

60+
# \
61+
!endif
62+
# \
63+
!include ..\build\expander.d
64+
5265
demo:
5366
$(RACO) make demo.rkt
5467
$(RACKET) demo.rkt

racket/src/expander/run.rkt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,9 @@
9393
(hash-update! instance-knot-ties
9494
(string->symbol (format "#%~a" sym))
9595
(lambda (l) (cons (if (equal? path "-")
96-
'ignore
97-
(path->complete-path path))
98-
l))
96+
'ignore
97+
(path->complete-path (normal-case-path path)))
98+
l))
9999
null)]
100100
[("++direct") primitive-table "Redirect imports from #%<primitive-table> to direct references"
101101
(hash-set! primitive-table-directs
@@ -273,11 +273,12 @@
273273
(load load-file))
274274

275275
(when dependencies-file
276+
(define (quote-if-space s) (if (regexp-match? #rx" " s) (format "\"~a\"" s) s))
276277
(call-with-output-file*
277278
dependencies-file
278279
#:exists 'truncate/replace
279280
(lambda (o)
280-
(fprintf o "~a:" dependencies-target)
281+
(fprintf o "~a:" (quote-if-space dependencies-target))
281282
(for ([dep (in-hash-keys dependencies)])
282-
(fprintf o " \\\n ~a" dep))
283+
(fprintf o " \\\n ~a" (quote-if-space dep)))
283284
(newline o))))

racket/src/io/Makefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ IGNORE = ++knot read - ++pure ../../collects/racket/private/collect.rkt
1212
# `$(GENERATED_RKTL)` appears as a dependency target in "$(BUILDDIR)expander.d"
1313
GENERATED_RKTL = $(BUILDDIR)compiled/io.rktl
1414

15-
io-src: ../build/so-rktio/Makefile
15+
RKTIO_DEP=../build/so-rktio/Makefile
16+
17+
io-src: $(RKTIO_DEP)
1618
$(RACO) make ../expander/bootstrap-run.rkt
1719
$(MAKE) $(GENERATED_RKTL)
1820

@@ -22,10 +24,20 @@ SAVE_DEPS = --depends $(GENERATED_RKTL) $(BUILDDIR)compiled/io.d
2224
$(GENERATED_RKTL): $(DIRECT_DEP)
2325
$(RACKET) ../expander/bootstrap-run.rkt -t main.rkt --submod main -c $(BUILDDIR)compiled/cache-src -k ../.. $(IGNORE) -s -x $(SAVE_DEPS) -o $(GENERATED_RKTL)
2426

27+
# \
28+
!if 0
29+
2530
# Dependencies in "expander.d" are created via the "cs" makefile
2631
-include $(BUILDDIR)expander.d
2732
-include $(BUILDDIR)compiled/io.d
2833

34+
# \
35+
!endif
36+
# \
37+
!include ..\build\expander_io.d
38+
# \
39+
!include ..\build\compiled\io.d
40+
2941
demo: compiled/rktio.rktl
3042
$(RACO) make demo.rkt
3143
$(RACKET) demo.rkt

racket/src/io/file/main.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@
344344
[(rktio-error? r)
345345
;; Errors are not reported, but are treated like non-links
346346
(define new-path (host-> host-path))
347-
;; If cleansing didn't change p, then return an `eq?`path
347+
;; If cleansing didn't change p, then return an `eq?` path
348348
(cond
349349
[(equal? new-path p) p]
350350
[else new-path])]

racket/src/io/path/cleanse.rkt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@
1212
(define/who (cleanse-path p-in)
1313
(check-path-argument who p-in)
1414
(define p (->path p-in))
15+
(define convention (path-convention p))
1516
(define (return bstr)
1617
(if (eq? bstr (path-bytes p))
1718
p
18-
(path bstr 'unix)))
19+
(path bstr convention)))
1920
(define bstr (path-bytes p))
20-
(case (path-convention p)
21+
(case convention
2122
[(unix)
2223
(return (clean-double-slashes bstr 'unix 0))]
2324
[(windows)
@@ -49,8 +50,8 @@
4950
(return (clean-double-slashes bstr 'windows drive-len)))]
5051
[(letter-drive-start? bstr (bytes-length bstr))
5152
(cond
52-
[(and ((bytes-length bstr) . > . 3)
53-
(is-sep? (bytes-ref bstr 3) 'windows))
53+
[(and ((bytes-length bstr) . > . 2)
54+
(is-sep? (bytes-ref bstr 2) 'windows))
5455
(return (clean-double-slashes bstr 'windows 2))]
5556
[else
5657
(return (bytes-append (subbytes bstr 0 2)

racket/src/io/path/parameter.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@
1111
;; wrapped to include security-guard checks.
1212

1313
(define/who current-directory
14-
(make-parameter (path #"/" (system-path-convention-type))
14+
(make-parameter (case (system-path-convention-type)
15+
[(unix) (path #"/" 'unix)]
16+
[(windows) (path #"C:\\" 'windows)])
1517
(lambda (v)
1618
(check-directory-path who v))))
1719

racket/src/io/path/split.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
3]
7777
[else 2])
7878
#:explode? explode?)]
79-
[(split-after-drive p #:explode? explode?)])]))
79+
[else (split-after-drive p #:explode? explode?)])]))
8080

8181
;; ----------------------------------------
8282

racket/src/io/port/string-input.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,8 @@
318318
(cond
319319
[(and b
320320
(or (eof-object? b)
321-
(b . < . 128)))
321+
(and (byte? b)
322+
(b . < . 128))))
322323
;; Shortcut worked
323324
(if (eof-object? b) b (integer->char b))]
324325
[else

racket/src/regexp/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,20 @@ SAVE_DEPS = --depends $(GENERATED_RKTL) $(BUILDDIR)compiled/regexp.d
2222
$(GENERATED_RKTL): $(DIRECT_DEP)
2323
$(RACKET) ../expander/bootstrap-run.rkt -t main.rkt -c $(BUILDDIR)compiled/cache-src -k ../.. $(IGNORE) -s -x $(SAVE_DEPS) -o $(GENERATED_RKTL)
2424

25+
# \
26+
!if 0
27+
2528
# Dependencies in "expander.d" are created via the "cs" makefile
2629
-include $(BUILDDIR)expander.d
2730
-include $(BUILDDIR)compiled/regexp.d
2831

32+
# \
33+
!endif
34+
# \
35+
!include ..\build\expander_regexp.d
36+
# \
37+
!include ..\build\compiled\regexp.d
38+
2939
demo:
3040
$(RACO) make demo.rkt
3141
$(RACKET) demo.rkt

racket/src/rktio/Makefile.in

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,16 +138,20 @@ clean:
138138

139139
# To rebuild the S-expression form of "rktio.h"
140140

141-
rktio-rktl rktio-inc:
141+
rktio-rktl rktio-inc rktio-def:
142142
$(MAKE) $(srcdir)/rktio.rktl
143143
$(MAKE) $(srcdir)/rktio.inc
144+
$(MAKE) $(srcdir)/rktio.def
144145

145146
$(srcdir)/rktio.rktl: $(srcdir)/rktio.h $(srcdir)/parse.rkt
146147
$(RACKET) $(srcdir)/parse.rkt -o $(srcdir)/rktio.rktl $(srcdir)/rktio.h
147148

148149
$(srcdir)/rktio.inc: $(srcdir)/rktio.h $(srcdir)/parse.rkt
149150
$(RACKET) $(srcdir)/parse.rkt -c -o $(srcdir)/rktio.inc $(srcdir)/rktio.h
150151

152+
$(srcdir)/rktio.def: $(srcdir)/rktio.h $(srcdir)/parse.rkt
153+
$(RACKET) $(srcdir)/parse.rkt -d -o $(srcdir)/rktio.def $(srcdir)/rktio.h
154+
151155
# ----------------------------------------
152156

153157
@HIDE_NOT_STANDALONE@librktio:

0 commit comments

Comments
 (0)