File: Makefile.in

package info (click to toggle)
scheme48 1.8%2Bdfsg-1%2Bdeb7u1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 14,984 kB
file content (883 lines) | stat: -rw-r--r-- 31,643 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
# Scheme 48 Makefile
# Documentation in files INSTALL and doc/install.txt

SHELL = /bin/sh

### Filled in by `configure' ###
srcdir = @srcdir@
VPATH = @srcdir@
CC = @CC@
LD = @LD@
DEFS = @DEFS@ -D__COMPILING_SCHEME48_ITSELF__ -DS48_HOST_ARCHITECTURE=\"$(HOST_ARCHITECTURE)\"
LIBS = @LIBS@
CFLAGS = @CFLAGS@
CPPFLAGS =
INSTALL = @INSTALL@
INSTALL_PROGRAM = @INSTALL_PROGRAM@
INSTALL_DATA = @INSTALL_DATA@

LDFLAGS = @LDFLAGS@
LDFLAGS_VM = @LDFLAGS_VM@
LIBOBJS = @LIBOBJS@

GC_OBJS = @GC_OBJS@

HOST_ARCHITECTURE = @host@
BIT_SUFFIX = @BIT_SUFFIX@

prefix = @prefix@
exec_prefix = @exec_prefix@

bindir = @bindir@
libdir = @libdir@
incdir = @includedir@
manext = 1
mandir = @mandir@/man$(manext)
datarootdir = @datarootdir@
datadir = @datadir@

DYNAMIC_EXTERNALS_CFLAGS=@DYNAMIC_EXTERNALS_CFLAGS@
DYNAMIC_EXTERNALS_LDFLAGS=@DYNAMIC_EXTERNALS_LDFLAGS@
DYNAMIC_EXTERNALS_LDFLAGS_IN_PLACE=@DYNAMIC_EXTERNALS_LDFLAGS_IN_PLACE@
### End of `configure' section###

# HP 9000 series, if you don't have gcc
#   CC = cc
#   CFLAGS = -Aa -O +Obb1800
#   DEFS = -D_HPUX_SOURCE -Dhpux

# Ultrix
#   LDFLAGS = -N

.c.o:
	$(CC) -c $(CPPFLAGS) $(DEFS) -I ./c -I$(srcdir)/c -I$(srcdir)/c/bibop $(CFLAGS) -o $@ $<

# You might want to change RUNNABLE to "s48"
VERSION = 1.`cat $(srcdir)/build/minor-version-number`
RUNNABLE = scheme48
CONFIG_SCRIPT = scheme48-config
MANPAGE = $(RUNNABLE).$(manext)
LIB = $(libdir)/scheme48-$(VERSION)
SHARE = $(datadir)/scheme48-$(VERSION)

distdir = /tmp

# If make barfs on this include line, just comment it out.  It's only
# really needed if you want to build the linker or rebuild initial.image.
include $(srcdir)/build/filenames.make
#
#NetBSD make wants to see this instead:
#.include "$(srcdir)/build/filenames.make"


# Static linker:
#
# You only need the linker if you're going to make changes to the
# things that go into the initial.image, which in general means the
# files in rts/.  If you decide you need to use the linker, then you
# gots your choice; it can run in just about any version of Scheme 48
# or Pseudoscheme.  (It has also been made to run in Scheme->C.)  It
# doesn't matter a whole lot which Scheme you use as long as it's not
# broken or unavailable.  The two best choices are:
#
# 1. As below.
#    These settings requires you to already have a $(RUNNABLE)
#    command.  This is desirable if you are making changes to the
#    system that might break scheme48vm and/or scheme48.image.  But it
#    requires you to have squirreled away a previous working version
#    of scheme48.  The settings assume a Unicode version; if you want
#    to use an installed non-Unicode-capable Scheme 48 (1.4 or earlier),
#    you need to use this setting:
#    LINKER_WRITEBYTE = ,load scheme/alt/write-byte.scm
#
# 2. LINKER_VM = ./$(VM) $(BIG_HEAP)
#    LINKER_RUNNABLE = $(LINKER_VM) -i $(IMAGE)
#    LINKER_WRITEBYTE = ,open (subset i/o (write-byte)) (subset ports (set-port-crlf?!))
#    This builds the linker on the scheme48vm and scheme48.image
#    that are in the current directory.

BIG_HEAP = -h 8000000
LINKER_VM = $(RUNNABLE) $(BIG_HEAP)
LINKER_RUNNABLE = $(LINKER_VM)
LINKER_WRITEBYTE = ,open (subset i/o (write-byte)) (subset ports (set-port-crlf?!))
START_LINKER-32 = echo ',batch';				\
	       echo ',bench on';				\
	       echo ',open signals handle features';		\
	       echo ',open bitwise ascii code-vectors';		\
	       echo '$(LINKER_WRITEBYTE)';			\
	       echo ',config ,load scheme/platform-interfaces.scm'; \
	       echo ',config ,load scheme/rts-packages-32.scm'; \
	       echo ',open platform';	\
	       echo ',open cells record-types';	\
	       echo ',load $(linker-files)';			\
	       echo ',load scheme/alt/init-defpackage.scm'

