File: link_with_gnu_libidn.sh

package info (click to toggle)
swirc 3.5.8-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,044 kB
  • sloc: cpp: 18,690; ansic: 18,414; sh: 1,011; python: 254; makefile: 108; javascript: 20
file content (57 lines) | stat: -rw-r--r-- 1,060 bytes parent folder | download
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
# Link with GNU libidn
#
# SPDX-FileCopyrightText: Copyright 2021-2023 Markus Uhlin
# SPDX-License-Identifier: BSD-3-Clause

link_with_gnu_libidn () {
	local _tmpfile _srcfile _out _libs

	printf "creating temp file..."
	_tmpfile=$(mktemp) || { echo "error"; exit 1; }
	echo "ok"

	_srcfile="${_tmpfile}.c"
	_out="${_tmpfile}.out"
	_libs="-lidn"
	cat <<EOF >"$_srcfile"
#include <idn-free.h>
#include <stdio.h>
#include <stringprep.h>

int
main(void)
{
	const char *cp;

	idn_free(NULL);
	if ((cp = stringprep_check_version(NULL)) != NULL)
		puts(cp);
	return 0;
}
EOF

	if [ ! -f "$_srcfile" ]; then
		echo "failed to create $_srcfile"
		exit 1
	fi

	printf "checking for gnu libidn..."

	${CC} ${CFLAGS} -Werror "$_srcfile" -o "$_out" ${LDFLAGS} ${_libs} \
	    >/dev/null 2>&1

	if [ $? -eq 0 ]; then
		echo "yes"
		cat <<EOF >>$MAKE_DEF_FILE
CPPFLAGS += -DHAVE_LIBIDN=1
LDLIBS += ${_libs}
EOF
	else
		echo "no"
	fi

	echo "cleaning..."
	test -f "$_tmpfile" && rm -f "$_tmpfile"
	test -f "$_srcfile" && rm -f "$_srcfile"
	test -f "$_out" && rm -f "$_out"
}