File: config.pkg

package info (click to toggle)
termdebug 2.2+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid, stretch
  • size: 456 kB
  • ctags: 685
  • sloc: ansic: 5,008; sh: 560; makefile: 48; lex: 46
file content (446 lines) | stat: -rw-r--r-- 14,619 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
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
# Copyright (C) 2010,2012-2013 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 pkgconfig_dep verbose_compile"

checkfunction() {
	CHECKFOR="$1"
	CODE="$2"
	shift 2
	{
		while [ $# -ne 0 ]
		do
			if [ "x$1" = "x--" ]
			then
				shift
				break
			fi
			echo "#include $1"
			shift
		done
		cat <<EOF
int main(int argc, char *argv[]) {
	${CODE}
	return 0;
}
EOF
	} > .config.c

	clean .config.o .config
	test_link "${CHECKFOR}" "$@"
}

config() {
	unset CONFIGFLAGS CONFIGLIBS

	# Test for all required functionality

	cat > .config.c <<EOF
#include <stdlib.h>
#include <errno.h>
#include <stdarg.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <termios.h>
#include <fcntl.h>
#include <time.h>
#include <string.h>
#include <signal.h>
#include <ctype.h>
#include <limits.h>
#include <stdint.h>
#include <libgen.h>

int main(int argc, char *argv[]) {
	char *args[2];
	struct timeval tv;
	struct winsize wsz;
	struct timespec ts;
	int fd[2];
	struct sigaction sa;
	sigset_t ss;
	struct termios tios;

	execvp("test", args);
	fcntl(0, F_SETFL, 0);
	fileno(stdin);
	fork();
	getcwd(args[0], 0);
	gettimeofday(&tv, NULL);
	ioctl(0, TIOCGWINSZ, &wsz);
	isatty(0);
	kill(0, SIGTERM);
	localtime((time_t) 0);
	nanosleep(&ts, &ts);
	pipe(fd);
	read(0, args[0], 1);
	write(0, args[0], 1);
	close(0);
	setenv("NAME", "VALUE", 1);
	unsetenv("NAME");
	sigaction(SIGWINCH, &sa, &sa);
	sigemptyset(&ss);
	sigaddset(&ss, SIGCHLD);
	sigprocmask(SIG_UNBLOCK, &ss, NULL);
	sleep(3);
	snprintf(args[0], 1, "foo%d", 1);
	tcgetattr(0, &tios);
	tcsetattr(0, TCSAFLUSH, &tios);
	umask((mode_t) 0077);
	unlink("PATH");
	waitpid(0, fd, WNOHANG | WUNTRACED);
	basename("foo");
}
EOF

	clean .config.o

	test_link "required functions" || {
		check_message_result "Testing required functions seperatly for debugging purposes"

		checkfunction "execvp" 'char *args[2]; execvp("test", args);' "<unistd.h>"
		checkfunction "fcntl" "fcntl(0, F_SETFL, 0);" "<unistd.h>" "<fcntl.h>"
		checkfunction "fileno" "fileno(stdin);" "<stdio.h>"
		checkfunction "fork" "fork();" "<unistd.h>"
		checkfunction "getcwd" 'char *args[2]; getcwd(args[0], 0);' "<unistd.h>"
		checkfunction "gettimeofday" "struct timeval tv; gettimeofday(&tv, NULL);" "<stdlib.h>" "<sys/time.h>"
		checkfunction "ioctl" "struct winsize wsz; ioctl(0, TIOCGWINSZ, &wsz);" "<sys/ioctl.h>"
		checkfunction "isatty" "isatty(0);" "<unistd.h>"
		checkfunction "kill" "kill(0, SIGTERM);" "<sys/types.h>" "<signal.h>"
		checkfunction "localtime" "localtime((time_t) 0);" "<time.h>"
		checkfunction "nanosleep" "struct timespec ts; nanosleep(&ts, &ts);" "<time.h>"
		checkfunction "pipe" "int fd[2]; pipe(fd);" "<unistd.h>"
		checkfunction "read" "char *args[2]; read(0, args[0], 1);" "<unistd.h>"
		checkfunction "write" "char *args[2]; write(0, args[0], 1);" "<unistd.h>"
		checkfunction "close" "close(0);" "<unistd.h>"
		checkfunction "setenv" 'setenv("NAME", "VALUE", 1);' "<stdlib.h>"
		checkfunction "unsetenv" 'unsetenv("NAME");' "<stdlib.h>"
		checkfunction "sigaction" "struct sigaction sa; sigaction(SIGWINCH, &sa, &sa);" "<signal.h>"
		checkfunction "sigemptyset" "sigset_t ss; sigemptyset(&ss);" "<signal.h>"
		checkfunction "sigaddset" "sigset_t ss; sigaddset(&ss, SIGCHLD);" "<signal.h>"
		checkfunction "sigprocmask" "sigset_t ss; sigprocmask(SIG_UNBLOCK, &ss, NULL);" "<stdlib.h>" "<signal.h>"
		checkfunction "sleep" "sleep(3);" "<unistd.h>"
		checkfunction "snprintf" 'char *args[2]; snprintf(args[0], 1, "foo%d", 1);' "<stdio.h>"
		checkfunction "tcgetattr" "struct termios tios; tcgetattr(0, &tios);" "<termios.h>" "<unistd.h>"
		checkfunction "tcsetattr" "struct termios tios; tcsetattr(0, TCSAFLUSH, &tios);" "<termios.h>" "<unistd.h>"
		checkfunction "umask" "umask((mode_t) 0077);" "<sys/types.h>" "<sys/stat.h>"
		checkfunction "unlink" 'unlink("PATH");' "<unistd.h>"
		checkfunction "waitpid" "int fd[2]; waitpid(0, fd, WNOHANG | WUNTRACED);" "<sys/types.h>" "<sys/wait.h>"
		checkfunction "basename" 'basename("foo");' "<libgen.h>"

		check_message_result "!! A required function is not available."
		exit 1
	}

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

	if checkfunction "poll" "struct pollfd fds[1]; fds[0].events = POLLIN; poll(fds, 1, 1);" "<poll.h>"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_POLL"
	else
		if checkfunction "select in sys/select.h" "fd_set readfds; struct timeval timeout; select(&readfds, NULL, NULL, NULL, &timeout);" "<stdlib.h>" "<sys/select.h>"
		then
			CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_SYS_SELECT_H"
		elif not checkfunction "select in old header files" "fd_set readfds; struct timeval timeout; select(&readfds, NULL, NULL, NULL, &timeout);" "<stdlib.h>" "<sys/time.h>" "<sys/types.h>" "<unistd.h>"
		then
			check_message_result "!! Could not find select"
			exit 1
		fi
	fi

	unset NEED_LIBUTIL
	if checkfunction "openpty in pty.h" "int a; struct winsize wsz; openpty(&a, &a, NULL, NULL, &wsz);" "<stdlib.h>" "<pty.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_OPENPTY"
		NEED_LIBUTIL=1
	elif checkfunction "openpty in util.h" "int a; struct winsize wsz; openpty(&a, &a, NULL, NULL, &wsz);" "<stdlib.h>" "<sys/types.h>" "<sys/ioctl.h>" "<termios.h>" "<util.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_OPENPTY -DOPENPTY_IN_UTIL_H"
		NEED_LIBUTIL=1
	elif checkfunction "openpty in libutil.h" "int a; struct winsize wsz; openpty(&a, &a, NULL, NULL, &wsz);" "<stdlib.h>" "<sys/types.h>" "<sys/ioctl.h>" "<termios.h>" "<libutil.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_OPENPTY -DOPENPTY_IN_LIBUTIL_H"
		NEED_LIBUTIL=1
	else
		cat > .config.c <<EOF
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char *argv[]) {
	grantpt(0);
	unlockpt(0);
	ptsname(0);
	open("foo", O_RDWR | O_NOCTTY);
}
EOF
		clean .config.o
		test_link "required functions for openpty work-around" || {
			check_message_result "Testing required functions seperatly for debugging purposes"

			checkfunction "grantpt" "grantpt(0);" "<stdlib.h>"
			checkfunction "unlockpt" "unlockpt(0);" "<stdlib.h>"
			checkfunction "ptsname" "ptsname(0);" "<stdlib.h>"
			checkfunction "open" 'open("foo", O_RDWR | O_NOCTTY);' "<unistd.h>" "<fcntl.h>"

			check_message_result "!! Did not find any method to open a new pseudo terminal."
			exit 1
		}

		if checkfunction "posix_openpt" "posix_openpt(O_RDWR | O_NOCTTY);" "<stdlib.h>" "<fcntl.h>"
		then
			CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_POSIX_OPENPT"
		else
			check_message "Checking for /dev/ptmx... "
			if not [ -c "/dev/ptmx" ]
			then
				check_message_result "no"
				check_message_result "!! Did not find a method to open a new pseudo terminal."
				exit 1
			fi
			check_message_result "yes"
		fi

	fi

	if checkfunction "login_tty in utmp.h" "login_tty(0);" "<utmp.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_LOGIN_TTY"
		NEED_LIBUTIL=1
	elif checkfunction "login_tty in util.h" "login_tty(0);" "<termios.h>" "<util.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_LOGIN_TTY -DLOGIN_TTY_IN_UTIL_H"
		NEED_LIBUTIL=1
	elif checkfunction "login_tty in libutil.h" "login_tty(0);" "<sys/types.h>" "<sys/ioctl.h>" "<termios.h>" "<libutil.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_LOGIN_TTY -DLOGIN_TTY_IN_LIBUTIL_H"
		NEED_LIBUTIL=1
	else
		cat > .config.c <<EOF
#include <unistd.h>

int main(int argc, char *argv[]) {
	dup2(0, 1);
	setsid();
}
EOF
		clean .config.o
		test_link "required functions for login_tty work-around" || {
			check_message_result "Testing required functions seperatly for debugging purposes"

			checkfunction "dup2" "dup2(0, 1);" "<unistd.h>"
			checkfunction "setsid" "unlockpt(0);" "<stdlib.h>"

			check_message_result "!! Did not find a method to open a new pseudo terminal."
			exit 1
		}

	fi

	if checkfunction "forkpty in pty.h" "int a; struct winsize wsz; forkpty(&a, NULL, NULL, &wsz);" "<stdlib.h>" "<pty.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_FORKPTY"
		NEED_LIBUTIL=1
	elif checkfunction "forkpty in util.h" "int a; struct winsize wsz; forkpty(&a, NULL, NULL, &wsz);" "<stdlib.h>" "<sys/types.h>" "<sys/ioctl.h>" "<termios.h>" "<util.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_FORKPTY -DFORKPTY_IN_UTIL_H"
		NEED_LIBUTIL=1
	elif checkfunction "forkpty in libutil.h" "int a; struct winsize wsz; forkpty(&a, NULL, NULL, &wsz);" "<stdlib.h>" "<sys/types.h>" "<sys/ioctl.h>" "<termios.h>" "<libutil.h>" -- "TESTLIBS=-lutil"
	then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_FORKPTY -DFORKPTY_IN_LIBUTIL_H"
		NEED_LIBUTIL=1
	fi
	[ "x${NEED_LIBUTIL}" = "x1" ] && CONFIGLIBS="${CONFIGLIBS} -lutil"

	unset CURSES_FOUND CURSES_LIBS CURSES_FLAGS
	cat > .config.c <<EOF
#include <stdlib.h>
#include <curses.h>
#include <term.h>

int main(int argc, char *argv[]) {
	setupterm(NULL, 1, NULL);
	putp(tigetstr("smacs"));
	return 0;
}
EOF
	clean .config.o
	if pkgconfig tinfo CURSES test_link ; then
		CURSES_FOUND=1
	elif pkgconfig ncurses CURSES test_link ; then
		CURSES_FOUND=1
	elif test_compile "curses header file" ; then
		if test_link "terminfo access functions in -ltinfo" "TESTLIBS=-ltinfo" ; then
			CURSES_LIBS="-ltinfo"
			CURSES_FOUND=1
		elif test_link "curses library in -lcurses" "TESTLIBS=-lcurses" ; then
			CURSES_LIBS="-lcurses"
			CURSES_FOUND=1
		else
			if test_link "ncurses library in -lncurses" "TESTLIBS=-lncurses" ; then
				CURSES_LIBS="-lncurses"
				CURSES_FOUND=1
			fi
		fi
	fi


	if [ "${CURSES_FOUND}" = 1 ] ; then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_CURSES ${CURSES_FLAGS}"
		CONFIGLIBS="${CONFIGLIBS} ${CURSES_LIBS}"
		OPTOBJECTS="${OPTOBJECTS} src/curses_handling.o"
		KEEPGOING=1
	else
		check_message_result "!! Warning: compiling without curses. This means visual compare will not be available. Install the curses development package if you wish to compile with curses."
		KEEPGOING=0
	fi

	if [ $KEEPGOING = 1 ] ; then
		clean_c
		cat > .config.c <<EOF
#include <unictype.h>
#include <uniwidth.h>

int main(int argc, char *argv[]) {
	int32_t c;
	char nul;
	uc_is_general_category_withtable(c, UC_CATEGORY_MASK_Cs);
	uc_width(c, &nul);
	return 0;
}
EOF
		if test_link "libunistring" TESTLIBS="-lunistring" ; then
			CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_UNISTRING"
			CONFIGLIBS="${CONFIGLIBS} -lunistring"
			OPTOBJECTS="${OPTOBJECTS} src/window.o src/write_stringlist.o"
		else
			check_message_result "!! Warning: compiling without libunistring. This means visual compare will not be available."
			KEEPGOING=0
		fi
	fi

	if [ $KEEPGOING = 1 ] ; then
		clean_c
		cat > .config.c <<EOF
#include <stdlib.h>
#include <cairo.h>

int main(int argc, char *argv[]) {
	cairo_surface_write_to_png(NULL, NULL);
	return 0;
}
EOF
		pkgconfig cairo CAIRO test_link || KEEPGOING=0
	fi
	if [ $KEEPGOING = 1 ] ; then
		clean_c
		cat > .config.c <<EOF
#include <stdlib.h>
#include <pango/pangocairo.h>

int main(int argc, char *argv[]) {
	PangoFontDescription *font_desc = pango_font_description_new();
	return 0;
}
EOF
		pkgconfig pangocairo PANGOCAIRO test_link || KEEPGOING=0
	fi
	if [ $KEEPGOING = 1 ] ; then
		clean_c
		cat > .config.c <<EOF
#include <iconv.h>

int main(int argc, char *argv[]) {
	iconv_t handle = iconv_open("UTF-8", "ISO-8859-1");
	return 0;
}
EOF
		if test_link "iconv" ; then
			ICONVLIBS=
		elif test_link "iconv in -liconv" TESTLIBS="-liconv" ; then
			ICONVLIBS=-liconv
		else
			KEEPGOING=0
		fi
	fi

	if [ $KEEPGOING = 1 ] ; then
		CONFIGFLAGS="${CONFIGFLAGS} -DHAVE_CAIRO ${CAIRO_FLAGS} ${PANGOCAIRO_FLAGS}"
		CONFIGLIBS="${CONFIGLIBS} -DHAVE_CAIRO ${CAIRO_LIBS} ${PANGOCAIRO_LIBS} -lunistring ${ICONVLIBS}"
		OPTOBJECTS="${OPTOBJECTS} src/write_image.o"
	else
		check_message_result "!! Warning: compiling without cairo. This means that no images can be generated from tdreplay and tdcompare."
	fi

	if [ $KEEPGOING = 1 ] ; then
		clean_c
		unset PTHREADFLAGS PTHREADLIBS
		PTHREAD_NOT_FOUND=0
		cat > .config.c <<EOF
#include <stdlib.h>
#include <pthread.h>
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
pthread_t thread;

void *thread_func(void *arg) {
	(void) arg;
	return NULL;
}

int main(int argc, char *argv[]) {
	void *result;
	pthread_mutex_lock(&mutex);
	pthread_mutex_unlock(&mutex);
	pthread_cond_signal(&cond);
	pthread_cond_wait(&cond, &mutex);
	pthread_create(&thread, NULL, thread_func, NULL);
	pthread_join(thread, &result);
	return 0;
}
EOF
		if not test_compile "pthreads" ; then
			PTHREAD_NOT_FOUND=1
			check_message_result "!! Can not find flags to compile with pthreads. Image writing will be done on main thread. See config.log for compile details."
		else
			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
				PTHREAD_NOT_FOUND=1
				check_message_result "!! Can not find flags to link with pthreads. tdreplay will not provide -P/--picture-series. See config.log for compile details."
			fi
		fi
		if [ "$PTHREAD_NOT_FOUND" = 0 ] ; then
			CONFIGFLAGS="${CONFIGFLAGS} ${PTHREADFLAGS}"
			CONFIGLIBS="${CONFIGLIBS} ${PTHREADLIBS}"
			OPTOBJECTS="${OPTOBJECTS} src/picture_queue.o"
		fi
	fi

	create_makefile "CONFIGFLAGS=${CONFIGFLAGS}" "CONFIGLIBS=${CONFIGLIBS}" "OPTOBJECTS=${OPTOBJECTS}"
}