xaizek / pinfo (License: GPLv2 only) (since 2018-12-07)
Console-based info and manual pages reader, which adds interactive navigation to man pages.
<root> / macros / curses.m4 (415eecf4a82bd85a416265d90e1bd64c87f5b00b) (10KiB) (mode 100644) [raw]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469
dnl Curses detection: 
dnl Copyright (c) 2005 by Bas Zoetekouw <bas@debian.org>

dnl  This program is free software; you can redistribute it and/or modify
dnl  it under the terms of version 2 of the GNU General Public License as
dnl  published by the Free Software Foundation.
dnl
dnl  This program is distributed in the hope that it will be useful, but
dnl  WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
dnl  General Public License for more details.
dnl 
dnl  You should have received a copy of the GNU General Public License
dnl  along with this program; if not, write to the Free Software
dnl  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
dnl  
dnl 
dnl  How to use this?
dnl  (-) put a call to AC_CHECK_CURSES in configure.ac (after the call to
dnl      AC_PROG_CC, obviously)
dnl  (-) AC_CHECK_CURSES will look for a curses library (or look at the
dnl  	location the user specified on the ./configure command line) , and
dnl  	checks if it is usable.  If it is found, and is usable, the shell
dnl  	variable $USE_CURSES is set for use in configure.ac, and the
dnl  	autoheader USE_CURSES will be defined.  
dnl  (-) the includes and libraries cc options are put into the
dnl      $CURSES_INCLUDES and $CURSES_LIBS shell variables and the automake 
dnl      variables @CURSES_INCLUDES@ and @CURSES_LIBS@.  Additional flags 
dnl      that are needed are put in $CURSES_FLAGS and @CURSES_FLAGS@



dnl First define the headers for config.h.in:
AH_TEMPLATE([USE_CURSES],[
	Use Ncurses?
])
AH_TEMPLATE([CURSES_WCHAR],[
	Does curses have support for non-iso8859 charsets?
])
AH_TEMPLATE(CURSES_H_NAME, [
	Name of the ncurses.h file that should be included
])
AH_TEMPLATE([CURSES_COLORS],[
	Defined if curses has support for colors
])
AH_TEMPLATE(CURSES_KEY_END,[
	Defined if curses has KEY_END definition
])
AH_TEMPLATE(CURSES_MOUSE,[
	Defined if curses has support for mouse events
])

dnl
dnl  "main" function.  Call this from configure.ac
dnl
AC_DEFUN([AC_CHECK_CURSES],[
	CFLAGS=${CFLAGS--O}

	curses_location=false
	use_curses=true
	AC_ARG_WITH(curses,
		[  --with-curses=dir       Use <dir> as base dir for curses library],
		[
			if test "x$withval" = "xno"
			then
				use_curses=false
			fi
			if test "x$withval" != "xyes"
			then
				curses_location=$withval
			fi
		]
	)

	dnl  search for (n)curses.h
	if test "x$use_curses" = "xtrue"
	then
		AC_SEARCH_CURSES_H()
	fi
		
	dnl  if we found anything, check if it works
	if test "x$found_curses_h" = "xtrue"; then
		AC_CHECK_CURSES_COMPILE()
	else
		curses_usable=false
	fi

	dnl  if it works, check for several features and set variables
	if test "x$curses_usable" = "xtrue"
	then
		USE_CURSES=true

		dnl  use curses
		AC_DEFINE(USE_CURSES)

		dnl  define lib and include dirs
		CURSES_INCLUDES=$curses_includes
		CURSES_LIBS=$curses_libs
		AC_SUBST(CURSES_INCLUDES)
		AC_SUBST(CURSES_LIBS)

		dnl  name of ncurses.h file
		AC_DEFINE_UNQUOTED(CURSES_H_NAME, [<$curses_h>])

		dnl  colors?
		AC_CURSES_CHECK_COLORS()
		if test "x$curses_colors" = "xtrue"
		then
			AC_DEFINE(CURSES_COLORS)
			CURSES_COLORS=true
		else
			CURSES_COLORS=false
		fi

		dnl  mouse?
		AC_CURSES_CHECK_MOUSE()
		if test "x$curses_mouse" = "xtrue"
		then
			AC_DEFINE(CURSES_MOUSE)
			CURSES_MOUSE=true
		else
			CURSES_MOUSE=false
		fi

		dnl  wchar?
		AC_CURSES_CHECK_WIDECHAR()
		if test "x$curses_wchar" = "xfalse"
		then
			CURSES_WCHAR=false
		else
			AC_DEFINE(CURSES_WCHAR)
			CURSES_WCHAR=true
			CURSES_FLAGS=$curses_wchar
			AC_SUBST(CURSES_FLAGS)
		fi

		dnl  end key?
		AC_CURSES_CHECK_ENDKEY()
		if test "x$curses_endkey" = "xtrue"
		then
			AC_DEFINE(CURSES_KEY_END)
			CURSES_KEY_END=true
		else
			CURSES_KEY_END=false
		fi

	fi
		
])


		
dnl
dnl searches for curses in a specific place
dnl Parameters: directory filename curses_LIBS curses_INCLUDES
dnl
AC_DEFUN([AC_SEARCH_CURSES_FILE], [
	if test "x$stop_searching" = "xfalse"
	then
		if test -f $1/$2
		then
			AC_MSG_RESULT([$1/$2])
			curses_h="$2"
			curses_libs="$3"
			curses_includes="$4"
			stop_searching=true
			found_curses_h=true
		fi
	fi
])

