b1944aa66223e2ebe0075f24e3f6c20db8a6b667
[pkgsrc.git] / devel / ncursesw / builtin.mk
1 # $NetBSD: builtin.mk,v 1.8 2009/01/18 06:56:34 dholland Exp $
2
3 BUILTIN_PKG:=   ncursesw
4
5 # H_NB_CURSESW searches for NetBSD's <curses.h> that uses HAVE_WCHAR to
6 #       build with wide curses support.
7 #
8 # XXX Need to deal with Solaris <curses.h>
9 #
10 BUILTIN_FIND_LIBS:=                     ncursesw curses
11 BUILTIN_FIND_FILES_VAR:=                H_NB_CURSESW H_NCURSESW
12 BUILTIN_FIND_FILES.H_NB_CURSESW=        /usr/include/curses.h
13 BUILTIN_FIND_GREP.H_NB_CURSESW=         \#ifdef[        ]*HAVE_WCHAR
14 BUILTIN_FIND_FILES.H_NCURSESW=          /usr/include/ncursesw/curses.h  \
15                                         /usr/include/curses.h
16 BUILTIN_FIND_GREP.H_NCURSESW=           \Id: curses.wide,v
17
18 .include "../../mk/buildlink3/bsd.builtin.mk"
19
20 ###
21 ### Determine if there is a built-in implementation of the package and
22 ### set IS_BUILTIN.<pkg> appropriately ("yes" or "no").
23 ###
24 .if !defined(IS_BUILTIN.ncursesw)
25 IS_BUILTIN.ncursesw=    no
26 .  if empty(H_NCURSESW:M__nonexistent__) && \
27       empty(H_NCURSESW:M${LOCALBASE}/*) && \
28       !empty(BUILTIN_LIB_FOUND.ncursesw:M[yY][eE][sS])
29 IS_BUILTIN.ncursesw=    yes
30 .  endif
31 .endif
32 MAKEVARS+=      IS_BUILTIN.ncursesw
33
34 ###
35 ### If there is a built-in implementation, then set BUILTIN_PKG.<pkg> to
36 ### a package name to represent the built-in package.
37 ###
38 .if !defined(BUILTIN_PKG.ncursesw) && \
39     !empty(IS_BUILTIN.ncursesw:M[yY][eE][sS]) && \
40     empty(H_NCURSESW:M__nonexistent__)
41 BUILTIN_VERSION.ncursesw!=                                              \
42         ${AWK} '/\#define[      ]*NCURSES_VERSION[      ]/ {            \
43                         vers = $$3;                                     \
44                         gsub("\"", "", vers);                           \
45                         print vers;                                     \
46                 }                                                       \
47         ' ${H_NCURSESW:Q}
48 BUILTIN_PKG.ncursesw=   ncursesw-${BUILTIN_VERSION.ncursesw}
49 .endif
50 MAKEVARS+=      BUILTIN_PKG.ncursesw
51
52 ###
53 ### Determine whether we should use the built-in implementation if it
54 ### exists, and set USE_BUILTIN.<pkg> appropriate ("yes" or "no").
55 ###
56 .if !defined(USE_BUILTIN.ncursesw)
57 .  if ${PREFER.ncursesw} == "pkgsrc"
58 USE_BUILTIN.ncursesw=   no
59 .  else
60 USE_BUILTIN.ncursesw=   ${IS_BUILTIN.ncursesw}
61 .    if defined(BUILTIN_PKG.ncursesw) && \
62         !empty(IS_BUILTIN.ncursesw:M[yY][eE][sS])
63 USE_BUILTIN.ncursesw=   yes
64 .      for _dep_ in ${BUILDLINK_API_DEPENDS.ncursesw}
65 .        if !empty(USE_BUILTIN.ncursesw:M[yY][eE][sS])
66 USE_BUILTIN.ncursesw!=                                                  \
67         if ${PKG_ADMIN} pmatch ${_dep_:Q} ${BUILTIN_PKG.ncursesw:Q}; then \
68                 ${ECHO} yes;                                            \
69         else                                                            \
70                 ${ECHO} no;                                             \
71         fi
72 .        endif
73 .      endfor
74 .    endif
75 # XXX
76 # XXX By default, assume that the native curses on NetBSD systems is
77 # XXX good enough to replace ncursesw.  In reality, no version of NetBSD
78 # XXX has a curses library that can completely replace ncursesw; however,
79 # XXX some versions implement enough of ncursesw that some packages are
80 # XXX happy.
81 # XXX
82 .    if empty(H_NB_CURSESW:M__nonexistent__) && \
83         empty(H_NB_CURSESW:M${LOCALBASE}/*)
84 USE_BUILTIN.ncursesw=   yes
85 .    endif
86 .  endif  # PREFER.ncursesw
87 .endif
88 MAKEVARS+=      USE_BUILTIN.ncursesw
89
90 # If USE_NCURSES is defined, then only use the built-in "ncursesw"
91 # if it's *actually* ncursesw.
92 #
93 .if defined(USE_NCURSES) && !empty(IS_BUILTIN.ncursesw:M[nN][oO])
94 USE_BUILTIN.ncursesw=   no
95 .endif
96
97 # Define BUILTIN_LIBNAME.ncursesw to be the base name of the built-in
98 # ncursesw library.
99 #
100 .if !empty(BUILTIN_LIB_FOUND.ncursesw:M[yY][eE][sS])
101 BUILTIN_LIBNAME.ncursesw=       ncursesw
102 .elif !empty(BUILTIN_LIB_FOUND.curses:M[yY][eE][sS])
103 BUILTIN_LIBNAME.ncursesw=       curses
104 .endif
105
106 ###
107 ### The section below only applies if we are not including this file
108 ### solely to determine whether a built-in implementation exists.
109 ###
110 CHECK_BUILTIN.ncursesw?=        no
111 .if !empty(CHECK_BUILTIN.ncursesw:M[nN][oO])
112
113 .  if !empty(USE_BUILTIN.ncursesw:M[yY][eE][sS])
114 BUILDLINK_LIBNAME.ncursesw=     ${BUILTIN_LIBNAME.ncursesw}
115 BUILDLINK_TRANSFORM+=           l:ncursesw:${BUILTIN_LIBNAME.ncursesw}
116 .    if empty(H_NB_CURSESW:M__nonexistent__) && \
117         empty(H_NB_CURSESW:M${LOCALBASE}/*)
118 BUILDLINK_CPPFLAGS.ncursesw+=   -DHAVE_WCHAR=1
119 .    endif
120 .  endif
121
122 # According to the ncurses(3) manual page, applications that want to use
123 # the wide curses definitions need to define _XOPEN_SOURCE_EXTENDED.
124 #
125 .  if !empty(USE_BUILTIN.ncursesw:M[nN][oO]) || \
126       (!empty(USE_BUILTIN.ncursesw:M[yY][eE][sS]) && \
127        !empty(IS_BUILTIN.ncursesw:M[yY][eE][sS]))
128 USE_NCURSES=                    yes
129 BUILDLINK_CPPFLAGS.ncursesw+=   -D_XOPEN_SOURCE_EXTENDED=1
130 .  endif
131 BUILDLINK_TARGETS+=             buildlink-ncursesw-curses-h
132
133 # Packages will expect the following includes to provide declarations
134 # for ncursesw if wide curses are supported:
135 #
136 #       <ncursesw/curses.h>
137 #       <ncurses.h>
138 #       <curses.h>
139 #
140 # We must explicitly force the symlinks to be created as we have to
141 # overwrite any that ncurses/buildlink3.mk might create ahead of us.
142 #
143 .  if !target(buildlink-ncursesw-curses-h)
144 .PHONY: buildlink-ncursesw-curses-h
145 buildlink-ncursesw-curses-h:
146         ${RUN}                                                          \
147         curses_h="ncursesw/ncurses.h curses.h";                         \
148         for f in $$curses_h; do                                         \
149                 src=${BUILDLINK_PREFIX.ncursesw:Q}"/include/$$f";       \
150                 dests="ncursesw/curses.h ncurses.h curses.h";           \
151                 for dest in $$dests; do                                 \
152                         dest=${BUILDLINK_DIR:Q}"/include/$$dest";       \
153                         if ${TEST} -f "$$src"; then                     \
154                                 ${ECHO_BUILDLINK_MSG} "Linking $$dest -> $$f."; \
155                                 ${MKDIR} `${DIRNAME} "$$dest"`;         \
156                                 ${LN} -fs "$$src" "$$dest";             \
157                         fi;                                             \
158                 done;                                                   \
159         done
160 .  endif
161
162 .endif  # CHECK_BUILTIN.ncursesw