| 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 |
| 15 | LANGS = |
| 16 | SOURCES = |
| 17 | TARGETS = $(patsubst %,%-fringe,$(LANGS)) |
| 18 | CLEANFILES = $(TARGETS) |
| 19 | |
| 20 | all:: |
| 21 | clean::; rm -f $(CLEANFILES) |
| 22 | |
| 23 | ###-------------------------------------------------------------------------- |
| 24 | ### Silent rules stuff. |
| 25 | |
| 26 | ## Default verbosity setting. |
| 27 | V = 0 |
| 28 | |
| 29 | ## Infrastructure. |
| 30 | v_echo = $(call v_echo_$V,$1) |
| 31 | v_echo_1 = |
| 32 | v_echo_0 = @printf " %-6s %s\n" "$1" "$@"; |
| 33 | V_HIDE = $(V_HIDE_$V) |
| 34 | V_HIDE_0 = @ |
| 35 | |
| 36 | ###-------------------------------------------------------------------------- |
| 37 | ### Testing. |
| 38 | |
| 39 | CLEANFILES += test.* |
| 40 | test:: all |
| 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; \ |
| 60 | fi |
| 61 | |
| 62 | ###-------------------------------------------------------------------------- |
| 63 | ### Reporting. |
| 64 | |
| 65 | report:: |
| 66 | wc -l $(SOURCES) | sort -n |
| 67 | |
| 68 | ###-------------------------------------------------------------------------- |
| 69 | ### C. |
| 70 | |
| 71 | CC = gcc |
| 72 | CFLAGS = -O2 -g -pedantic -Wall |
| 73 | CLEANFILES += *.o |
| 74 | .SUFFIXES: .c |
| 75 | .c.o:; $(call v_echo,CC)$(CC) -c $(CFLAGS) -o $@ $< |
| 76 | |
| 77 | LANGS += c |
| 78 | SOURCES += c-fringe.c |
| 79 | c-fringe: c-fringe.o |
| 80 | $(call v_echo,CCLD)$(CC) -o $@ $^ |
| 81 | |
| 82 | ###-------------------------------------------------------------------------- |
| 83 | ### Haskell. |
| 84 | |
| 85 | HC = ghc |
| 86 | HFLAGS = -O2 |
| 87 | CLEANFILES += *.hi *.hc |
| 88 | .SUFFIXES: .hs |
| 89 | .hs.o:; $(call v_echo,HC)$(HC) -c $(HFLAGS) -o $@ $< |
| 90 | |
| 91 | LANGS += haskell |
| 92 | SOURCES += haskell-fringe.hs |
| 93 | haskell-fringe: haskell-fringe.o |
| 94 | $(call v_echo,HCLD)$(HC) -o $@ $^ |
| 95 | |
| 96 | ###-------------------------------------------------------------------------- |
| 97 | ### Icon. |
| 98 | |
| 99 | ICONT = icont |
| 100 | IFLAGS = -u -s -fa |
| 101 | |
| 102 | LANGS += icon |
| 103 | SOURCES += icon-fringe.icn |
| 104 | icon-fringe: icon-fringe.icn |
| 105 | $(call v_echo,ICONT)$(ICONT) $(IFLAGS) -o $@ $^ |
| 106 | |
| 107 | ###-------------------------------------------------------------------------- |
| 108 | ### Common Lisp. |
| 109 | |
| 110 | CLEANFILES += *.core *.fasl |
| 111 | |
| 112 | .SUFFIXES: .lisp .fasl |
| 113 | .lisp.fasl: |
| 114 | $(call v_echo,CL)sbcl --noinform --eval \ |
| 115 | '(quit :unix-status (if (compile-file "$<" :verbose nil :print nil) 0 1))' |
| 116 | |
| 117 | LANGS += cl |
| 118 | SOURCES += cl-fringe.lisp |
| 119 | cl-fringe: cl-fringe.fasl |
| 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 |
| 122 | |
| 123 | ###-------------------------------------------------------------------------- |
| 124 | ### F#. |
| 125 | |
| 126 | FSC = fsharpc |
| 127 | FSCFLAGS = |
| 128 | CLEANFILES += *.exe |
| 129 | .SUFFIXES: .fs .exe |
| 130 | .fs.exe:; $(call v_echo,FSC)$(FSC) --nologo $(FSCFLAGS) -o $@ $< |
| 131 | |
| 132 | LANGS += f\# |
| 133 | SOURCES += f\#-fringe.fs |
| 134 | f\#-fringe: f\#-fringe.exe |
| 135 | $(call v_echo,CP)chmod +x $< && cp $< $@ |
| 136 | |
| 137 | ###-------------------------------------------------------------------------- |
| 138 | ### Scheme. |
| 139 | |
| 140 | SCMC = csc |
| 141 | SCMFLAGS = -c -O2 |
| 142 | .SUFFIXES: .scm |
| 143 | .scm.o:; $(call v_echo,SCMC)$(SCMC) $(SCMFLAGS) -o $@ $< |
| 144 | |
| 145 | LANGS += scheme |
| 146 | SOURCES += scheme-fringe.scm |
| 147 | scheme-fringe: scheme-fringe.o |
| 148 | $(call v_echo,SCMLD)$(SCMC) -o $@ $^ |
| 149 | |
| 150 | ###-------------------------------------------------------------------------- |
| 151 | ### Go. |
| 152 | |
| 153 | GOBUILD = go build |
| 154 | LANGS += go |
| 155 | SOURCES += go-fringe.go |
| 156 | go-fringe: go-fringe.go |
| 157 | $(call v_echo,GO)$(GOBUILD) -o $@ $^ |
| 158 | |
| 159 | ###-------------------------------------------------------------------------- |
| 160 | ### Smalltalk. |
| 161 | |
| 162 | LANGS += smalltalk |
| 163 | TARGETS += smalltalk-fringe.im |
| 164 | SOURCES += smalltalk-fringe.st |
| 165 | smalltalk-fringe.im: smalltalk-fringe.st |
| 166 | $(call v_echo,GSTIM)echo "ObjectMemory snapshot: '$@.new'" | gst $^ - |
| 167 | $(V_HIDE)mv $@.new $@ |
| 168 | smalltalk-fringe: |
| 169 | $(call v_echo,GENSH){ echo '#! /bin/sh'; \ |
| 170 | echo '"exec" "gst" "-I" "$@.im" "-f" "$$0" "$$@"'; \ |
| 171 | echo 'ObjectMemory quit: (Node main: Smalltalk arguments)'; \ |
| 172 | } >$@.new |
| 173 | $(V_HIDE)chmod +x $@.new && mv $@.new $@ |
| 174 | |
| 175 | ###-------------------------------------------------------------------------- |
| 176 | ### Forth. |
| 177 | |
| 178 | LANGS += forth |
| 179 | TARGETS += forth-fringe |
| 180 | SOURCES += forth-fringe.fth |
| 181 | forth-fringe: forth-fringe.fth |
| 182 | $(call v_echo,FORTHI)gforthmi $@ $< |
| 183 | |
| 184 | ###-------------------------------------------------------------------------- |
| 185 | ### Erlang. |
| 186 | |
| 187 | ERLC = erlc |
| 188 | CLEANFILES += *.beam erl_crash.dump |
| 189 | .SUFFIXES: .erl .beam |
| 190 | .erl.beam:; $(call v_echo,ERLC)$(ERLC) $(ERLCFLAGS) $< |
| 191 | |
| 192 | LANGS += erlang |
| 193 | TARGETS += erlang-fringe.beam |
| 194 | SOURCES += erlang-fringe.erl |
| 195 | erlang-fringe: |
| 196 | $(call v_echo,GENSH){ echo '#! /bin/sh'; \ |
| 197 | echo 'exec erl -pa . -noshell -run erlang-fringe main -extra "$$@"'; \ |
| 198 | } >$@.new |
| 199 | $(V_HIDE)chmod +x $@.new && mv $@.new $@ |
| 200 | |
| 201 | ###-------------------------------------------------------------------------- |
| 202 | ### Algol 68. |
| 203 | |
| 204 | ALGOL68 = /usr/local/bin/a68g |
| 205 | |
| 206 | LANGS += algol68 |
| 207 | TARGETS += algol68-fringe |
| 208 | SOURCES += algol68-fringe.a68 |
| 209 | |
| 210 | algol68-fringe: algol68-fringe.a68 |
| 211 | $(call v_echo,GENSH){ echo '#! $(ALGOL68) --script'; \ |
| 212 | cat $<; \ |
| 213 | } >$@.new |
| 214 | $(V_HIDE)chmod +x $@.new && mv $@.new $@ |
| 215 | |
| 216 | ###-------------------------------------------------------------------------- |
| 217 | ### Dylan. |
| 218 | |
| 219 | D2C = d2c |
| 220 | CLEANFILES += dylan-*.c *.mak |
| 221 | |
| 222 | LANGS += dylan |
| 223 | TARGETS += dylan-fringe |
| 224 | SOURCES += dylan-fringe.dylan dylan-fringe-exports.dylan |
| 225 | SOURCES += dylan-fringe.lid |
| 226 | |
| 227 | dylan-fringe: dylan-fringe.lid dylan-fringe.dylan dylan-fringe-exports.dylan |
| 228 | $(call v_echo,D2C)d2c -g $< |
| 229 | |
| 230 | ###----- That's all, folks -------------------------------------------------- |
| 231 | |
| 232 | all:: $(TARGETS) |