File: config.pkg

package info (click to toggle)
libtranscript 0.3.3-1
  • links: PTS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 18,172 kB
  • sloc: ansic: 222,898; cpp: 4,309; sh: 1,016; xml: 173; makefile: 70; lex: 44
file content (233 lines) | stat: -rw-r--r-- 6,245 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
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
# Copyright (C) 2011-2012 G.P. Halkes
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

EXTENSIONS="c libtool cxx pkgconfig verbose_compile gettext lfs"
MAKEFILES="Makefile mk/libtranscript mk/linkltc mk/ucm2ltc"

SWITCHES="-ucm2ltc"
DEFAULT_LINGUAS=nl
LTSHARED=1
INSTALLDIRS="bindir libdir docdir mandir includedir"

USERHELP=print_help
PRECHECKFUNC=precheck

print_help() {
	cat <<EOF
  --with-ucm2ltc     Build converter specification compiler (ucm2ltc)
                           Requires a working C++ compiler
EOF
}

precheck() {
	if [ "no" = "${with_ucm2ltc}" ] ; then
		EXTENSIONS="`echo \"${EXTENSIONS}\" | sed 's/[^ ]*cxx//g'`"
	fi
}

checkfunction() {
	clean_c

	CHECKFOR="$1"
	CODE="$2"
	shift 2
	{
		for INCLUDE
		do
			echo "#include ${INCLUDE}"
		done
		cat <<EOF
int main(int argc, char *argv[]) {
	${CODE}
	return 0;
}
EOF
	} > .config.c

	test_link "${CHECKFOR}"
}

