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 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
|
AC_INIT(src/main.c)
AM_CONFIG_HEADER(include/config.h)
AM_INIT_AUTOMAKE(njamd, 0.9.3pre2)
AM_DISABLE_STATIC
AM_MAINTAINER_MODE
AC_CANONICAL_HOST
AC_PROG_CC
AC_ISC_POSIX
AM_PROG_CC_STDC
AC_PROG_INSTALL
AC_PATH_XTRA
dnl AC_PATH_X
AC_DEFINE(_GNU_SOURCE)
dnl FIXME: HACK to get devel automake to work
AC_SUBST(DEP_FILES)
dnl Prefer ncurses over curses
AC_ARG_ENABLE(frontend, [ --disable-frontend Don't build the front end], enable_frontend=no, enable_frontend=yes)
if test "$enable_frontend" = "yes"; then
AC_CHECK_LIB(ncurses, initscr, CURSES_LIB=-lncurses, enable_frontend=no)
fi
AC_CHECK_HEADER(ncurses.h,,AC_CHECK_HEADER(curses.h,,enable_frontend=no))
AM_CONDITIONAL(ENABLE_FE, test "$enable_frontend" = "yes")
if test "$enable_frontend" = "yes"; then
NJAMD_BIN=njamd
fi
AC_SUBST(NJAMD_BIN)
AC_SUBST(CURSES_LIB)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)
dnl if the test for lpthread fails, we're on one of those cooky systems with
dnl two libcs. So we must build two libraries
AM_CONDITIONAL(HAVE_CURSES, test "$build_curses" = "yes")
FPTHREAD=
FPTHREAD_R=
LFPTHREAD_R=
AC_CHECK_HEADER(pthread.h,
AC_DEFINE(HAVE_PTHREAD_H, 1)
have_pthreads="yes"
AC_CHECK_LIB(pthread, pthread_mutex_init,
AC_DEFINE(HAVE_LIBPTHREAD,1)
LFPTHREAD=-pthread
LPTHREAD=-lpthread
FPTHREAD="-pthread -D_THREAD_SAFE",
LFPTHREAD_R=-pthread
FPTHREAD_R="-pthread -D_THREAD_SAFE"
NJAMD_R=libnjamd_r.la
lame_pthread="yes"),
have_pthreads="no")
dnl we have no working GTK gui. Just take it out.
dnl AM_PATH_GTK(1.2.0, AC_DEFINE(HAVE_GTK, 1) build_gtk="yes", build_gtk="no")
AC_SUBST(GTK_CFLAGS)
build_gtk=no
AM_CONDITIONAL(HAVE_GTK, test "$build_gtk" = "yes")
CFLAGS="$CFLAGS -Wall -I`pwd`/include"
dnl CFLAGS="-O3 -g -Wall -I`pwd`/include"
AC_SUBST(CFLAGS)
AC_SUBST(LPTHREAD)
AC_SUBST(X_CFLAGS)
AC_SUBST(X_LIBS)
AC_SUBST(X_PRE_LIBS)
AC_SUBST(X_EXTRA_LIBS)
dnl *** from autoscan ***
dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(ncurses.h curses.h fcntl.h limits.h sys/time.h unistd.h execinfo.h)
AC_CHECK_HEADER(sys/user.h, AC_DEFINE(HAVE_SYS_USER_H, 1) [SYS_USER_H="#include <sys/user.h>"])
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_HEADER_TIME
dnl Checks for library functions.
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
dnl AC_FUNC_VPRINTF
AC_CHECK_FUNCS(memalign posix_memalign vsnprintf snprintf select strdup strerror strtol backtrace_symbols_fd)
AC_CHECK_FUNC(mmap, ,AC_MSG_ERROR([NJAMD requires mmap to work. Sorry BeOS people. Less sorry to you other people..]))
dnl *** end autoscan ***
dnl *** Hand written tests ***
dnl test bitwidth
AC_MSG_CHECKING([processor bitwidth])
AC_TRY_RUN(
int main()
{
if(sizeof(void *) == 4)
return 0;
else
return 1;
},
dnl if success, 32 bits
AC_MSG_RESULT(32)
AC_DEFINE(HAVE_32_BITS, 1),
AC_MSG_RESULT(64)
AC_DEFINE(HAVE_64_BITS, 1),
dnl cross compile: guess 32
AC_MSG_RESULT(Cross compile: guessed 32)
AC_DEFINE(HAVE_32_BITS, 1)
)
AC_MSG_CHECKING([If mmap can map non page_size multiples])
AC_TRY_RUN([
#include <stdio.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main()
{
int i;
int anon_fd = -1;
#ifndef MAP_ANON
#define MAP_ANON 0
anon_fd = open("/dev/zero", O_RDWR);
#endif
for(i=200; i<2000; i++)
{
if((mmap(NULL, i, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, anon_fd, 0))
== (void *)-1)
return 1;
}
return 0;
}],
AC_MSG_RESULT([yes]),
AC_MSG_ERROR([mmap cannot handle non-page size multiples]),
AC_MSG_RESULT([Cross compile... assuming yes]))
AC_MSG_CHECKING([If we can trust gcc with bitfields])
AC_TRY_RUN([
struct bitfields
{
int x : 4;
int y : sizeof(long)*8 - 4;
};
int main()
{
struct bitfields t1;
long t2;
t2 = 3;
t1.x = 1;
t1.y = 3;
t1 = *(struct bitfields *)&t2;
t2 = *(long *)&t1;
if(sizeof(long) != sizeof(struct bitfields))
{
return 1;
}
return 0;
}],
AC_MSG_RESULT([yes]),
AC_MSG_ERROR([GCC is not being bitfield-friendly. Issue a bug report with
./bug_njamd]),
AC_MSG_RESULT([Cross compile... assuming yes])
)
dnl test alignment
dnl Plans: Test double with no alignment. if it fails, try double with int
dnl alignment. if it fails try double with void * alignment.
dnl If THAT fails then we have double alignment required..
dnl We don't always just use alignof because it doesn't give the REQUIRED
dnl alignment, only the optimal
AC_MSG_CHECKING([default alignment requirement])
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* Last 4 bits end in 1 */
*(double *)(buf | 0xf) = 3.3;
return 0;
}],
dnl sucess! No alignment needed
AC_DEFINE(NJ_ALIGNMENT, 1) AC_MSG_RESULT([none needed]),
dnl else try the next step up
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 2 bits end in 0 for sizeof(int) = 4 */
*(double *)((buf | 0xf) & ~(sizeof(int)-1)) = 3.3;
return 0;
}],
dnl sucess! Use int alignment
AC_DEFINE(NJ_ALIGNMENT, sizeof(int)) AC_MSG_RESULT([sizeof(int)]),
dnl else try void *
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 3 bits end in 0 for sizeof(void *) = 8 */
*(double *)((buf | 0xf) & ~(sizeof(void *)-1)) = 3.3;
return 0;
}],
dnl sucess! use void *
AC_DEFINE(NJ_ALIGNMENT, sizeof(void *)) AC_MSG_RESULT([sizeof(void *)]),
dnl else try double
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 3 bits end in 0 for sizeof(double) = 8 */
*(double *)((buf | 0xf) & ~(sizeof(double)-1)) = 3.3;
return 0;
}],
dnl sucess! use double alignment
AC_DEFINE(NJ_ALIGNMENT, sizeof(double)) AC_MSG_RESULT([sizeof(double)]),
dnl failure?? I suck.
AC_MSG_ERROR([Mike Perry is a moron. Mail mikepery@fscked.org and tell him his alignment check does not work.]),
dnl cross compile
AC_DEFINE(NJ_ALIGNMENT, __alignof__(double)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_ALIGNMENT, __alignof__(double)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_ALIGNMENT, __alignof__(double)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_ALIGNMENT, __alignof__(double)) AC_MSG_RESULT([using gcc])
)
dnl test alignment
dnl Plans: Test int with no alignment. if it fails, try int with int
dnl alignment. We don't always just use alignof because it doesn't give the
dnl REQUIRED alignment, only the optimal
AC_MSG_CHECKING([int alignment requirement])
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* Last 4 bits end in 1 */
*(int *)(buf | 0xf) = 0xdeadbeef;
return 0;
}],
dnl sucess! No alignment needed
AC_DEFINE(NJ_INT_ALIGNMENT, 1) AC_MSG_RESULT([none needed]),
dnl int
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 2 bits end in 0 for sizeof(int) = 4 */
*(int *)((buf | 0xf) & ~(sizeof(int)-1)) = 0xdeadbeef;
return 0;
}],
dnl sucess! Use int alignment
AC_DEFINE(NJ_INT_ALIGNMENT, sizeof(int)) AC_MSG_RESULT([sizeof(int)]),
dnl failure?? I suck.
AC_MSG_ERROR([Mike Perry is a moron. Mail mikepery@fscked.org and tell him his alignment check does not work.]),
dnl cross compile
AC_DEFINE(NJ_INT_ALIGNMENT, __alignof__(int)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_INT_ALIGNMENT, __alignof__(int)) AC_MSG_RESULT([using gcc])
)
dnl Plans: Test pointer with no alignment. if it fails, try pointer with int
dnl alignment, if that fails, try void * alignment.
dnl We don't always just use alignof because it doesn't give the REQUIRED
dnl alignment, only the optimal
AC_MSG_CHECKING([ptr alignment requirement])
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* Last 4 bits end in 1 */
buf = (buf | 0xf);
*(char **)buf = buf;
*((*(char **)buf)+47) = 'a';
return 0;
}],
dnl sucess! No alignment needed
AC_DEFINE(NJ_PTR_ALIGNMENT, 1) AC_MSG_RESULT([none needed]),
dnl int
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 2 bits end in 0 for sizeof(int) = 4 */
buf = ((buf | 0xf) & ~(sizeof(int)-1));
*(char **)buf = buf;
*((*(char **)buf)+47) = 'a';
return 0;
}],
dnl sucess! Use int alignment
AC_DEFINE(NJ_PTR_ALIGNMENT, sizeof(int)) AC_MSG_RESULT([sizeof(int)]),
dnl try void *
AC_TRY_RUN(
[#include <stdlib.h>
int main()
{
unsigned long buf = malloc(128);
/* last 2 bits end in 0 for sizeof(void *) = 4 */
buf = ((buf | 0xf) & ~(sizeof(void *)-1));
*(char **)buf = buf;
*((*(char **)buf)+47) = 'a';
return 0;
}],
dnl sucess! Use void *
AC_DEFINE(NJ_PTR_ALIGNMENT, sizeof(void *)) AC_MSG_RESULT([sizeof(void *)]),
dnl failure?? I suck.
AC_MSG_ERROR([Mike Perry is a moron. Mail mikepery@fscked.org and tell him his alignment check does not work.]),
dnl cross compile
AC_DEFINE(NJ_PTR_ALIGNMENT, __alignof__(void *)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_PTR_ALIGNMENT, __alignof__(void *)) AC_MSG_RESULT([using gcc])
),
dnl cross compile
AC_DEFINE(NJ_PTR_ALIGNMENT, __alignof__(void *)) AC_MSG_RESULT([using gcc])
)
dnl check if PAGE_SIZE, PAGE_MASK, and PAGE_SHIFT are defined AND constants
AC_MSG_CHECKING([for usable PAGE_SIZE])
AC_TRY_COMPILE(
[#include <unistd.h>
#include <sys/param.h>
#include <limits.h>
#include <sys/types.h>
${SYS_USER_H}
#ifndef NJ_PAGE_SIZE
# if defined(PAGE_SIZE)
# define NJ_PAGE_SIZE PAGE_SIZE
# elif defined(EXEC_PAGESIZE)
# define NJ_PAGE_SIZE EXEC_PAGESIZE
# elif defined(NBPG)
# ifndef CLSIZE
# define CLSIZE 1
# endif
# define NJ_PAGE_SIZE (NBPG*CLSIZE)
# elif defined(NBPC)
# define NJ_PAGE_SIZE (NBPC)
# elif defined(PAGESIZE)
# define NJ_PAGE_SIZE PAGESIZE
# endif
#endif
char tmp[NJ_PAGE_SIZE];
],
[
int fcn(void)
{
return 0;
}],
AC_DEFINE(HAVE_PAGE_SIZE,1)
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
)
AC_MSG_CHECKING([for usable PAGE_SHIFT])
AC_TRY_COMPILE(
[#include <unistd.h>
#include <sys/param.h> /* stupid openbsd */
#include <limits.h>
#include <sys/types.h>
${SYS_USER_H}
char tmp[PAGE_SHIFT];
],
[
int fcn(void)
{
return 0;
}],
AC_DEFINE(HAVE_PAGE_SHIFT,1)
AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
)
AC_MSG_CHECKING([for usable PAGE_MASK])
AC_TRY_COMPILE(
[#include <unistd.h>
#include <sys/param.h> /* stupid openbsd */
#include <limits.h>
#include <sys/types.h>
${SYS_USER_H}
char tmp[(PAGE_MASK & 0) + 1];
],
[
int fcn(void)
{
return 0;
}],
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_PAGE_MASK, 1)
AC_MSG_CHECKING([if PAGE_MASK is unsanely negated ala FreeBSD])
AC_TRY_RUN(
[#include <unistd.h>
#include <sys/param.h> /* stupid openbsd */
#include <limits.h>
#include <sys/types.h>
${SYS_USER_H}
int main(void)
{
if(PAGE_MASK & 0xfff)
return 1;
else
return 0;
}],
AC_MSG_RESULT([no]),
AC_DEFINE(NEGATE_PAGE_MASK, 1)
AC_MSG_RESULT([it is.. your kernel is lame]),
AC_MSG_RESULT([Cross compiling: assuming sane OS])
),
AC_MSG_RESULT(no)
)
AC_MSG_CHECKING([if va_lists are pass by value])
AC_TRY_RUN(
[#include <stdio.h>
#include <stdarg.h>
int test2(int a, va_list va)
{
int b;
b = va_arg(va, int);
if(b != 2)
return 1;
b = va_arg(va, int);
va_end(va);
return 0;
}
int test3(int a, va_list va)
{
int b;
b = va_arg(va, int);
if(b != 3)
return 1;
return 0;
}
int test(int a, ...)
{
va_list va;
int b;
va_start(va, a);
if(test2(a, va) != 0)
return 1;
b = va_arg(va, int);
if(b != 2)
return 1;
va_end(va);
va_start(va, a);
if(test2(a, va) != 0)
return 1;
b = va_arg(va, int);
if(test3(a, va) != 0)
return 1;
b = va_arg(va, int);
if(b != 3)
return 1;
va_end(va);
return 0;
}
main(int argc, char **argv)
{
return test(1, 2, 3, 4);
}],
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no])
AC_DEFINE(NEED_VA_REWIND, 1),
AC_MSG_RESULT([Cross compiling.. guessing no]) AC_DEFINE(NEED_VA_REWIND, 1)
)
dnl FIXME: Hack.. This SHOUD pick the most recent version of libc on the box..
dnl Eventually we need to figure out how to make AC_CHECK_LIB return the path
dnl to that lib if cross compilation is not on.
dnl FIXME: sometimes libc is only in /usr/lib (BSD)
if test "$cross_compiling" = "yes"; then
AC_DEFINE(LIBC_SO_PATH, ["/lib/libc.so"])
AC_DEFINE(LIBC_R_PATH, ["/usr/lib/libc_r.so"])
AC_DEFINE(LIBPTHREAD_PATH, ["/usr/lib/libpthread.so"])
LIBC_PATH="/lib/libc.so"
AC_MSG_RESULT([Guessing /lib/libc.so])
AC_MSG_WARN([This program must know the exact location of libc.so. Cross compilation may break this])
else
AC_MSG_CHECKING([for location of current libc])
file_guess="`ls /lib/libc.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
file_guess="`ls /usr/lib/libc.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
AC_MSG_RESULT([Not Found])
AC_MSG_WARN([Can't find valid libc! This will SERIOUSLY limit your features. Please mail mikepery@fscked.org with the location of your libc])
LIBC_PATH="Not Found"
fi
fi
LIBC_PATH=${file_guess}
AC_DEFINE_UNQUOTED(LIBC_SO_PATH, ["${LIBC_PATH}"])
AC_MSG_RESULT([${file_guess}])
if test "$have_pthreads" = "yes"; then
AC_MSG_CHECKING([for location of current thread library])
if test "$lame_pthread" = "yes"; then
file_guess="`ls /lib/libc_r.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
file_guess="`ls /usr/lib/libc_r.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
AC_MSG_RESULT([Not found])
AC_MSG_WARN([Can't find valid libpthread!])
FPTHREAD_R=""
NJAMD_R=
lame_pthread="no"
fi
fi
else
file_guess="`ls /lib/libpthread.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
file_guess="`ls /usr/lib/libpthread.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
file_guess="`ls /usr/local/lib/libpthread.*s* 2> /dev/null | tail -1`"
if test -z "${file_guess}"; then
AC_MSG_RESULT([Not found])
AC_MSG_WARN([Can't find valid libpthread!])
FPTHREAD_R=""
NJAMD_R=
lame_pthread="no"
fi
fi
fi
fi
AC_MSG_RESULT([${file_guess}])
AC_DEFINE_UNQUOTED(LIBC_R_PATH, ["${file_guess}"])
AC_DEFINE_UNQUOTED(LIBPTHREAD_PATH, ["${file_guess}"])
fi
fi
AM_CONDITIONAL(LAME_PTHREAD, test "$lame_pthread" = "yes")
AC_SUBST(NJAMD_R)
AC_SUBST(FPTHREAD)
AC_SUBST(FPTHREAD_R)
AC_SUBST(LFPTHREAD)
AC_SUBST(LFPTHREAD_R)
AC_SUBST(LIBC_PATH)
dnl if no libc, no dlopen.
if test "$LIBC_PATH" != "Not Found"; then
dnl Test for working dlopen. FreeBSD's dlopen is broken for ELF
AC_CHECK_LIB(dl, dlopen, LIB_DL=-ldl)
AC_SUBST(LIB_DL)
AC_MSG_CHECKING([for working dlopen])
echo "#include <stdio.h>
#include <dlfcn.h>
#include <signal.h>
typedef void (*nj_sighandler_t)(int);
nj_sighandler_t (*__njLibcSignal)(int, nj_sighandler_t);
void tmp(int a)
{
return;
}
int main()
{
void* handle = NULL;
if ((handle = dlopen(\"${LIBC_PATH}\", RTLD_LAZY)) == NULL)
return 2;
if((__njLibcSignal = dlsym(handle, \"signal\")) == NULL)
return 2;
dlclose(handle);
__njLibcSignal(SIGUSR1, tmp);
return 0;
}" > autoconf-tmp-dlconfig.c
gcc ${LIB_DL} autoconf-tmp-dlconfig.c -o autoconf-tmp-dlconfig 2> /dev/null
if test -s autoconf-tmp-dlconfig && (./autoconf-tmp-dlconfig; exit) 2> /dev/null
then
SANE_DLOPEN="yes"
AC_DEFINE(HAVE_SANE_DLOPEN, 1)
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
fi
rm -f autoconf-tmp-*
AC_PROG_LIBTOOL
AM_PROG_LIBTOOL
AC_MSG_CHECKING([for malloc's default alignment])
echo "#include <stdio.h>
int main()
{
int i, j;
unsigned long align;
align = ~(unsigned long)malloc(1) & 0x3f;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 0x3f; j++)
{
align &= ~(unsigned long)malloc(i);
align &= 0x3f;
}
}
printf(\"%d\", (align & 0x3f)+1);
return 0;
}" > autoconf-tmp-aligntest.c
gcc autoconf-tmp-aligntest.c -o autoconf-tmp-aligntest
TMP=`./autoconf-tmp-aligntest`
if test $TMP -eq "64" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 64)
elif test $TMP -eq "32" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 32)
elif test $TMP -eq "16" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 16)
elif test $TMP -eq "8" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 8)
elif test $TMP -eq "4" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 4)
elif test $TMP -eq "2" ; then
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 2)
else
AC_DEFINE(LIBC_MALLOC_ALIGNMENT, 1)
fi
AC_MSG_RESULT($TMP)
AC_MSG_CHECKING([if gcc supports __attribute__ in libs])
echo "#include <unistd.h>
static void tmp(void) __attribute__((constructor));
static void tmp(void)
{
_exit(0);
}
" > autoconf-tmp-attr.c
echo "#include <unistd.h>
int main(void)
{
_exit(1);
}
" > autoconf-tmp-attrmain.c
./libtool --mode=compile gcc -c ./autoconf-tmp-attr.c > /dev/null
./libtool --mode=link gcc ./autoconf-tmp-attr.lo -o libtmp.la -rpath /tmp > /dev/null
gcc autoconf-tmp-attrmain.c -o autoconf-tmp-attrmain -L./.libs/ -ltmp 2> /dev/null
if test -s autoconf-tmp-attrmain && (LD_LIBRARY_PATH=./.libs/ ./autoconf-tmp-attrmain; exit) 2> /dev/null
then
AC_DEFINE(HAVE_ATTRIB_CONSTRUCT, 1)
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
rm -f libtmp*
rm -f autoconf-tmp-*
rm -rf ./.libs/
AC_MSG_CHECKING([if errno is handled properly with threads])
echo "
#include <stdlib.h>
char buf[[90]];
static void AnObject2() __attribute__((constructor));
static void AnObject2()
{
char *buffer;
snprintf(buf, sizeof(buf), \"hello-%d-hi\", 6);
buffer = (char *)malloc(50);
strcpy(buffer, \"This is ok, I guess...\");
}
" > autoconf-tmp-errnolib.c
echo "int main() {return 0;}" > autoconf-tmp-errnomain.c
./libtool --mode=compile gcc -c ./autoconf-tmp-errnolib.c > /dev/null
./libtool --mode=link gcc ./autoconf-tmp-errnolib.lo -o libtmp.la -lpthread -rpath /tmp > /dev/null
gcc autoconf-tmp-errnomain.c -o autoconf-tmp-errnomain -L./.libs/ -lpthread -ltmp 2> /dev/null
if test -s autoconf-tmp-errnomain && (LD_LIBRARY_PATH=./.libs/ ./autoconf-tmp-errnomain; exit) 2> /dev/null
then
AC_DEFINE(HAVE_WORKING_ERRNO, 1)
AC_MSG_RESULT([yes])
else
AC_MSG_RESULT([no])
fi
rm -f libtmp*
rm -f autoconf-tmp-*
rm -rf ./.libs/
AC_MSG_CHECKING([if sigaction is POSIX])
AC_TRY_COMPILE(
[
#include <signal.h>
#include <stdio.h>
#include <signal.h>
],
[
void action_hdlr(int sig, siginfo_t *si, void *p)
{
exit(0);
}
int sigtest(void)
{
struct sigaction sa;
sigemptyset(&sa.sa_mask);
sa.sa_flags = SA_RESTART | SA_SIGINFO;
sa.sa_handler = 0;
sa.sa_sigaction = action_hdlr;
sigaction(SIGUSR1, &sa, NULL);
raise(SIGUSR1);
exit(1);
}],
AC_DEFINE(HAVE_POSIX_SIGACTION,1)
AC_MSG_RESULT([yes]),
AC_MSG_RESULT([no]))
AC_MSG_CHECKING([if __builtin_return_address works as documented])
AC_TRY_RUN(
[#include <stdio.h>
#define RA(x) case x: return __builtin_return_address(x)
static void *return_address(int frame)
{
switch(frame)
{
RA(0);
RA(1);RA(2);RA(3);RA(4);RA(5);RA(6);RA(7);RA(8);RA(9);
RA(10);RA(11);RA(12);RA(13);RA(14);RA(15);RA(16);RA(17);RA(18);RA(19);
default:
return NULL;
}
}
void interim(void)
{
register int i, waste2, waste3;
register void *t;
for(i=waste2=waste3=0; t = return_address(i); i++, waste2++, waste3++)
{
}
}
void interim0()
{
interim();
}
void interim1()
{
interim0();
}
int main()
{
interim1();
exit(0);
}],
AC_DEFINE(HAVE_WORKING_RET_ADDR,1)
AC_MSG_RESULT([Wow Im impressed]),
AC_MSG_RESULT(of course not)
rm -f core
AC_MSG_CHECKING([if we can work around it])
AC_TRY_RUN(
[#include <stdio.h>
#define RA(x) case x: return (__builtin_frame_address(x) ? __builtin_return_address(x) : 0)
static void *return_address(int frame)
{
switch(frame)
{
RA(0);
RA(1);RA(2);RA(3);RA(4);RA(5);RA(6);RA(7);RA(8);RA(9);
RA(10);RA(11);RA(12);RA(13);RA(14);RA(15);RA(16);RA(17);RA(18);RA(19);
default:
return NULL;
}
}
void interim(void)
{
register int i, waste2, waste3;
register void *t;
for(i=waste2=waste3=0; t = return_address(i); i++, waste2++, waste3++)
{
}
}
void interim0()
{
interim();
}
void interim1()
{
interim0();
}
int main()
{
interim1();
exit(0);
}],
AC_DEFINE(HAVE_WORKING_RET_ADDR,1)
AC_DEFINE(USE_FRAME_ADDR_HACK,1) AC_MSG_RESULT(yes),
AC_MSG_RESULT(no)
rm -f core
AC_MSG_WARN([Unable to get valid return address information. NJAMD will not be able to provide stack traces in user code on this platform.])
AC_MSG_CHECKING([If __builtin_return_address works at all])
AC_TRY_RUN(
[#include <stdio.h>
void ra_0(void)
{
/* We need return addresses up to at least 3 */
if(__builtin_return_address(0) == NULL)
exit(1);
if(__builtin_return_address(1) == NULL)
exit(1);
if(__builtin_return_address(2) == NULL)
exit(1);
if(__builtin_return_address(3) == NULL)
exit(1);
}
void ra_1()
{
ra_0();
}
void ra_2()
{
ra_1();
}
void ra_3()
{
ra_2();
}
int main()
{
ra_3();
exit(0);
}],
AC_DEFINE(USE_FRAME_ADDR_HACK,1) AC_MSG_RESULT([PHEW!]),
AC_DEFINE(HAVE_DEADLY_RET_ADDR,1)
AC_MSG_RESULT([Dear God..])
AC_MSG_WARN([The GCC maintainer of this platform needs to be shot. They
might as well have aliased __builtin_return_address to raise(SIGSEGV). Sigh.
As such be very impressed if NJAMD works at all. Sorry.])
rm -f core,
AC_MSG_RESULT([cross compiling: hoping that __builtin_return_address is sane])),
AC_DEFINE(HAVE_WORKING_RET_ADDR,1)
AC_DEFINE(USE_FRAME_ADDR_HACK,1) AC_MSG_RESULT([cross comping: guessing workaround needed])
),
dnl cross compiling
AC_DEFINE(HAVE_WORKING_RET_ADDR,1)
AC_DEFINE(USE_FRAME_ADDR_HACK,1) AC_MSG_RESULT([cross compiling: guessing workaround needed])
)
dnl *** End handwritten tests ***
AC_OUTPUT(
Makefile
docs/Makefile
tests/Makefile
src/Makefile
src/fe/Makefile
src/fe/console/Makefile
src/fe/gui/Makefile
src/fe/gui/gtkextext/Makefile
src/fe/util/Makefile
src/lib/Makefile
kernel_mods/Makefile
include/Makefile
)
|