START_LINKER-64 = echo ',batch';				\
	       echo ',bench on';				\
	       echo ',open signals handle features';		\
	       echo ',open bitwise ascii code-vectors';		\
	       echo '$(LINKER_WRITEBYTE)';			\
	       echo ',config ,load scheme/platform-interfaces.scm'; \
	       echo ',config ,load scheme/rts-packages-64.scm'; \
	       echo ',open platform';	\
	       echo ',open cells record-types';	\
	       echo ',load $(linker-files)';			\
	       echo ',load scheme/alt/init-defpackage.scm'

# --------------------
# You shouldn't have to change anything below this point.

# Targets:

IMAGE = scheme48.image
INITIAL = $(srcdir)/build/initial.image
VM = scheme48vm
POSIX_EXTERNAL = c/posix.so
SRFI_27_EXTERNAL = c/srfi-27.so
UNIX_OBJS = c/unix/misc.o c/unix/io.o c/unix/fd-io.o c/unix/event.o
OBJS =	c/scheme48vm-$(BIT_SUFFIX).o \
	c/extension.o c/free.o c/double_to_string.o c/bignum.o \
	c/external.o c/external-lib.o c/external-init.o c/init.o

FAKEHS	= c/fake/dlfcn.h c/fake/sigact.h c/fake/strerror.h \
		c/fake/sys-select.h c/fake/langinfo.h

SCHEME48HS = c/scheme48.h c/scheme48arch.h c/scheme48write-barrier.h

# Sources:

CONFIG_FILES = scheme/interfaces.scm scheme/packages.scm \
	       scheme/vm/shared-interfaces.scm	\
	       scheme/low-packages.scm scheme/rts-packages.scm \
	       scheme/comp-packages.scm scheme/initial-packages.scm

# Rules:

# The following is the first rule and therefore the "make" command's
# default target.
enough: vm $(POSIX_EXTERNAL) $(SRFI_27_EXTERNAL) $(IMAGE) script-interpreter go

# --------------------
# External code to include in the VM
# After changing any of these you should delete `scheme48vm' and remake it.

EXTERNAL_OBJECTS = c/unix/socket.o c/unix/dynlink.o \
		   c/unix/sysexits.o $(ASM_OBJECTS)

# Rules for any external code.

# POSIX rules; this could have its own Makefile, but I don't want to bother.

posix_dir = c/posix

CC_POSIX = $(CC) -c $(CPPFLAGS) $(DEFS) -I ./c -I$(srcdir)/c -I$(srcdir)/c/bibop $(CFLAGS) $(DYNAMIC_EXTERNALS_CFLAGS) -o $@ $<

$(posix_dir)/user.o: c/posix/user.c \
	$(SCHEME48HS) c/c-mods.h $(posix_dir)/posix.h
	$(CC_POSIX)

$(posix_dir)/regexp.o: c/posix/regexp.c \
	$(SCHEME48HS) c/c-mods.h $(posix_dir)/posix.h
	$(CC_POSIX)

$(posix_dir)/proc-env.o: c/posix/proc-env.c \
	$(SCHEME48HS) c/c-mods.h $(posix_dir)/posix.h
	$(CC_POSIX)

$(posix_dir)/io.o: c/posix/io.c \
	$(SCHEME48HS) c/c-mods.h $(posix_dir)/posix.h
	$(CC_POSIX)

$(posix_dir)/proc.o: c/posix/proc.c \
	$(SCHEME48HS) c/c-mods.h \
	c/event.h $(posix_dir)/posix.h $(posix_dir)/s48_signals.h
	$(CC_POSIX)

$(posix_dir)/posix.o: c/posix/posix.c
	$(CC_POSIX)

$(posix_dir)/dir.o: c/posix/dir.c \
  $(SCHEME48HS) c/scheme48heap.h c/c-mods.h \
  c/event.h c/fd-io.h $(posix_dir)/posix.h
	$(CC_POSIX)

POSIX_OBJECTS = $(posix_dir)/user.o     $(posix_dir)/regexp.o	\
                $(posix_dir)/proc-env.o $(posix_dir)/proc.o	\
                $(posix_dir)/io.o	$(posix_dir)/dir.o	\
		$(posix_dir)/posix.o

$(POSIX_EXTERNAL) : $(POSIX_OBJECTS)
	$(LD) -o $@ $(POSIX_OBJECTS) $(DYNAMIC_EXTERNALS_LDFLAGS_IN_PLACE) 


# End of POSIX rules

c/srfi-27.o: c/srfi-27.c $(SCHEM48HS)
	$(CC) -c $(CPPFLAGS) $(DEFS) -I ./c -I$(srcdir)/c -I$(srcdir)/c/bibop $(CFLAGS) $(DYNAMIC_EXTERNALS_CFLAGS) -o $@ $<

$(SRFI_27_EXTERNAL) : c/srfi-27.o
	$(LD) -o $@ $^ $(DYNAMIC_EXTERNALS_LDFLAGS_IN_PLACE)

# Native-code glue rules

ASM_OBJECTS = c/fake/glue.o
ASM_INITIALIZERS =