config() {
	unset CONFIGFLAGS
	# Test for all required functionality

	clean_c
	cat > .config.c <<EOF
#include <sys/types.h>
#include <stdint.h>
#include <dirent.h>

int main(int argc, char *argv[]) {
	DIR *dir;
	struct dirent *entry;
	uint16_t foo;

	dir = opendir(".");
	entry = readdir(dir);
	puts(entry->d_name[0]);
	closedir(dir);
	return 0;
}
EOF

	test_link "opendir/readdir/closedir/dirent.h/stdint.h" || error "!! Some required functionality is not available. See config.log for details."

	clean_c
	cat > .config.c <<EOF
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int main(int argc, char *argv[]) {
	struct stat statbuf;
	symlink("old", "new");
	unlink("name");
	lstat("name", &statbuf);
	S_ISLNK(statbuf.st_mode);
	return 0;
}
EOF

	test_link "symlink/unlink/lstat" || error "!! Some required functionality is not available. See config.log for details."

	clean_c
	unset PTHREADFLAGS PTHREADLIBS
	cat > .config.c <<EOF
#include <stdlib.h>
#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

int main(int argc, char *argv[]) {
	pthread_mutex_lock(&mutex);
	pthread_mutex_unlock(&mutex);
	return 0;
}
EOF
	test_compile "pthreads" || error "!! Pthreads are required to compile libtranscript. See config.log for compile details."
	test_compile "-pthread flag" && PTHREADFLAGS=-pthread
	# Libtool sometimes adds -nostdlib, which then requires that -lpthread is specified
	# separately. Therefore, we first test for -pthread -lpthread, then for
	# -pthread, then -lpthread and if all else fails without anything
	if [ -n "${PTHREADFLAGS}" ] && test_link "pthreads in ${PTHREADFLAGS} -lpthread" "TESTLIBS=${PTHREADFLAGS} -lpthread" ; then
		PTHREADLIBS="${PTHREADFLAGS} -lpthread"
	elif [ -n "${PTHREADFLAGS}" ] && test_link "pthreads in ${PTHREADFLAGS}" "TESTLIBS=${PTHREADFLAGS}" ; then
		PTHREADLIBS="${PTHREADFLAGS}"
	elif test_link "pthreads in -lpthread" TESTLIBS=-lpthread ; then
		PTHREADLIBS=-lpthread
	elif test_link "pthreads in standard library" "TESTLIBS=" ; then
		:
	else
		error "!! Can not find required linker flags for pthreads. Pthreads are required to compile libtranscript. See config.log for compile details."
	fi


	unset HAS_DYNAMIC DL_FLAGS DL_LIBS
	clean_c
	cat > .config.c <<EOF
#include <dlfcn.h>

int main(int argc, char *argv[]) {
	void *handle = dlopen("name", RTLD_LOCAL);
	dlsym(handle, "func");
	dlclose(handle);
	dlerror();
	return 0;
}
EOF
	if test_compile "dlopen/dlsym/dlclose/dlerror in dlfcn.h" ; then
		if test_link "dlopen/dlsym/dlclose/dlerror in standard library" ; then
			HAS_DYNAMIC=y
			DL_FLAGS=-DHAS_DLFCN
		elif test_link "dlopen/dlsym/dlclose/dlerror in -ldl" TESTLIBS=-ldl ; then
			HAS_DYNAMIC=y
			DL_FLAGS=-DHAS_DLFCN
			DL_LIBS=-ldl
		fi
	fi

	if [ -z "$HAS_DYNAMIC" ] ; then
		clean_c
		cat > .config.c <<EOF
#include <ltdl.h>

int main(int argc, char *argv[]) {
	lt_dlhandle handle;
	handle = lt_dlopen("name");
	lt_dlsym(handle, "sym_name");
	lt_dlclose(handle);
	lt_dlinit();
	lt_dlexit();
	lt_dlerror();
	return 0;
}
EOF
		if test_link "libltdl" "TESTLIBS=-lltdl" ; then
			HAS_DYNAMIC=y
			DL_LIBS=-ltdl
		fi
	fi

	[ -z "$HAS_DYNAMIC" ] && error "!! Can not find dlfcn functions or libltdl. Either dlfcn functions or libltdl are/is required to compile libtranscript."
	CONFIGFLAGS="${CONFIGFLAGS} ${DL_FLAGS}"
	CONFIGLIBS="${CONFIGLIBS} ${DL_LIBS}"

	HAS_SETLOCALE=unknown
	if checkfunction "nl_langinfo" "nl_langinfo(CODESET);" "<langinfo.h>" ; then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAS_NL_LANGINFO"
	elif checkfunction "setlocale" "setlocale(LC_CTYPE, NULL);" "<locale.h>" ; then
		HAS_SETLOCALE=yes
	else
		error "!! A required function is not available."
	fi

	checkfunction "strdup" "strdup(\"foo\");" "<string.h>" && CONFIGFLAGS="${CONFIGFLAGS} -DHAS_STRDUP"

	clean_c
	cat > .config.c <<EOF
static inline int foo() { return 4; }
int main(int argc, char *argv[]) {
	return foo;
}
EOF
	test_compile "inline keyword" && CONFIGFLAGS="${CONFIGFLAGS} -DHAS_INLINE"

	if [ yes = "${with_ucm2ltc}" ] ; then
		clean_cxx
		cat > .configcxx.cc <<EOF
#include <stdio.h>

int main(int argc, char *argv[]) {
	char test[10];
	snprintf(test, sizeof(test), "foo");
}
EOF
		test_link_cxx "snprintf" || error "!! Function required for ucm2ltc not found. Try configuring without --with-ucm2ltc."
	else
		MAKEFILES="Makefile mk/libtranscript mk/linkltc"
		cat > mk/ucm2ltc <<EOF
all:
clean:
dist-clean:
EOF
	fi

	PKGCONFIG_DESC="Character-set conversion library"
	PKGCONFIG_VERSION="0.3.3"
	PKGCONFIG_URL="http://os.ghalkes.nl/libtranscript.html"
	PKGCONFIG_CFLAGS="-I\${includedir}/transcript"
	PKGCONFIG_LIBS="-ltranscript"
	PKGCONFIG_LIBS_PRIVATE="$CONFIGLIBS $PTHREADLIBS"

	gen_pkgconfig libtranscript
	create_makefile "CONFIGFLAGS=${CONFIGFLAGS}" "CONFIGLIBS=${CONFIGLIBS}" "PTHREADFLAGS=${PTHREADFLAGS}" "PTHREADLIBS=${PTHREADLIBS}"
}