Enable native code compilation when ocamlopt is available.
[whenjobs.git] / daemon / Makefile.am
1 # whenjobs
2 # Copyright (C) 2012 Red Hat Inc.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18 EXTRA_DIST = $(SOURCES) whenjobsd.pod
19
20 sbin_SCRIPTS = whenjobsd
21
22 OCAMLPACKAGES = -package unix,num,camlp4.lib,calendar,rpc -I ../lib
23
24 OCAMLCFLAGS = -g -warn-error CDEFLMPSUVYZX $(OCAMLPACKAGES)
25 OCAMLOPTFLAGS = $(OCAMLCFLAGS)
26
27 # These should be in alphabetical order. 
28 SOURCES = \
29         daemon.mli \
30         daemon.ml \
31         syslog.mli \
32         syslog.ml \
33         whenjobsd.ml \
34         whenproto_srv.mli \
35         whenproto_srv.ml
36
37 # In dependency order.
38 OBJECTS = \
39         syslog.cmo \
40         whenproto_srv.cmo \
41         daemon.cmo \
42         whenjobsd.cmo
43
44 XOBJECTS = $(OBJECTS:.cmo=.cmx)
45
46 # Daemon.
47 noinst_LIBRARIES = libdaemon.a
48 libdaemon_a_SOURCES = exit.c syslog_c.c
49 libdaemon_a_CFLAGS = -I$(shell $(OCAMLC) -where)
50
51 whenproto_srv.ml whenproto_srv.mli: whenproto.x
52         $(OCAMLRPCGEN) -int int32 -hyper int64 -srv $<
53
54 whenproto.x: ../lib/whenproto.x
55         ln -f $< $@
56
57 if HAVE_OCAMLOPT
58 whenjobsd: ../lib/whenlib.cmxa $(XOBJECTS) libdaemon.a
59         $(OCAMLFIND) opt $(OCAMLOPTFLAGS) -ccopt -L../lib \
60           -linkpkg whenlib.cmxa \
61           libdaemon_a-exit.o libdaemon_a-syslog_c.o \
62           $(XOBJECTS) -o $@
63 else
64 whenjobsd: ../lib/whenlib.cma $(OBJECTS) libdaemon.a
65         $(OCAMLFIND) c -custom $(OCAMLCFLAGS) -ccopt -L../lib \
66           -linkpkg whenlib.cma \
67           libdaemon_a-exit.o libdaemon_a-syslog_c.o \
68           $(OBJECTS) -o $@
69 endif
70
71 # Rules for all OCaml files.
72 %.cmi: %.mli ../lib/whenlib.cma
73         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
74 %.cmo: %.ml ../lib/whenlib.cma
75         $(OCAMLFIND) ocamlc $(OCAMLCFLAGS) -c $< -o $@
76 %.cmx: %.ml ../lib/whenlib.cma
77         $(OCAMLFIND) ocamlopt $(OCAMLOPTFLAGS) -c $< -o $@
78
79 SUFFIXES = .cmo .cmi .cmx .ml .mli .mll .mly
80
81 # OCaml dependencies.
82 depend: .depend
83
84 .depend: $(SOURCES)
85         rm -f $@ $@-t
86         $(OCAMLFIND) ocamldep $^ | \
87           $(SED) -e 's/ *$$//' | \
88           $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
89           LANG=C sort > $@-t
90         mv $@-t $@
91
92 -include .depend
93
94 # Manual page.
95 man_MANS = whenjobsd.8
96
97 whenjobsd.8: whenjobsd.pod
98         pod2man \
99           -c "Job scheduling" \
100           --release "$(PACKAGE)-$(VERSION)" \
101           --section 8 \
102           --stderr --utf8 \
103           $< > $@
104
105 CLEANFILES = \
106         *.cmi *.cmo *.cmx *.cma *.cmxa *~ \
107         whenproto.x \
108         whenproto_srv.ml whenproto_srv.mli \
109         whenjobsd