# Real definitions to be used when a. native code works and b. it is supported
# on the machine we're compiling on
#ASM_OBJECTS = c/glue.o c/asm-glue.o
#ASM_INITIALIZERS =	s48_init_asm_glue

# End of native-code glue rules

# Two-space copier objects

GC_TWOSPACE_OBJS = c/scheme48-twospace-heap-$(BIT_SUFFIX).o

c/scheme48-twospace-heap-$(BIT_SUFFIX).o: c/prescheme.h c/scheme48vm.h c/scheme48heap.h \
			c/scheme48vm-prelude.h c/c-mods.h \
			c/event.h c/io.h c/fd-io.h

# The BIBOP Garbage Collector
GC_BIBOP_OBJS =  c/scheme48-bibop-heap-$(BIT_SUFFIX).o \
	c/bibop/page_alloc.o c/bibop/memory_map.o c/bibop/areas.o \
	c/bibop/generation_gc.o c/bibop/find_all.o c/bibop/check_heap.o \
	c/bibop/utils.o c/bibop/area_roots.o c/bibop/remset.o

bibop: $(GC_BIBOP_OBJS)

c/scheme48-bibop-heap-$(BIT_SUFFIX).o: c/prescheme.h c/scheme48vm.h c/scheme48heap.h \
			c/scheme48vm-prelude.h \
			c/bibop/bibop.h \
			c/c-mods.h c/event.h c/io.h c/fd-io.h

c/bibop/page_alloc.o: c/bibop/page_alloc.h c/bibop/page_constants.h            \
	c/bibop/memory.h
c/bibop/memory_map.o: c/bibop/memory_map.h c/bibop/utils.h                     \
	c/bibop/page_constants.h
c/bibop/areas.o: c/bibop/areas.h c/bibop/page_constants.h c/bibop/utils.h      \
	c/bibop/memory_map.h c/bibop/area_roots.h c/bibop/gc_config.h          \
	c/bibop/remset.h
c/bibop/generation_gc.o: c/bibop/generation_gc.h c/bibop/page_constants.h      \
	c/bibop/areas.h c/bibop/memory.h c/bibop/data.h c/bibop/utils.h        \
	c/bibop/memory_map.h c/bibop/check_heap.h c/bibop/area_roots.h         \
	c/bibop/measure.h c/bibop/measure.ci 				       \
	c/bibop/gc_config.h c/bibop/remset.h				       \
	$(SCHEME48HS)
c/bibop/find_all.o: c/bibop/find_all.h c/bibop/generation_gc.h c/bibop/areas.h \
	c/bibop/data.h c/bibop/memory.h					       \
	$(SCHEME48HS)
c/bibop/check_heap.o: c/bibop/check_heap.h c/scheme48.h c/bibop/generation_gc.h\
	c/bibop/utils.h c/bibop/data.h c/bibop/memory.h c/bibop/memory_map.h   \
	$(SCHEME48HS)
c/bibop/area_roots.o: c/bibop/area_roots.h c/bibop/areas.h c/bibop/memory.h    \
	c/bibop/memory_map.h c/bibop/measure.h c/bibop/gc_config.h             \
	c/bibop/remset.h
c/bibop/remset.o: c/bibop/remset.h c/bibop/memory.h c/scheme48.h	       \
	c/bibop/utils.h c/bibop/data.h c/bibop/generation_gc.h 		       \
	c/bibop/gc_config.h						       \
	$(SCHEME48HS)


# End of BIBOP GC rules


$(VM): c/main.o $(OBJS) $(GC_OBJS) $(UNIX_OBJS) $(LIBOBJS) $(EXTERNAL_OBJECTS) \
	c/scheme48.exp c/scheme48.def
	$(CC) $(LDFLAGS) $(LDFLAGS_VM) $(CFLAGS) -o $@ c/main.o		\
		$(OBJS) $(GC_OBJS) $(UNIX_OBJS)				\
		$(LIBOBJS) $(LIBS)					\
		$(EXTERNAL_OBJECTS)
	# Cygwin
	if test -x /usr/bin/dlltool; then \
		dlltool --dllname $(VM).exe --output-lib $(VM).a --def $(srcdir)/c/scheme48.def; \
	fi

script-interpreter: c/script-interpreter.o
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ c/script-interpreter.o

c/main.o: c/main.c c/scheme48vm.h c/scheme48heap.h
	$(CC) -c $(CFLAGS) -o $@ \
		-DDEFAULT_IMAGE_NAME=\"$(LIB)/$(IMAGE)\" \
		$(CPPFLAGS) $(DEFS) $(srcdir)/c/main.c

c/scheme48vm-$(BIT_SUFFIX).o: c/prescheme.h c/scheme48vm.h \
		c/scheme48heap.h \
		c/scheme48image.h c/bignum.h c/event.h \
		c/io.h c/fd-io.h \
		c/scheme48vm-prelude.h c/c-mods.h \
		$(SCHEME48HS)

c/bignum.o: c/bignum.h c/bignumint.h $(SCHEME48HS)
c/extension.o: c/sysdep.h $(FAKEHS) $(SCHEME48HS) c/scheme48vm.h
c/free.o: c/sysdep.h
c/external.o: c/sysdep.h $(FAKEHS) $(SCHEME48HS) c/c-mods.h
c/unix/event.o: c/sysdep.h $(FAKEHS) c/scheme48vm.h c/scheme48heap.h \
			c/event.h c/fd-io.h