dnl
dnl  Search for curses.h in several different places
dnl
AC_DEFUN([AC_SEARCH_CURSES_H], [
	AC_MSG_CHECKING([location of curses.h file])

	stop_searching=false
	found_curses_h=false

	dnl  if a particular location was specified
	if test "x$curses_location" != "xfalse"
	then
		dnl  check this particular location
		AC_SEARCH_CURSES_FILE($curses_location/include, ncursesw/ncurses.h, 
					-L$curses_location/lib -lncursesw, 
					-I$curses_location/include )
		AC_SEARCH_CURSES_FILE($curses_location/include, ncursesw.h, 
					-L$curses_location/lib -lncursesw, 
					-I$curses_location/include )
		AC_SEARCH_CURSES_FILE($curses_location/include, ncurses/ncurses.h, 
					-L$curses_location/lib -lncurses, 
					-I$curses_location/include )
		AC_SEARCH_CURSES_FILE($curses_location/include, ncurses.h, 
					-L$curses_location/lib -lncurses, 
					-I$curses_location/include )
		AC_SEARCH_CURSES_FILE($curses_location/include, curses.h, 
					-L$curses_location/lib -lncurses, 
					-I$curses_location/include )
	
	else
		dnl  check lots of default locations

		dnl  first preference is ncursesw
		AC_SEARCH_CURSES_FILE(/usr/local/include, ncursesw/ncurses.h, 
					-L/usr/local/lib -lncursesw, 
					-I/usr/local/include )
		AC_SEARCH_CURSES_FILE(/usr/local/include/, ncursesw.h, 
					-L/usr/local/lib -lncursesw, 
					-I/usr/local/include )
	
		AC_SEARCH_CURSES_FILE(/usr/include, ncursesw/ncurses.h, 
					-L/usr/lib -lncursesw, 
					-I/usr/include )
		AC_SEARCH_CURSES_FILE(/usr/include/, ncursesw.h, 
					-L/usr/lib -lncursesw, 
					-I/usr/include )
			
		dnl  after that, look for normal ncurses
		AC_SEARCH_CURSES_FILE(/usr/local/include, ncurses.h, 
					-L/usr/local/lib -lncurses, 
					-I/usr/local/include )
		AC_SEARCH_CURSES_FILE(/usr/local/include, ncurses/ncurses.h, 
					-L/usr/local/lib -lncurses, 
					-I/usr/local/include )
	
		AC_SEARCH_CURSES_FILE(/usr/include, ncurses.h, 
					-L/usr/lib -lncurses,
					-I/usr/include )
		AC_SEARCH_CURSES_FILE(/usr/include, ncurses/ncurses.h, 
					-L/usr/lib -lncurses, 
					-I/usr/include )

		dnl  after that, look for curses
		AC_SEARCH_CURSES_FILE(/usr/local/include, curses.h, 
					-L/usr/local/lib -lncurses, 
					-I/usr/local/include )
		AC_SEARCH_CURSES_FILE(/usr/local/include, curses/curses.h, 
					-L/usr/local/lib -lncurses, 
					-I/usr/local/include )
	
		AC_SEARCH_CURSES_FILE(/usr/include, curses.h, 
					-L/usr/lib -lncurses,
					-I/usr/include )
		AC_SEARCH_CURSES_FILE(/usr/include, curses/curses.h, 
					-L/usr/lib -lncurses, 
					-I/usr/include )
	fi

])

dnl
dnl check if the curses header we found, works
dnl
AC_DEFUN([AC_CHECK_CURSES_COMPILE], [

	dnl save CFLAGS and LIBS and set new ones
	CFLAGS_OLD=$CFLAGS
	CFLAGS="$CFLAGS $curses_includes"
	LIBS_OLD=$LIBS
	LIBS="$LIBS $curses_libs"

	dnl do the compile test 
	AC_MSG_CHECKING([if curses is usable])
	AC_LINK_IFELSE([
		AC_LANG_PROGRAM(
			[[
				#include <$curses_h> 
			]], 
			[[
				initscr();
				printw("Hello World !!!");
				refresh();
				getch();
				endwin();
				return 0;
			]]
		)],
		[
			curses_usable=true
			AC_MSG_RESULT([yes])
		],
		[
			curses_usable=false
			AC_MSG_RESULT([no])
		]
	)

	dnl restore variables
	CFLAGS=$CFLAGS_OLD
	LIBS=$LIBS_OLD

])

