OSDN Git Service

improve OMakefile
[happyabc/happyabc.git] / OMakefile
1 PREFIX=
2         if $(not $(defined PREFIX))
3                 value /usr/local
4         else
5                 value $(PREFIX)
6 ENABLE_DEBUG=
7         if $(not $(defined ENABLE_DEBUG))
8                 value false
9         else
10                 value $(ENABLE_DEBUG)
11
12 # behavior as traditional cpp
13 CPPFLAGS=-traditional-cpp
14
15 if $(file-exists VERSION)
16         VERSION=$(shell head -1 VERSION)
17         export
18 else
19         VERSION=local-HEAD
20         export
21
22 Shell. +=
23     ocaml-clean(argv) =
24       rm -f *.cm[aiox] *.o *.omc *.opt *.run *~ $(argv) *.cmxa *.a *.spot *.spit *.annot *.runner
25
26 # ------------------------------
27 # camlp4 rules
28 # ------------------------------
29 public.UseCamlp4(files) =
30         protected.CAMLP4CMO = $(addprefix $(ROOT)/camlp4/,$(addsuffix .cmo,$(files)))
31         OCAMLPPFLAGS+=-pp 'camlp4o $(CAMLP4CMO)'
32         OCAMLDEPFLAGS+=-pp 'camlp4o $(CAMLP4CMO)'
33         export
34
35         .SCANNER: scan-ocaml-%.ml: %.ml $(CAMLP4CMO)
36
37 # ------------------------------
38 # ounit rules
39 # ------------------------------
40 OUNIT_SRC_DIR=../src/
41 OUNIT_LIBS[]=
42
43 Shell. +=
44     ounit-postproc(argv) =
45       (grep "FAIL\|ERROR\|Error\|Fail" && exit 1) || exit 0
46
47 public.OUnitTest(name,files) =
48         protected.test_file = $(addsuffix Test,$(name))
49         protected.target    = $(addsuffix .runner.run,$(test_file))
50         protected.src_files = $(addprefix $(OUNIT_SRC_DIR),$(files))
51
52         .PHONY: check check-$(name) clean
53         OCamlProgram($(target), $(test_file) $(src_files) $(OUNIT_LIBS))
54
55         check-$(name): $(target)
56                 $(addprefix ./,$(target)) | ounit-postproc
57
58         check: check-$(name)
59
60         export
61
62 # ------------------------------
63 # other rules
64 # ------------------------------t
65 %.mli : %.mlip
66     @rm -f $@
67     @echo "(* CAUTION: this is a generated file.  If you edit it, all changes will be lost! *)" > $@
68     $(CPP) $(CPPFLAGS) $*.mlip >> $@
69     @chmod 444 $@
70
71 .SCANNER: %.mli : %.mlip
72     $(CPP) $(CPPFLAGS) -M $< ;  true
73
74 %.ml: %.mlp
75     @rm -f $@
76     @echo "(* CAUTION: this is a generated file.  If you edit it, all changes will be lost! *)" > $@
77     $(CPP) $(CPPFLAGS) $*.mlp >> $@
78     @chmod 444 $@
79
80 .SCANNER: %.ml : %.mlp
81     $(CPP) $(CPPFLAGS) -M $< ; true
82
83
84 USE_OCAMLFIND = true
85
86 if $(not $(OCAMLFIND_EXISTS))
87    eprintln('This project requires ocamlfind, but is was not found.')
88    eprintln('You need to install ocamlfind and run "omake --configure".')
89    exit 1
90
91 NATIVE_ENABLED = false
92 BYTE_ENABLED = true
93
94
95 .PHONY: all install config clean distclean example
96
97 # ------------------------------
98 # config
99 # ------------------------------
100 config: OMakefile.config base/config.ml
101
102 .INCLUDE: OMakefile.config
103         if $(mem config,$(TARGETS))
104                 rm -f $@
105                 if $(and $(defined RELATIVE),$(RELATIVE))
106                         echo LIB_DIR=$(PREFIX) >> $@
107                         echo SHARE_DIR=$(PREFIX) >> $@
108                         echo BIN_DIR=$(PREFIX) >> $@
109                 else
110                         if $(not $(defined LIB_DIR))
111                                 echo LIB_DIR=$(PREFIX)/lib/habc >> $@
112                         else
113                                 echo LIB_DIR=$(LIB_DIR) >> $@
114                         if $(not $(defined SHARE_DIR))
115                                 echo SHARE_DIR=$(PREFIX)/share/habc >> $@
116                         else
117                                 echo SHARE_DIR=$(SHARE_DIR) >> $@
118                         if $(not $(defined BIN_DIR))
119                                 echo BIN_DIR=$(PREFIX)/bin >> $@
120                         else
121                                 echo BIN_DIR=$(BIN_DIR) >> $@
122
123                 if $(shell-success-null ocamlc$(if $(OCAMLC_OPT_EXISTS), .opt) -annot)
124                         @echo "static.OCAMLFLAGS +=-annot" >> $@
125                 else
126                         @echo "static.OCAMLFLAGS +=-dtypes" >> $@
127                 if $(ENABLE_DEBUG)
128                         @echo "static.OCAMLFLAGS +=-g" >> $@
129         if $(not $(file-exists OMakefile.config))
130                 @echo "Please refer to the installation instructions in file README.mkdn."
131                 @echo "If you've just unpacked the distribution, something like"
132                 @echo "   omake config"
133                 @echo "   omake all"
134                 @echo "   omake install"
135                 @echo "should work.  But see the file README.mkdn for more details."
136
137 base/config.ml:
138         if $(mem config,$(TARGETS))
139                 rm -f $@
140                 echo 'let version = "$(VERSION)"' >> $@
141                 if $(and $(defined RELATIVE),$(RELATIVE))
142                         @echo 'let bin_dir   = Str.global_replace (Str.regexp "\\\\") "/" (Filename.dirname Sys.executable_name)' >> $@
143                         @echo 'let share_dir = bin_dir' >> $@
144                         @echo 'let lib_dir   = bin_dir' >> $@
145                 else
146                         @echo 'let bin_dir   = "$(ocaml-escaped  $(BIN_DIR))"' >> $@
147                         @echo 'let share_dir = "$(ocaml-escaped  $(SHARE_DIR))"' >> $@
148                         @echo 'let lib_dir   = "$(ocaml-escaped  $(LIB_DIR))"' >> $@
149                 @echo 'let default_includes = [lib_dir;"."]' >> $@
150                 @echo 'let default_template = share_dir ^ "/template.xml"' >> $@
151                 @echo 'let path_sep="$(PATHSEP)"' >> $@
152                 @echo 'let exe="$(EXE)"' >> $@
153
154 .SUBDIRS: scm xml driver base lib camlp4 docs
155
156 # ------------------------------
157 # all
158 # ------------------------------
159 habc-scm$(EXE): scm/src/habc-scm$(EXE)
160         $(LN) $^ .
161
162 habc-xml$(EXE): xml/src/habc-xml$(EXE)
163         $(LN) $^ .
164
165 habc$(EXE) : driver/habc$(EXE)
166         $(LN) $^ .
167
168 PROGRAM = habc$(EXE) habc-xml$(EXE) habc-scm$(EXE)
169
170 all: config $(PROGRAM)
171
172 .DEFAULT: all
173
174 # ------------------------------
175 # install
176 # ------------------------------
177 install: $(PROGRAM)
178         mkdir -p $(BIN_DIR)
179         mkdir -p $(LIB_DIR)
180         mkdir -p $(SHARE_DIR)
181         mkdir -p $(SHARE_DIR)/example
182         $(INSTALL) $(PROGRAM)   $(BIN_DIR)
183         $(INSTALL) share/habc/* $(SHARE_DIR)
184         $(INSTALL) example/*    $(SHARE_DIR)/example/
185         $(INSTALL) lib/habc/*   $(LIB_DIR)
186         if $(or $(equal Win32,$(OSTYPE)),$(equal Cygwin,$(OSTYPE)))
187                 $(INSTALL) win32/swfmill/* $(BIN_DIR)/
188                 $(INSTALL) README.mkdn $(BIN_DIR)/
189
190 # ------------------------------
191 # clean
192 # ------------------------------
193 clean:
194         ocaml-clean *.abc $(PROGRAM)
195
196 distclean: clean
197         ocaml-clean *.abc $(PROGRAM) OMakefile.config base/config.ml
198
199 # ------------------------------
200 # example
201 # ------------------------------
202 %.swf: example/%.scm all
203         ./habc -o $(removesuffix $@) $<