1#!/bin/sh
2#
3# sysconfig.sh -- automatically configure portability checks
4#
5# Copyright (c) 2011-2019 David Demelier <markand@malikania.fr>
6#
7# Permission to use, copy, modify, and/or distribute this software for any
8# purpose with or without fee is hereby granted, provided that the above
9# copyright notice and this permission notice appear in all copies.
10#
11# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18#
19
20# Define CC, CFLAGS, LDFLAGS before calling this script.
21
22compile()
23{
24	$CC $CFLAGS -x "c" - -o /dev/null $LDFLAGS > /dev/null 2>&1 && echo $1
25}
26
27# resizeterm(3) (ncurses function)
28cat << EOF | compile "#define HAVE_RESIZETERM"
29#include <curses.h>
30
31int
32main(void)
33{
34	resizeterm(0, 0);
35}
36EOF
37
38# random/srandom.
39cat << EOF | compile "#define HAVE_RANDOM"
40#include <stdlib.h>
41
42int
43main(void)
44{
45	srandom(0);
46	random();
47}
48EOF
49
50# err(3) family functions.
51cat << EOF | compile "#define HAVE_ERR"
52#include <err.h>
53
54int
55main(void)
56{
57	err(1, "");
58	errx(1, "");
59}
60EOF
61
62# getopt(3) function.
63cat << EOF | compile "#define HAVE_GETOPT"
64#include <unistd.h>
65
66int
67main(void)
68{
69	getopt(0, 0, 0);
70}
71EOF
72