Mk/Uses/iconv: support iconv+
[dports.git] / Mk / bsd.ocaml.mk
1 # ex:ts=4
2 #
3 # $MBSDlabs: portmk/bsd.ocaml.mk,v 1.18 2006/08/06 18:47:23 stas Exp $
4 # $FreeBSD: ports/Mk/bsd.ocaml.mk,v 1.5 2012/11/17 05:54:17 svnexp Exp $
5 #
6 # bsd.ocaml.mk - Support for the Objective Caml language packages
7 #
8 # Author: Stanislav Sedov <ssedov@mbsd.msk.ru>
9 #
10 # Feel free to send any comments and suggestions to maintainer.
11 #
12 # Currently recognised variables are:
13 #
14 # USE_OCAML             -       Set if your port uses OCaml to build/install.
15 # NO_OCAML_BUILDDEPENDS -       Don't add ocamlc to BUILD|EXTRACT|PATCH_DEPENDS.
16 # NO_OCAML_RUNDEPENDS   -       Don't add ocamlc to RUN_DEPENDS.
17 # USE_OCAML_FINDLIB     -       Set if your port uses ocamlfind to install
18 #                               packages. Package direcories will be
19 #                               automatically deleted.
20 # USE_OCAML_LDCONFIG    -       Set if your port installs shared libraries
21 #                               into ocaml site-lib dir. OCaml ld.conf file
22 #                               will be automatically processed.
23 # USE_OCAMLFIND_PLIST   -       Add contents of findlib target directories
24 #                               automatically.
25 # USE_OCAML_WASH        -       Set if your port wants to automatically
26 #                               purge shared Ocaml dirs on uninstall. It's
27 #                               useful when installing to non-standard PREFIX
28 # OCAML_PKGDIRS         -       Directories under site-lib to be processed
29 #                               if USE_OCAML_FINDLIB specified.
30 #                               Default: ${PORTNAME}
31 # OCAML_LDLIBS          -       Directories under PREFIX to be automatically
32 #                               added/removed from ld.conf
33 #                               Default: ${OCAML_SITELIBDIR}/${PORTNAME}
34
35 .if !defined(OCAML_include)
36
37 OCAML_MAINTAINER=       ports@FreeBSD.org
38 OCAML_include=          bsd.ocaml.mk
39
40 #
41 # OCaml programs location
42 #
43 OCAMLC?=                ${LOCALBASE}/bin/ocamlc
44 OCAMLC_OPT?=            ${LOCALBASE}/bin/ocamlc.opt
45 OCAMLCP?=               ${LOCALBASE}/bin/ocamlcp
46 OCAMLFIND?=             ${LOCALBASE}/bin/ocamlfind
47
48 #
49 # OCaml library directory
50 #
51 OCAML_LIBDIR?=          lib/ocaml
52
53 #
54 # Where to install site libraries
55 #
56 OCAML_SITELIBDIR?=      ${OCAML_LIBDIR}/site-lib
57
58 #
59 # OCaml compiler port dependency
60 #
61 OCAMLC_PORT?=           ${PORTSDIR}/lang/ocaml
62 OCAMLC_DEPEND?=         ${OCAMLC}:${OCAMLC_PORT}
63
64 #
65 # OCaml package manager port dependency
66 #
67 OCAMLFIND_PORT?=        ${PORTSDIR}/devel/ocaml-findlib
68 OCAMLFIND_DEPEND?=      ${OCAMLFIND}:${OCAMLFIND_PORT}
69
70 #
71 # Common OCaml examples and documents location
72 #
73 OCAML_DOCSDIR=          ${PREFIX}/share/doc/ocaml
74 OCAML_EXAMPLESDIR=      ${PREFIX}/share/examples/ocaml
75
76 #
77 # Location of OCaml ld.conf file
78 #
79 OCAML_LDCONF?=          ${OCAML_LIBDIR}/ld.conf
80
81 OCAMLFIND_DESTDIR?=     ${PREFIX}/${OCAML_SITELIBDIR}
82 OCAMLFIND_LDCONF?=      ${PREFIX}/${OCAML_LDCONF}
83
84 .if defined(USE_OCAML)
85 . if !defined(NO_OCAML_BUILDDEPENDS)
86 EXTRACT_DEPENDS+=       ${OCAMLC_DEPEND}
87 PATCH_DEPENDS+=         ${OCAMLC_DEPEND}
88 BUILD_DEPENDS+=         ${OCAMLC_DEPEND}
89 . endif
90 . if !defined(NO_OCAML_RUNDEPENDS)
91 RUN_DEPENDS+=           ${OCAMLC_DEPEND}
92 . endif
93 PLIST_SUB+=     OCAML_SITELIBDIR="${OCAML_SITELIBDIR}"
94 .endif
95
96 .if defined(USE_OCAML_FINDLIB) || defined(USE_OCAML_LDCONFIG)
97 . if !target(post-install-script)
98 post-install-script: ocaml-findlib ocaml-ldconfig ocaml-wash
99 . endif
100 .endif
101
102 .if defined(USE_OCAML_FINDLIB)
103 #
104 # We'll additionally add ocamlfind to RUN_DEPENDS, since
105 # if the port requires ocamlfind to install - it requires
106 # some ocaml libraries and these libraries RUN_DEPENDS on
107 # ocamlfind
108 #
109 BUILD_DEPENDS+=         ${OCAMLFIND_DEPEND}
110 RUN_DEPENDS+=           ${OCAMLFIND_DEPEND}
111 MAKE_ENV+=      OCAMLFIND_DESTDIR="${OCAMLFIND_DESTDIR}" \
112                 OCAMLFIND_LDCONF="${OCAMLFIND_LDCONF}"
113
114 #
115 # Directories under site-lib to process automatically
116 #
117 OCAML_PKGDIRS?= ${PORTNAME}
118 . if !target(pre-install-script)
119 pre-install-script:
120 .if !exists(${OCAMLFIND_DESTDIR})
121         @${MKDIR} "${PREFIX}/${OCAML_SITELIBDIR}"
122 .endif
123 . endif
124 . if !target(ocaml-findlib)
125 ocaml-findlib:
126 .  for DIR in ${OCAML_PKGDIRS}
127 .   if defined(USE_OCAMLFIND_PLIST)
128         @${FIND} ${PREFIX}/${OCAML_SITELIBDIR}/${DIR}/ -type f -print | ${SED} -e \
129                 's,^${PREFIX}/,,' >> ${TMPPLIST}
130 .   endif
131         @${ECHO_CMD} "@unexec rmdir %D/${OCAML_SITELIBDIR}/${DIR} 2>/dev/null || true" >> ${TMPPLIST}
132         @${ECHO_CMD} "@unexec ${OCAMLFIND} remove ${DIR} 2>/dev/null" \
133                 >> ${TMPPLIST}
134 .  endfor
135 . endif
136 .endif
137
138 .if defined(USE_OCAML_LDCONFIG)
139 #
140 # Directories under PREFIX for appending to ld.conf
141 #
142 OCAML_LDLIBS?=  ${OCAML_SITELIBDIR}/${PORTNAME}
143 . if !target(ocaml-ldconfig)
144 ocaml-ldconfig:
145 .  for LIB in ${OCAML_LDLIBS}
146         @${ECHO_CMD} "${PREFIX}/${LIB}" >> "${PREFIX}/${OCAML_LDCONF}"
147         @${ECHO_CMD} "@exec ${ECHO_CMD} "%D/${LIB}" >> %D/${OCAML_LDCONF}" \
148                 >> ${TMPPLIST}
149         @${ECHO_CMD} "@unexec ${SED} -i \"\" -e '/${LIB:S#/#\/#g}/d' %D/${OCAML_LDCONF}"  >> ${TMPPLIST}
150 .  endfor
151 . endif
152 .endif
153
154 .if defined(USE_OCAML_WASH)
155 . if !target(ocaml-wash)
156 ocaml-wash:
157         @${ECHO_CMD} "@unexec rmdir %D/${OCAML_SITELIBDIR} 2>/dev/null || true"\
158                 >> ${TMPPLIST}
159 #       If ld.conf is empty
160         @${ECHO_CMD} "@unexec if [ ! -s %D/${OCAML_LDCONF} ]; then ${RM} -f %D/${OCAML_LDCONF}; fi || true" >> ${TMPPLIST}
161         @${ECHO_CMD} "@unexec rmdir %D/${OCAML_LIBDIR} 2>/dev/null || true" \
162                 >> ${TMPPLIST}
163 . endif
164 .endif
165
166 .if !target(ocaml-findlib)
167 ocaml-findlib:
168         @${DO_NADA}
169 .endif
170
171 .if !target(ocaml-ldconfig)
172 ocaml-ldconfig:
173         @${DO_NADA}
174 .endif
175
176 .if !target(ocaml-wash)
177 ocaml-wash:
178         @${DO_NADA}
179 .endif
180
181 #
182 # XXX: temporary workaround for non-standard PREFIX
183 #
184 .if !target(add-plist-post)
185 add-plist-post:
186 . if (${PREFIX} != ${LOCALBASE} && \
187         ${PREFIX} != ${LINUXBASE} && ${PREFIX} != "/usr")
188         @${ECHO_CMD} "@unexec rmdir %D 2> /dev/null || true" >> ${TMPPLIST}
189 . else
190         @${DO_NADA}
191 . endif
192
193 # If we are using PORTDOCS macro port cannot delete OCAML_DOCSDIR, so
194 # we shoud try to accomodate it
195 . if defined(PORTDOCS)
196         @${ECHO_CMD} "@unexec rmdir ${OCAML_DOCSDIR} 2>/dev/null || true" \
197                 >> ${TMPPLIST}
198 . endif
199 .endif
200
201 .endif #!defined(OCAML_include)