dnl
dnl  check if this version of curses has support for colors
dnl 
AC_DEFUN([AC_CURSES_CHECK_COLORS], [

	dnl save and change CFLAGS
	CFLAGS_OLD=$CFLAGS
	CFLAGS="$CFLAGS $curses_includes"
	
	dnl  print nice message
	AC_MSG_CHECKING([if ncurses supports colors])

	dnl  we check for definition of COLOR_YELLOW
	AC_EGREP_CPP(
		HAVE_COLOR_YELLOW,
		[
    		#include <$curses_h>
    		#ifdef COLOR_YELLOW
		        HAVE_COLOR_YELLOW
		    #endif
		],
		[
    		curses_colors=true
		    AC_MSG_RESULT(yes)
		],
		[
    		curses_colors=false
		    AC_MSG_RESULT(no)
		]
	)

	dnl  restore CFLAGS
	CFLAGS=$CFLAGS_OLD

])
dnl
dnl  check if this version of curses can handle utf8 and friends
dnl 
AC_DEFUN([AC_CURSES_CHECK_WIDECHAR], [

	dnl save and change CFLAGS
	CFLAGS_OLD=$CFLAGS
	CFLAGS="$CFLAGS $curses_includes"
	
	dnl  print nice message
	AC_MSG_CHECKING([if ncurses supports extended chars])

	dnl  this will contain the define we need
	curses_wchar=false

	dnl  first check with default options
	dnl  we check for existence of the add_wch() function
	AC_COMPILE_IFELSE([
		AC_LANG_PROGRAM(
			[[ #include <$curses_h> ]], 
			[[ char *p = (char *) add_wch; ]]
		)],
		[
			dnl if found, set variables and print result
			curses_wchar=true
			AC_MSG_RESULT([yes])
		],
		[
			dnl if not found, do NOP
			true
		]
	)

	dnl  not found, now try with -D_XOPEN_SOURCE_EXTENDED
	if test "x$curses_wchar" = "xfalse"
	then
		AC_COMPILE_IFELSE([
			AC_LANG_PROGRAM(
				[[ 
					#define _XOPEN_SOURCE_EXTENDED
					#include <$curses_h> 
				]], 
				[[ char *p = (char *) add_wch; ]]
			)],
			[
				dnl if found, set variables and print result
				curses_wchar=-D_XOPEN_SOURCE_EXTENDED
				AC_MSG_RESULT([yes, with $curses_wchar])
			],
			[
				dnl if not found, do NOP
				true
			]
		)
	fi
	
	dnl  restore CFLAGS
	CFLAGS=$CFLAGS_OLD

	dnl  print message if not found
	if test "x$curses_wchar" = "xfalse"
	then
		AC_MSG_RESULT([no]);
	fi
	
])

dnl
dnl  check if this version of curses has an end key definition
dnl 
AC_DEFUN([AC_CURSES_CHECK_ENDKEY], [

	dnl save and change CFLAGS
	CFLAGS_OLD=$CFLAGS
	CFLAGS="$CFLAGS $curses_includes"
	
	dnl  print nice message
	AC_MSG_CHECKING([if ncurses supports the end key])

	dnl  we check for definition of HAVE_KEY_END
	AC_EGREP_CPP(
		HAVE_KEY_END,
		[
    		#include <$curses_h>
    		#ifdef KEY_END
		        HAVE_KEY_END
		    #endif
		],
		[
    		curses_endkey=true
		    AC_MSG_RESULT(yes)
		],
		[
    		curses_endkey=false
		    AC_MSG_RESULT(no)
		]
	)

	dnl  restore CFLAGS
	CFLAGS=$CFLAGS_OLD

])

dnl
dnl  check if this version of curses has support for mouse events
dnl 
AC_DEFUN([AC_CURSES_CHECK_MOUSE], [

	dnl save and change CFLAGS
	CFLAGS_OLD=$CFLAGS
	CFLAGS="$CFLAGS $curses_includes"
	
	dnl  print nice message
	AC_MSG_CHECKING([if ncurses supports mouse events])

	dnl  we check for definition of BUTTON1_CLICKED
	AC_EGREP_CPP(
		HAVE_BUTTON1_CLICKED,
		[
    		#include <$curses_h>
    		#ifdef BUTTON1_CLICKED
		        HAVE_BUTTON1_CLICKED
		    #endif
		],
		[
    		curses_mouse=true
		    AC_MSG_RESULT(yes)
		],
		[
    		curses_mouse=false
		    AC_MSG_RESULT(no)
		]
	)

	dnl  restore CFLAGS
	CFLAGS=$CFLAGS_OLD

])

dnl vim:ts=4:sw=4
Hints

Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"

Clone this repository using HTTP(S):
git clone https://code.reversed.top/user/xaizek/pinfo

Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@code.reversed.top/user/xaizek/pinfo

You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a pull request:
... clone the repository ...
... make some changes and some commits ...
git push origin master