-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
231 lines (177 loc) · 6.14 KB
/
Makefile
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
# {{{ COPYING
#
# This file is part of a binding for OCaml to the Chipmunk library.
# Copyright (C) 2008 Florent Monnier <monnier.florent(_)gmail.com>
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation the
# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
# sell copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# The Software is provided "as is", without warranty of any kind, express or
# implied, including but not limited to the warranties of merchantability,
# fitness for a particular purpose and noninfringement. In no event shall
# the authors or copyright holders be liable for any claim, damages or other
# liability, whether in an action of contract, tort or otherwise, arising
# from, out of or in connection with the software or the use or other dealings
# in the Software.
#
# }}}
all: chipmunk.cma chipmunk.cmxa
# generated parts
gens: wrap_chipmunk.gen.c chipmunk.gen.ml
wrap_chipmunk.gen.c: gen_funcs.h generate_funcs.ml generate_structs.ml gen_structs.h
> $@
echo "// This is a generated file" >> $@
ocaml generate_funcs.ml --gen-c < gen_funcs.h >> $@
echo "// Structure member access" >> $@
ocaml generate_structs.ml --gen-c < gen_structs.h >> $@
chipmunk.gen.ml: gen_funcs.h generate_funcs.ml generate_structs.ml gen_structs.h
> $@
echo "(* This is a generated file *)" >> $@
ocaml generate_funcs.ml --gen-ml < gen_funcs.h >> $@
echo >> $@
echo "(** {4 Structure Members Access} *)" >> $@
ocaml generate_structs.ml --gen-ml < gen_structs.h >> $@
Chipmunk-6.1.5/src/libchipmunk.a:
( cd ./Chipmunk-6.1.5/ && cmake . && make chipmunk_static )
wrap_chipmunk.o: wrap_chipmunk.c wrap_chipmunk.gen.c
ocamlc -c -ccopt "-I./Chipmunk-6.1.5/include -O3 -std=gnu99 -ffast-math" $<
dll_chipmunk_stubs.so lib_chipmunk_stubs.a: wrap_chipmunk.o \
Chipmunk-6.1.5/src/libchipmunk.a
ocamlmklib \
-L./Chipmunk-6.1.5/src/ \
-o _chipmunk_stubs $< \
-ccopt -O3 -ccopt -std=gnu99 -ccopt -ffast-math \
-lchipmunk
# Makes use of a minimal preprocessor for OCaml source files.
# It is similar to cpp, but this replacement for cpp is because
# cpp versions in different environments may have different
# behaviour with unexpected reactions which will break OCaml code.
MLPP=./mlpp.exe
$(MLPP): mlpp.ml
ocamlopt -w -6 str.cmxa $< -o $@
clean-mlpp:
rm -f $(MLPP)
# generate oo sig
oo: oo.mli
oo.mli: chipmunk.ml
ocamlc -i $< > $@
chipmunk.ml: chipmunk.ml.pp chipmunk.gen.ml $(MLPP)
$(MLPP) $< > $@
chipmunk.mli: chipmunk.ml.pp chipmunk.gen.ml $(MLPP)
$(MLPP) -D MLI -C $< > $@
sed -i $@ -e 's/= struct/: sig/g'
chipmunk.cmi: chipmunk.mli
ocamlc -c $<
# bytecode
chipmunk.cmo: chipmunk.ml chipmunk.cmi
ocamlc -w -6 -c $<
CUSTOM=-custom
chipmunk.cma: chipmunk.cmo dll_chipmunk_stubs.so \
Chipmunk-6.1.5/src/libchipmunk.a
ocamlc -a $(CUSTOM) -o $@ $< \
-ccopt -L./Chipmunk-6.1.5/src/ \
-dllib dll_chipmunk_stubs.so \
-cclib -l_chipmunk_stubs \
-cclib -lchipmunk
# native
chipmunk.cmx: chipmunk.ml chipmunk.cmi
ocamlopt -w -6 -c $<
chipmunk.cmxa chipmunk.a: chipmunk.cmx dll_chipmunk_stubs.so \
Chipmunk-6.1.5/src/libchipmunk.a
ocamlopt -a -o $@ $< \
-cclib -l_chipmunk_stubs \
-ccopt -O3 -ccopt -std=gnu99 -ccopt -ffast-math \
-ccopt -L./Chipmunk-6.1.5/src/ \
-cclib -lchipmunk
.PHONY: clean-doc clean clean-mlpp run-opt-demo test install
# doc
doc: chipmunk.mli
if [ ! -d $@ ]; then mkdir $@ ; fi
cp .style.css $@/_style.css
ocamldoc $< \
-colorize-code -html \
-css-style _style.css \
-d $@
clean-doc:
rm -f doc/*
if [ -d doc ]; then touch doc; fi
# clean
clean: clean-doc clean-mlpp
rm -f \
*.[oa] *.so *.cm[ixoa] *.cmxa *.opt *~ \
doc/*.{html,css} \
*.gen.{ml,c} chipmunk.ml{,i} \
oo.mli log*
# demo
DEMO=./demos/moon_buggy.ml
demo: cp_ml_demo.opt
cp_ml_demo.opt: $(DEMO) chipmunk.cmxa
sed -e 's/^#.*$$//g' demos/moon_buggy.ml > /tmp/`basename $<`
ocamlopt -I +glMLite GL.cmxa Glu.cmxa Glut.cmxa \
chipmunk.cmxa /tmp/`basename $<` -o $@ \
-ccopt -L./
run-opt-demo: cp_ml_demo.opt
./cp_ml_demo.opt
# test
test: chipmunk.cma
ocaml $(DEMO)
# manual install
PREFIX = "`ocamlc -where`/chipmunk"
DIST_FILES=\
chipmunk.a \
chipmunk.cmi \
chipmunk.cma \
chipmunk.cmx \
chipmunk.cmxa \
lib_chipmunk_stubs.a
SO_DIST_FILES=\
dll_chipmunk_stubs.so
install: $(DIST_FILES) $(SO_DIST_FILES)
if [ ! -d $(PREFIX) ]; then install -d $(PREFIX) ; fi
install -m 0755 \
$(SO_DIST_FILES) \
$(PREFIX)/
install -m 0644 \
$(DIST_FILES) \
$(PREFIX)/
uninstall:
rm -i $(PREFIX)/*
rmdir $(PREFIX)
# findlib install
install_findlib: $(DIST_FILES) $(SO_DIST_FILES) META
ocamlfind install chipmunk $^
uninstall_findlib: $(DIST_FILES) $(SO_DIST_FILES) META
ocamlfind remove chipmunk
# tar-ball
VERSION=0.04.2
P_DIR=ocaml-chipmunk-$(VERSION)
TARBALL=$(P_DIR).tgz
snapshot release rel dist pack: $(TARBALL)
CP_FILES= wrap_chipmunk.c chipmunk.ml.pp \
wrap_chipmunk.h \
Makefile META README.txt \
generate_structs.ml gen_structs.h \
generate_funcs.ml gen_funcs.h \
mlpp.ml .style.css
DM_FILES= demos/moon_buggy.ml \
demos/demo_dist.ml
$(P_DIR)/demos: $(DM_FILES)
if [ ! -d $@ ]; then mkdir -p $@; fi
cp $^ $@/
$(P_DIR): LICENSE_MIT.txt $(CP_FILES) $(P_DIR)/demos
mkdir -p $(P_DIR)
cp LICENSE_MIT.txt $(P_DIR)/
cp -f $(CP_FILES) $(P_DIR)/
sed -i $(P_DIR)/META -e "s:@VERSION@:$(VERSION):g"
$(TARBALL): $(P_DIR)
tar cf $(P_DIR).tar $(P_DIR)
gzip -9 $(P_DIR).tar
mv $(P_DIR).tar.gz $@
# vim: fdm=marker