Makefile: Silent-rules stuff.
[fringe] / Makefile
CommitLineData
2bd37ef1
MW
1### Makefile for same-fringe implementations.
2
3###--------------------------------------------------------------------------
4### Notes about organization.
5###
6### Most projects have lots of stuff in just a few languages, so it makes
7### sense to put the language configuration in one place. This one's
8### different. Its entire purpose is to demonstrate lots of different
9### approaches.
10###
11### So, at the top we declare the main targets; then each language has its
12### configuration and build rules.
13
14.SUFFIXES: .o
15LANGS =
8f12efe5 16SOURCES =
2bd37ef1
MW
17TARGETS = $(patsubst %,%-fringe,$(LANGS))
18CLEANFILES = $(TARGETS)
19
20all::
21clean::; rm -f $(CLEANFILES)
22
23###--------------------------------------------------------------------------
43aab76c
MW
24### Silent rules stuff.
25
26## Default verbosity setting.
27V = 0
28
29## Infrastructure.
30v_echo = $(call v_echo_$V,$1)
31v_echo_1 =
32v_echo_0 = @printf " %-6s %s\n" "$1" "$@";
33V_HIDE = $(V_HIDE_$V)
34V_HIDE_0 = @
35
36###--------------------------------------------------------------------------
2bd37ef1
MW
37### Testing.
38
39CLEANFILES += test.*
40test:: all
b3cbee25
MW
41 @win=0 lose=0; \
42 for lang in $(LANGS); do \
43 echo >&3 "*** $$lang"; \
44 printf "Test $$lang..."; \
45 time=`command time -o/dev/stdout -f "%U user; %S system; %E" \
46 ./test ./$${lang}-fringe 2>&3`; \
47 if [ $$? -eq 0 ]; then \
48 win=$$(expr $$win + 1); \
49 printf " ok ($$time)\n"; \
50 else \
51 lose=$$(expr $$lose + 1); \
52 printf " FAILED\n"; \
53 fi; \
54 done 3>test.log; \
55 if [ $$lose -eq 0 ]; then \
56 echo "All $$win test(s) OK"; \
57 else \
58 echo "FAILED $$lose test(s)!"; \
59 exit 1; \
2bd37ef1
MW
60 fi
61
62###--------------------------------------------------------------------------
8f12efe5
MW
63### Reporting.
64
65report::
66 wc -l $(SOURCES) | sort -n
67
68###--------------------------------------------------------------------------
2bd37ef1
MW
69### C.
70
71CC = gcc
72CFLAGS = -O2 -g -pedantic -Wall
73CLEANFILES += *.o
74.SUFFIXES: .c
43aab76c 75.c.o:; $(call v_echo,CC)$(CC) -c $(CFLAGS) -o $@ $<
2bd37ef1
MW
76
77LANGS += c
8f12efe5 78SOURCES += c-fringe.c
2bd37ef1 79c-fringe: c-fringe.o
43aab76c 80 $(call v_echo,CCLD)$(CC) -o $@ $^
2bd37ef1
MW
81
82###--------------------------------------------------------------------------
83### Haskell.
84
85HC = ghc
eee4486f 86HFLAGS = -O2
2bd37ef1
MW
87CLEANFILES += *.hi *.hc
88.SUFFIXES: .hs
43aab76c 89.hs.o:; $(call v_echo,HC)$(HC) -c $(HFLAGS) -o $@ $<
2bd37ef1
MW
90
91LANGS += haskell
8f12efe5 92SOURCES += haskell-fringe.hs
2bd37ef1 93haskell-fringe: haskell-fringe.o
43aab76c 94 $(call v_echo,HCLD)$(HC) -o $@ $^
2bd37ef1
MW
95
96###--------------------------------------------------------------------------
97### Icon.
98
99ICONT = icont
100IFLAGS = -u -fa
101
102LANGS += icon
8f12efe5 103SOURCES += icon-fringe.icn
2bd37ef1 104icon-fringe: icon-fringe.icn
43aab76c 105 $(call v_echo,ICONT)$(ICONT) -o $@ $^
2bd37ef1
MW
106
107###--------------------------------------------------------------------------
108### Common Lisp.
109
23416a99
MW
110CLEANFILES += *.core *.fasl
111
112.SUFFIXES: .lisp .fasl
43aab76c
MW
113.lisp.fasl:
114 $(call v_echo,CL)sbcl --eval \
115 '(quit :unix-status (if (compile-file "$<") 0 1))'
a72b6978 116
2bd37ef1 117LANGS += cl
8f12efe5 118SOURCES += cl-fringe.lisp
23416a99 119cl-fringe: cl-fringe.fasl
43aab76c
MW
120 $(call v_echo,CP)cp $< $@.new && chmod +x $@.new && mv $@.new $@
121## $(call v_echo,CL)cl-launch -o $@ -f `pwd`/$^ +I -r launch -d $@.core
2bd37ef1
MW
122
123###--------------------------------------------------------------------------
124### F#.
125
126FSC = fsc
127CLEANFILES += *.exe
128.SUFFIXES: .fs .exe
43aab76c 129.fs.exe:; $(call v_echo,FSC)$(FSC) -o $@ $<
2bd37ef1
MW
130
131LANGS += f\#
8f12efe5 132SOURCES += f\#-fringe.fs
2bd37ef1 133f\#-fringe: f\#-fringe.exe
43aab76c 134 $(call v_echo,CP)chmod +x $< && cp $< $@
2bd37ef1
MW
135
136###--------------------------------------------------------------------------
137### Scheme.
138
139SCMC = csc
140SCMFLAGS = -c -O2
d33d05c3 141.SUFFIXES: .scm
43aab76c 142.scm.o:; $(call v_echo,SCMC)$(SCMC) $(SCMFLAGS) -o $@ $<
2bd37ef1
MW
143
144LANGS += scheme
8f12efe5 145SOURCES += scheme-fringe.scm
2bd37ef1 146scheme-fringe: scheme-fringe.o
43aab76c 147 $(call v_echo,SCMLD)$(SCMC) -o $@ $^
2bd37ef1
MW
148
149###--------------------------------------------------------------------------
d888ccd5
MW
150### Go.
151
152GOOBJ = 8
153GOC = $(GOOBJ)g
154GOLINK = $(GOOBJ)l
155CLEANFILES += *.$(GOOBJ)
156.SUFFIXES: .$(GOOBJ) .go
43aab76c 157.go.$(GOOBJ):; $(call v_echo,GOC)$(GOC) $(GOFLAGS) $<
d888ccd5
MW
158
159LANGS += go
160SOURCES += go-fringe.go
161go-fringe: go-fringe.$(GOOBJ)
43aab76c 162 $(call v_echo,GOLD)$(GOLINK) -o $@ $^
d888ccd5
MW
163
164###--------------------------------------------------------------------------
2bd37ef1
MW
165### Smalltalk.
166
167LANGS += smalltalk
168TARGETS += smalltalk-fringe.im
8f12efe5 169SOURCES += smalltalk-fringe.st
2bd37ef1 170smalltalk-fringe.im: smalltalk-fringe.st
43aab76c
MW
171 $(call v_echo,GSTIM)echo "ObjectMemory snapshot: '$@.new'" | gst $^ -
172 $(V_HIDE)mv $@.new $@
2bd37ef1 173smalltalk-fringe:
43aab76c 174 $(call v_echo,GENSH){ echo '#! /bin/sh'; \
2bd37ef1
MW
175 echo '"exec" "gst" "-I" "$@.im" "-f" "$$0" "$$@"'; \
176 echo 'ObjectMemory quit: (Node main: Smalltalk arguments)'; \
177 } >$@.new
43aab76c 178 $(V_HIDE)chmod +x $@.new && mv $@.new $@
2bd37ef1
MW
179
180###----- That's all, folks --------------------------------------------------
181
182all:: $(TARGETS)