Sync Mk with ports
[dports.git] / Mk / Uses / ncurses.mk
1 # $FreeBSD$
2 #
3 # handle dependency on the ncurses port
4 #
5 # Feature:      ncurses
6 # Usage:        USES=ncurses
7 # Valid ARGS:   base port
8 #
9 # use/port can now set this options to the makefiles
10 # NCURSES_RPATH= yes    - pass RFLAGS options to CFLAGS
11 #
12 # Overridable defaults:
13 # NCURSES_PORT= devel/ncurses
14 #
15 # The makefile sets the following variables:
16 # NCURSESBASE           - "/usr" or ${LOCALBASE}
17 # NCURSESLIB            - path to the libs
18 # NCURSESINC            - path to the matching includes
19 # NCURSESRPATH          - rpath for dynamic linker
20 #
21 # BUILD_DEPENDS         - are added if needed
22 # RUN_DEPENDS           - are added if needed
23 #
24 # MAINTAINER: portmgr@FreeBSD.org
25
26 .if !defined(_INCLUDE_USES_NCURSES_MK)
27 _INCLUDE_USES_NCURSES_MK=       yes
28
29 .if empty(ncurses_ARGS)
30 .  if !exists(${DESTDIR}/${LOCALBASE}/lib/libncurses.so) && exists(${DESTDIR}/usr/lib/libncurses.so)
31 ncurses_ARGS=   base
32 .  else
33 ncurses_ARGS=   port
34 .  endif
35 .endif
36
37 .if ${ncurses_ARGS} == base
38 NCURSESBASE=    /usr
39 NCURSESINC=     ${NCURSESBASE}/include
40
41 .  if exists(${LOCALBASE}/lib/libncurses.so)
42 _USES_sanity+=  400:check-depends-ncurses
43 check-depends-ncurses:
44         @${ECHO_CMD} "Dependency error: this port wants the ncurses library from the FreeBSD"
45         @${ECHO_CMD} "base system. You can't build against it, while a newer"
46         @${ECHO_CMD} "version is installed by a port."
47         @${ECHO_CMD} "Please deinstall the port or undefine WITH_NCURSES_BASE."
48         @${FALSE}
49 .  endif
50
51 NCURSESRPATH=   /usr/lib:${LOCALBASE}/lib
52
53 .elif ${ncurses_ARGS} == port
54 NCURSESBASE=    ${LOCALBASE}
55 NCURSESINC=     ${LOCALBASE}/include/ncurses
56
57 .  if !defined(NCURSES_PORT) && exists(${DESTDIR}/${LOCALBASE}/lib/libncurses.so)
58 PKG_DBDIR?=     ${DESTDIR}/var/db/pkg
59 .    if defined(DESTDIR)
60 PKGARGS=        -c ${DESTDIR}
61 .    endif
62 PKGARGS?=
63 NCURSES_INSTALLED!=     ${PKG_BIN} ${PKGARGS} which -qo ${LOCALBASE}/lib/libncurses.so || :
64 .  endif
65 NCURSES_INSTALLED?=
66
67 .  if ${NCURSES_INSTALLED} != ""
68 NCURSES_PORT=   ${NCURSES_INSTALLED}
69 NCURSES_SHLIBFILE!=     ${PKG_INFO} -ql ${NCURSES_INSTALLED} | grep -m 1 "^`pkg query "%p" ${NCURSES_INSTALLED}`/lib/libncurses.so."
70 NCURSES_SHLIBVER?=      ${NCURSES_SHLIBFILE:E}
71 .  endif
72
73 NCURSES_PORT?=          devel/ncurses
74 .  if exists (/usr/lib/priv/libprivate_ncursesw.so)
75 NCURSES_SHLIBVER?=      6
76 .  else
77 NCURSES_SHLIBVER?=      6P
78 .  endif
79
80 BUILD_DEPENDS+=         ${LOCALBASE}/lib/libncurses.so.${NCURSES_SHLIBVER}:${NCURSES_PORT}
81 RUN_DEPENDS+=           ${LOCALBASE}/lib/libncurses.so.${NCURSES_SHLIBVER}:${NCURSES_PORT}
82 NCURSESRPATH=           ${NCURSESBASE}/lib
83 LDFLAGS+=               -L${NCURSESRPATH} -Wl,-rpath=${NCURSESRPATH}
84 CFLAGS+=                -I${NCURSESBASE}/include -I${NCURSESINC}
85
86 .  if defined(NCURSES_RPATH)
87 CFLAGS+=                -Wl,-rpath,${NCURSESRPATH}
88 .  endif
89
90 .else
91 .error          USES=ncurses only accept 'port' and 'base' as arguments, got ${ncurses_ARGS}
92 .endif
93
94 NCURSESLIB=     ${NCURSESBASE}/lib
95
96 .endif