c/unix/fd-io.o: c/sysdep.h $(FAKEHS) c/scheme48vm.h c/scheme48heap.h \
			c/event.h c/fd-io.h
c/unix/misc.o: c/sysdep.h $(FAKEHS)
c/unix/io.o: c/io.h

c/unix/socket.o: $(SCHEME48HS) c/fd-io.h c/event.h
c/unix/dynlink.o: $(SCHEME48HS)

c/script-interpreter.o: c/sysdep.h $(FAKEHS) c/script-interpreter.c
	$(CC) -c $(CFLAGS) -o $@ \
		-DRUNNABLE=\"$(bindir)/$(RUNNABLE)\" \
		$(CPPFLAGS) $(DEFS) \
		-I ./c -I$(srcdir)/c \
		$(srcdir)/c/script-interpreter.c
c/fake/strerror.o: c/fake/strerror.h
c/fake/langinfo.o: c/fake/langinfo.h

# --------------------
# Make scheme48.image from initial.image and library .scm files.
#
# For bootstrap reasons, initial.image is *not* listed as a source,
# even though it really is.

$(IMAGE): $(VM) scheme/env/init-defpackage.scm scheme/more-interfaces.scm \
		scheme/link-packages.scm scheme/env-packages.scm \
		scheme/more-packages.scm \
		scheme/sort/interfaces.scm scheme/sort/packages.scm \
		scheme/cml/interfaces.scm scheme/cml/packages.scm \
		scheme/posix/packages.scm scheme/srfi/packages.scm \
		$(usual-files) build/initial.debug build/build-usual-image
	$(srcdir)/build/build-usual-image $(srcdir) \
		"`(cd $(srcdir) && pwd)`/scheme" "`pwd`/c" '$(IMAGE)' './$(VM)' \
		'$(INITIAL)-$(BIT_SUFFIX)'

### Fake targets:  all clean install man dist

install: enough dirs \
	 inst-script inst-vm inst-misc inst-man inst-inc inst-image \
	 inst-script-interpreters inst-config-script inst-externals

inst-vm:
	$(INSTALL_PROGRAM) $(VM) $(DESTDIR)$(LIB)
	if [-e $(VM).a]; then $(INSTALL_PROGRAM) $(VM).a $(DESTDIR)$(LIB); fi

inst-image:
	rm -f '/tmp/$(IMAGE)'
	$(srcdir)/build/build-usual-image $(srcdir) "$(SHARE)" "$(LIB)" \
		"/tmp/$(IMAGE)" "./$(VM)" "$(INITIAL)-$(BIT_SUFFIX)"
	$(INSTALL_DATA) /tmp/$(IMAGE) $(DESTDIR)$(LIB)
	rm /tmp/$(IMAGE)

inst-man:
	$(srcdir)/mkinstalldirs $(DESTDIR)$(mandir)
	sed 's=LBIN=$(bindir)=g' $(srcdir)/doc/scheme48.man |	   \
		sed 's=LLIB=$(LIB)=g' |				   \
		sed 's=LS48=$(RUNNABLE)=g' >$(MANPAGE)
	$(INSTALL_DATA) $(MANPAGE) $(DESTDIR)$(mandir)
	rm $(MANPAGE)

inst-inc: c/scheme48.exp c/scheme48.def
	$(INSTALL_DATA) $(srcdir)/c/scheme48.h $(DESTDIR)$(incdir)
	$(INSTALL_DATA) c/scheme48arch.h $(DESTDIR)$(incdir)
	$(INSTALL_DATA) $(srcdir)/c/scheme48write-barrier.h $(DESTDIR)$(incdir)
	$(INSTALL_DATA) $(srcdir)/c/scheme48.exp $(DESTDIR)$(incdir)
	$(INSTALL_DATA) $(srcdir)/c/scheme48.def $(DESTDIR)$(incdir)
	$(INSTALL_DATA) $(srcdir)/c/scheme48-external.exp $(DESTDIR)$(incdir)

inst-misc:
	for stub in env big sort opt misc link posix cml srfi; do	\
		for f in $(srcdir)/scheme/$$stub/*.scm; do		\
			$(INSTALL_DATA) $$f $(DESTDIR)$(SHARE)/$$stub || exit 1;	\
		done;							\
	done
	for f in $(srcdir)/scheme/rts/*num.scm 				\
		 $(srcdir)/scheme/rts/jar-defrecord.scm; do		\
		$(INSTALL_DATA) $$f $(DESTDIR)$(SHARE)/rts || exit 1;	\
	done

inst-script:
	script=$(DESTDIR)$(bindir)/$(RUNNABLE) &&			\
	LIB=$(LIB) &&							\
	echo "#!/bin/sh"	>$$script &&				\
	echo			>>$$script &&				\
	echo "lib=$$LIB"	>>$$script &&				\
	echo 'exec $$lib/$(VM) -i $$lib/$(IMAGE) "$$@"'			\
				>>$$script &&				\
	chmod +x $$script

inst-script-interpreters:
	for dialect in r5rs srfi-7; do					\
		$(INSTALL_PROGRAM) script-interpreter			\
			$(DESTDIR)$(bindir)/scheme-$$dialect;		\
	done

inst-config-script:
	config_script=$(bindir)/$(CONFIG_SCRIPT) &&			\
	sed -e 's,@incdir\@,$(incdir),g'				\
	    -e 's,@libdir\@,$(libdir),g'				\
	    -e 's,@CC\@,$(CC),g'					\
	    -e 's,@LD\@,$(LD),g'					\
	    -e 's,@DYNAMIC_EXTERNALS_CFLAGS\@,$(DYNAMIC_EXTERNALS_CFLAGS),g' \
	    -e 's,@DYNAMIC_EXTERNALS_LDFLAGS\@,$(DYNAMIC_EXTERNALS_LDFLAGS),g' \
	< $(srcdir)/build/$(CONFIG_SCRIPT).in > $$config_script &&	\
	chmod +x $$config_script

inst-externals:
	$(INSTALL_PROGRAM) $(POSIX_EXTERNAL) $(SRFI_27_EXTERNAL) $(DESTDIR)$(LIB)/

# Script to run scheme48 in this directory.
go:
	echo '#!/bin/sh'	>$@ &&					\
	echo			>>$@ &&					\
	echo "lib=\"`pwd`\""	>>$@ &&					\
	echo 'exec "$$lib"/$(VM) -i "$$lib"/$(IMAGE) "$$@"'		\
				>>$@ &&					\
	chmod +x $@

# Exports file for AIX and Cygwin

CAT_EXPORTS = cat $(srcdir)/c/scheme48.h $(srcdir)/c/fd-io.h $(srcdir)/c/event.h | egrep '^S48_EXTERN' | sed 's,^S48_EXTERN.*\(s48_[a-zA-Z0-9_]*\)(.*$$,\1,' | sed 's,^S48_EXTERN.*\(ps_[a-zA-Z0-9_]*\)(.*$$,\1,' | sed 's,^S48_EXTERN.*\(s48_[a-zA-Z0-9_]*\).*$$,\1,'

c/scheme48.exp: c/scheme48.h c/fd-io.h c/event.h
	echo '#!..' > $(srcdir)/c/scheme48.exp &&			\
	$(CAT_EXPORTS) >> $(srcdir)/c/scheme48.exp

c/scheme48.def: c/scheme48.h c/fd-io.h c/event.h
	echo 'EXPORTS' > $(srcdir)/c/scheme48.def &&			\
	$(CAT_EXPORTS) >> $(srcdir)/c/scheme48.def

dirs:
	for dir in $(libdir) $(bindir) $(incdir) $(datadir); do			 \
		$(srcdir)/mkinstalldirs $(DESTDIR)$$dir || exit 1;	 \
	done
	$(srcdir)/mkinstalldirs $(DESTDIR)$(LIB)
	for dir in rts env big sort opt misc link posix cml srfi; do	  \
		$(srcdir)/mkinstalldirs $(DESTDIR)$(SHARE)/$$dir || exit 1; \
	done

configure: configure.in
	autoheader && autoconf

clean:
	-rm -f $(VM) script-interpreter					\
		*.o c/unix/*.o c/posix/*.o c/*.o c/fake/*.o c/bibop/*.o	\
		$(POSIX_EXTERNAL) $(SRFI_27_EXTERNAL)			\
		c/*.a c/glue_gnu.s c/glue_darwin.s c/scheme48.exp 	\
		TAGS $(IMAGE)						\
		$(srcdir)/build/*.tmp $(srcdir)/$(MANPAGE) 		\
		$(srcdir)/scheme/debug/*.image 				\
		$(srcdir)/scheme/debug/*.debug 				\
		$(srcdir)/scheme/vm/scheme48vm-??.c 			\
		$(srcdir)/scheme/vm/scheme48*heap-??.c			\
		go $(distname)

distclean: clean
	rm -f Makefile config.log config.status config-cache \
		c/sysdep.h c/scheme48arch.h

check:	$(VM) $(IMAGE) $(POSIX_EXTERNAL) $(SRFI_27_EXTERNAL) scheme/debug/check.scm
	(								\
		echo ',batch';						\
                echo ',exec ,load =scheme48/debug/check.scm';           \
		echo ',config ,load =scheme48/test-packages.scm';	\
		echo ',open big-test';					\
		echo ',open sockets-test';				\
		echo ',config ,load =scheme48/misc/packages.scm';	\
		echo ',config ,load =scheme48/misc/test-packages.scm';	\
		echo ',open misc-test';					\
		echo ',config ,load =scheme48/cml/test-packages.scm';	\
		echo ',open cml-test';					\
		echo ',config ,load =scheme48/srfi/test-packages.scm';	\
		echo ',open srfi-test';					\
		echo ',config ,load =scheme48/posix/test-packages.scm';	\
		echo ',open posix-test';				\
		echo ',open test-suites';				\
		echo '(define-test-suite all-tests (compiler-tests big-tests tcp-sockets-tests misc-tests cml-tests srfi-tests posix-tests))'; \
		echo '(run-test-suite all-tests)'			\
	) | ./$(VM) -i $(IMAGE) -h 8000000

# --------------------
# Rules from here on down are not essential for the basic installation
# procedure.

all: vm image script-interpreter go
vm: $(VM)
image: $(INITIAL)-$(BIT_SUFFIX)
	$(MAKE) $(IMAGE)
test: check

tags:
	find . -name "*.scm" -o -name "*.c" -o -name "*.h" | etags -

# --------------------
# Distribution...

# DISTFILES should include all sources.
DISTFILES = README COPYING.rtf COPYING INSTALL WINDOWS.txt		\
		configure configure.in config.sub config.guess 		\
		acconfig.h Makefile.in 					\
		scheme48.sln scheme48.vcproj				\
		mkinstalldirs install-sh				\
		doc/*.ps doc/*.pdf doc/*.txt 				\
		doc/html/*.html doc/html/*.css doc/html/*.gif 		\
		doc/src/*.tex doc/src/*.sty doc/src/*.scm		\
		doc/scheme48.man					\
		emacs/README 						\
		build/*.scm build/*-version-number build/*.exec		\
		build/*.lisp build/build-usual-image build/filenames.make \
		build/initial.debug 					\
		build/initial.image-32 build/initial.image-64		\
		build/*.bat build/*.sh build/*.rc			\
		build/dummy build/*.wxs build/*.wxi			\
		build/*.bmp build/*.ico					\
		build/scheme48-config.in				\
		c/*.[ch] c/*/*.[ch] c/*/*.ci c/*.exp			\
		c/scheme48.h.in						\
		c/scheme48write-barrier.h c/scheme48arch.h.in		\
		emacs/*.el gdbinit					\
		scheme/*.scm scheme/*/*.scm scheme/vm/*/*.scm		\
		ps-compiler/minor-version-number			\
		ps-compiler/doc/node.txt ps-compiler/doc/todo.txt	\
		ps-compiler/*.scm ps-compiler/*/*.scm			\
		ps-compiler/prescheme/primop/*.scm			\
		ps-compiler/prescheme/test/*.scm			\
		c/sysdep.h.in

distname = scheme48-$(VERSION)

dist: build/initial.image-32 build/initial.image-64 c/scheme48.h
	distname=$(distname) &&						\
	distfile=$(distdir)/$$distname.tgz &&				\
	if [ -d $(distdir) ] &&						\
	   [ -w $$distfile -o -w $(distdir) ]; then			\
		cd $(srcdir) &&						\
		rm -f $$distname &&					\
		ln -s . $$distname &&					\
		files='' &&						\
		for i in $(DISTFILES); do				\
			if [ "$$i" != "c/sysdep.h" ]; then		\
				files="$$files $$distname/$$i";		\
			fi						\
		done &&							\
		tar -cf - $$files |					\
			gzip --best >$$distfile &&			\
		rm $$distname;						\
	else								\
		echo "Can't write $$distfile" >&2;			\
		exit 1;							\
	fi

# Increment the minor version number
inc:
	f=build/minor-version-number &&					\
	expr `cat $$f` + 1 >$$f.tmp &&					\
	mv $$f.tmp $$f &&						\
	cp $$f doc/src/version-number.tex &&				\
	echo '(define version-info "1.'`cat $$f`'")'			\
		>scheme/env/version-info.scm


# --------------------
# Generate build/filenames.make from *packages.scm
#
# This hack traces the module dependencies described in the
# various configuration files and converts them into dependency lists
# that "make" can use for its purposes.
#
# Since the distribution comes with a filenames.make, this rule
# shouldn't be invoked for simple installations.  But it will be used
# if you change any of the *-packages.scm files.
#
# You can actually run the forms in filenames.scm in any Scheme
# implementation that has syntax-rules and explicit-renaming low-level
# macros (e.g., most versions of Scheme 48 and Pseudoscheme).
# If there are errors running this script, and you need to debug,
# don't use the initial.image, use something that has a reasonable
# environment.
#
# If this fails and you don't feel like debugging or fixing the problem,
# try "touch filenames.make" and hope for the best.

PACKAGES=scheme/packages.scm scheme/rts-packages.scm scheme/alt-packages.scm \
	 scheme/comp-packages.scm scheme/initial-packages.scm \
	 scheme/link-packages.scm scheme/env-packages.scm \
	 scheme/sort/packages.scm scheme/more-packages.scm \
	 scheme/cml/packages.scm \
	 build/filenames.scm

$(srcdir)/build/filenames.make: $(PACKAGES)
# uncomment this if you activate the line below:
#	$(MAKE) $(VM) PACKAGES=
	cd $(srcdir) && \
	$(RUNNABLE) -a batch <build/filenames.scm
# or:	./$(VM) -i $(srcdir)/$(INITIAL)-$(BIT_SUFFIX) -a batch <build/filenames.scm


# --------------------
# Static linker
#
# The linker is capable of rebuilding an image from sources, even
# across an incompatible change in VM data representations.

# Bootstrap from Lucid Common Lisp: (last tested with
# Pseudoscheme 2.9 and Scheme 48 version 0.19)

PSEUDODIR = ../pseudo

link/linker-in-lucid: build/lucid-script.lisp $(linker-files) \
	    scheme/alt/pseudoscheme-features.scm \
	    scheme/alt/pseudoscheme-record.scm
	(echo \(defvar pseudoscheme-directory \"$(PSEUDODIR)/\"\); \
	 cat build/lucid-script.lisp; \
	 echo \(dump-linker\) \(lcl:quit\)) \
	| lisp

# --------------------
# Initial image
#
# The initial.image is built by the static linker.  The image contains
# Scheme, the byte-code compiler, and a minimal command processor, but
# no debugging environment to speak of.

$(INITIAL)-32: $(CONFIG_FILES) build/initial.scm scheme/rts-packages-32.scm $(initial-files) $(linker-files)
	cd $(srcdir) &&							\
	($(START_LINKER-32);						\
		echo '(load-configuration "scheme/platform-interfaces.scm")'; \
		echo '(load-configuration "scheme/rts-packages-32.scm")'; \
		echo '(load-configuration "scheme/interfaces.scm")';	\
		echo '(load-configuration "scheme/vm/shared-interfaces.scm")'; \
		echo '(load-configuration "scheme/packages.scm")';	\
		echo '(flatload initial-structures)';			\
		echo '(load "build/initial.scm")';			\
		echo '(link-initial-system)'				\
	) | $(LINKER_RUNNABLE)
	mv $(INITIAL) $@

$(INITIAL)-64: $(CONFIG_FILES) build/initial.scm scheme/rts-packages-64.scm $(initial-files) $(linker-files)
	cd $(srcdir) &&							\
	($(START_LINKER-64);						\
		echo '(load-configuration "scheme/platform-interfaces.scm")'; \
		echo '(load-configuration "scheme/rts-packages-64.scm")'; \
		echo '(load-configuration "scheme/interfaces.scm")';	\
		echo '(load-configuration "scheme/vm/shared-interfaces.scm")'; \
		echo '(load-configuration "scheme/packages.scm")';	\
		echo '(flatload initial-structures)';			\
		echo '(load "build/initial.scm")';			\
		echo '(link-initial-system)'				\
	) | $(LINKER_RUNNABLE)
	mv $(INITIAL) $@

# --------------------
# Various small images for debugging low-level changes

LOAD_DEBUG = \
	 $(START_LINKER-32); \
	 echo \(load-configuration \"scheme/interfaces.scm\"\); \
	 echo \(load-configuration \"scheme/packages.scm\"\); \
	 echo \(load-configuration \"scheme/vm/shared-interfaces.scm\"\); \
	 echo \(flatload debug-structures\)

scheme/debug/tiny.image: scheme/debug/tiny-packages.scm \
		  scheme/debug/tiny.scm
	cd $(srcdir) && \
	($(START_LINKER-32); \
	 echo \(load-configuration \"scheme/debug/tiny-packages.scm\"\); \
	 echo \(link-simple-system \'\(scheme/debug tiny\) \'start tiny-system\)) \
	| $(LINKER_RUNNABLE)

scheme/debug/low-test.image: scheme/debug/low-test-packages.scm \
		  scheme/debug/low-test.scm
	cd $(srcdir) && \
	($(START_LINKER-32); \
	 echo \(load-configuration \"scheme/debug/low-test-packages.scm\"\); \
	 echo \(link-simple-system \'\(scheme/debug low-test\) \'start low-test-system\)) \
	| $(LINKER_RUNNABLE)

scheme/debug/bignum-test.image: scheme/debug/low-test-packages.scm \
		  scheme/debug/bignum-test.scm
	cd $(srcdir) && \
	($(START_LINKER-32); \
	 echo \(load-configuration \"scheme/debug/low-test-packages.scm\"\); \
	 echo \(link-simple-system \'\(scheme/debug bignum-test\) \'start bignum-test-system\)) \
	| $(LINKER_RUNNABLE)

scheme/debug/little.image: $(CONFIG_FILES) scheme/debug-packages.scm
	cd $(srcdir) &&					\
	($(LOAD_DEBUG); echo \(link-little-system\))	\
	| $(LINKER_RUNNABLE)

scheme/debug/mini.image: $(CONFIG_FILES)
	cd $(srcdir) &&					\
	($(LOAD_DEBUG); echo \(link-mini-system\))	\
	| $(LINKER_RUNNABLE)

scheme/debug/medium.image: $(CONFIG_FILES)
	cd $(srcdir) &&						\
	($(LOAD_DEBUG); echo \(flatload compiler-structures\);	\
	 echo \(link-medium-system\)) \
	| $(LINKER_RUNNABLE)

# The following have not been updated for the new directory organization

c/smain.o: c/main.c
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) -DSTATIC_AREAS -o $@ $(srcdir)/c/main.c

mini: mini-heap.o smain.o
	$(CC) $(LDFLAGS) $(CFLAGS) -o $@ c/smain.o mini-heap.o $(OBJS) $(LIBS)

mini-heap.o: mini-heap.c
	$(CC) -c $(CPPFLAGS) $(DEFS) $(CFLAGS) -o $@ $(srcdir)/mini-heap.c

mini-heap.c: scheme/debug/mini1.image
	(echo ,exec ,load misc/load-static.scm; \
	 echo \(do-it 150000 \"$(srcdir)/scheme/debug/mini1.image\" \"$@\"\)) \
	| $(RUNNABLE) -h 3000000 -a batch

scheme/debug/mini1.image: $(VM) scheme/debug/mini.image
	echo "(write-image \"scheme/debug/mini1.image\" \
			   (usual-resumer (lambda (args) \
					    (command-processor #f args))) \
			   \"foo\")" \
	| ./$(VM) -i scheme/debug/mini.image -a batch


# --------------------
# Generate unicode-info.scm, srfi-14-base-char-set.scm, and unicode-normalization-info
# from UnicodeData.txt
# Get fresh UnicodeData.txt from http://www.unicode.org.

scheme/rts/syntax-info.scm: build/UnicodeData.txt			\
	build/PropList.txt						\
	build/SpecialCasing.txt						\
	build/CaseFolding.txt						\
	build/CompositionExclusions.txt					\
	scheme/link/unicode-data.scm 					\
	scheme/env/unicode-category.scm					\
	scheme/big/compact-table.scm
	cd $(srcdir) &&							\
		(echo ',batch';							\
		echo ',config ,load scheme/link/unicode-data-packages.scm';	\
		echo ",in unicode-data (create-unicode-tables \"build/UnicodeData.txt\" \"build/PropList.txt\" \"build/SpecialCasing.txt\" \"build/CaseFolding.txt\" \"build/CompositionExclusions.txt\" \"scheme/env/unicode-info.scm\" \"scheme/rts/syntax-info.scm\" \"scheme/big/unicode-normalization-info.scm\" \"scheme/srfi/srfi-14-base-char-sets.scm\")"		\
	) | $(RUNNABLE) -h 6000000

# --------------------
# Generate scheme48.h from VM sources

c/scheme48.h: c/scheme48.h.in scheme/vm/interp/arch.scm 		\
		scheme/vm/data/data.scm scheme/link/generate-c-header.scm
	cd $(srcdir) &&							\
	(echo ',bench';							\
		echo ',batch';						\
		echo ',load-package big-scheme';			\
		echo ',open big-scheme';				\
		echo ',load scheme/link/generate-c-header.scm';		\
		echo "(make-c-header-file \"$@\"			\
			  \"c/scheme48.h.in\"				\
			  \"scheme/vm/interp/arch.scm\"			\
			  \"scheme/vm/data/data.scm\"			\
			  \"scheme/rts/record.scm\")"			\
	) | $(RUNNABLE)

# An old version of the above for legacy code.

c/old-scheme48.h: scheme/vm/interp/arch.scm scheme/vm/data/data.scm \
	    scheme/link/generate-old-c-header.scm
	(echo ',bench';							\
		echo ',batch';						\
		echo ',load-package big-scheme';			\
		echo ',open big-scheme';				\
		echo ',load scheme/link/generate-old-c-header.scm';	\
		echo "(make-c-header-file \"$@\"			\
			  \"$(srcdir)/scheme/vm/interp/arch.scm\"	\
			  \"$(srcdir)/scheme/vm/data/data.scm\")"   	\
	) | $(RUNNABLE)

# Generate VM and GC from VM sources.
# Never called automatically.  Do not use unless you are sure you
# know what you are doing.
# Afterwards, you should probably make c/scheme48.h.

i-know-what-i-am-doing: \
	compile-vm-32 compile-twospace-gc-32 compile-bibop-gc-32 \
	compile-vm-64 compile-twospace-gc-64 compile-bibop-gc-64

# compiles VM without GC

compile-vm-32:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-32.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-vm-no-gc-32.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 12000000 &&					     \
		mv ../scheme/vm/scheme48vm-32.c ../c

compile-vm-64:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-64.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-vm-no-gc-64.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 12000000 &&					     \
		mv ../scheme/vm/scheme48vm-64.c ../c

# compiles the two-space copier GC

compile-twospace-gc-32:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-32.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-twospace-gc-32.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 8000000 &&					     \
		mv ../scheme/vm/scheme48-twospace-heap-32.c ../c

compile-twospace-gc-64:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-64.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-twospace-gc-64.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 8000000 &&					     \
		mv ../scheme/vm/scheme48-twospace-heap-64.c ../c

# compiles the BIBOP GC

compile-bibop-gc-32:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-32.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-bibop-gc-32.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 8000000 &&					     \
		mv ../scheme/vm/scheme48-bibop-heap-32.c ../c

compile-bibop-gc-64:
	cd $(srcdir)/ps-compiler &&					     \
	(echo ',batch';							     \
		echo ',config ,load ../scheme/platform-interfaces.scm';	     \
		echo ',config ,load ../scheme/rts-packages-64.scm';          \
		echo ',config ,load ../scheme/prescheme/interface.scm';	     \
		echo ',config ,load ../scheme/prescheme/package-defs.scm';   \
		echo ',exec ,load load-ps-compiler.scm';		     \
		echo ',exec ,load compile-bibop-gc-64.scm';		     \
		echo ',exit'						     \
	) | $(RUNNABLE) -h 8000000 &&					     \
		mv ../scheme/vm/scheme48-bibop-heap-64.c ../c