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 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093
|
#!/bin/sh
###############################################################################
#
# Copyright (C) 2003-2021 Anders Gavare. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
# SUCH DAMAGE.
#
#
# This is a minimal configure script, hardcoded for GXemul. This script
# figures out which compiler flags will work, and creates Makefiles in
# sub-directories. A config.h file is also created.
#
#
# ---> FOR NORMAL USE, JUST RUN ./configure WITHOUT OPTIONS!
#
#
# To compile the emulator with profiling (during development), use
# CFLAGS="-pg", run the emulator, and then run 'gprof gxemul' and study
# the results.
#
# Or better, using callgrind/cachegrind/kcachegrind:
# valgrind --tool=callgrind --dump-instr=yes ./gxemul -e testm88k test/FileLoader_A.OUT_M88K
# or
# valgrind --tool=cachegrind ./gxemul -e testm88k test/FileLoader_A.OUT_M88K
# followed by
# kcachegrind
#
#
# The main things that are detected by this script:
#
# o) special hacks for some OSes
# o) which compiler to use (overridden by setting CC)
# o) which compiler flags to use (overridden by setting CFLAGS)
# o) X11 flags and libraries (TODO: should be possible to override
# via command line options?)
#
# The general philosophy regarding command line switches is that anything
# which can be incorporated into the program as a runtime command line option
# should be, instead of requiring a recompile.
#
###############################################################################
#
# Figure out the default prefix for "make install":
#
# If the PREFIX environment variable is set before running configure, it is
# used. The DEFAULTPREFIX calculated here is only used if PREFIX is undefined.
#
DEFAULTPREFIX=/usr/local
if [ z`uname` = zLinux ]; then
# /usr is more common on Linux than /usr/local
DEFAULTPREFIX=/usr
else
TRY=/usr/local
if [ -d $TRY/bin ]; then
DEFAULTPREFIX=$TRY
else
TRY=/opt
if [ -d $TRY ]; then
DEFAULTPREFIX=$TRY
else
TRY=/usr
if [ -d $TRY ]; then
DEFAULTPREFIX=$TRY
fi
fi
fi
fi
OTHERLIBS="$LDFLAGS"
if [ z"$*" != z ]; then
# Parse command line options:
for a in $*; do
if [ z$a = z--disable-x ]; then
NOX11=YES
else if [ z$a = z--debug ]; then
DEBUG=YES
else if [ z$a = z--help ]; then
printf "usage: $0 [options]\n\n"
echo " --disable-x don't include X11 support,"\
"even if the host supports it"
echo " --debug configure for a" \
"debug build (turn off optimizations,"
echo " try enabling -Werror etc.)"
echo
echo "If the PREFIX environment variable is set," \
"it will override the default"
echo "value, which on this platform is: $DEFAULTPREFIX"
echo
exit
else
echo "Invalid option: $a"
echo "Run $0 --help to get a list of" \
"available options."
exit
fi; fi; fi
done
fi
###############################################################################
#
# Configure options:
#
# This creates a config.h file, which is then included from include/misc.h.
#
###############################################################################
# Head of config.h:
printf "/*
* THIS FILE IS AUTOMATICALLY CREATED BY configure!
* DON'T EDIT THIS FILE MANUALLY, IT WILL BE OVERWRITTEN.
*/
\n#ifndef CONFIG_H\n#define CONFIG_H\n\n" > config.h
# Figure out if VERSION should be defined.
X=`basename \`pwd\`|cut -d \- -f 2-`
if [ z"$X" = zgxemul ]; then
printf "#define VERSION \"(unknown version)\"\n" >> config.h
else
printf "#define VERSION \"$X\"\n" >> config.h
fi
if [ z"$DEBUG" = zYES ]; then
echo "Building a DEBUG version!"
fi
ZZ=`echo compiled on \`uname\`/\`uname -m\`, \`date\``
printf "#define COMPILE_DATE \"$ZZ\"\n" >> config.h
# Include support for all CPU types:
printf "#define ADD_ALL_CPU_FAMILIES " >> config.h
# Alpha
printf " add_cpu_family(alpha_cpu_family_init, ARCH_ALPHA);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_alpha.o cpu_alpha_palcode.o memory_alpha.o"
CPU_TOOLS="$CPU_TOOLS generate_alpha_misc"
# ARM
printf " add_cpu_family(arm_cpu_family_init, ARCH_ARM);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_arm.o cpu_arm_coproc.o memory_arm.o "
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u0_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u0_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u1_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p0_u1_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u0_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u0_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u1_w0.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_loadstore_p1_u1_w1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_dpi.o tmp_arm_r.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r0.o tmp_arm_r1.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r2.o tmp_arm_r3.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r4.o tmp_arm_r5.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r6.o tmp_arm_r7.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_r8.o tmp_arm_r9.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_ra.o tmp_arm_rb.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_rc.o tmp_arm_rd.o"
CPU_ARCHS="$CPU_ARCHS tmp_arm_re.o tmp_arm_rf.o tmp_arm_multi.o"
CPU_TOOLS="$CPU_TOOLS generate_arm_dpi generate_arm_r"
CPU_TOOLS="$CPU_TOOLS generate_arm_loadstore generate_arm_multi"
# i960
printf " add_cpu_family(i960_cpu_family_init, ARCH_I960);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_i960.o memory_i960.o"
# M88K
printf " add_cpu_family(m88k_cpu_family_init, ARCH_M88K);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_m88k.o memory_m88k.o"
CPU_TOOLS="$CPU_TOOLS generate_m88k_bcnd"
CPU_TOOLS="$CPU_TOOLS generate_m88k_loadstore"
# MIPS
printf " add_cpu_family(mips_cpu_family_init, ARCH_MIPS);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_mips.o cpu_mips_coproc.o "
CPU_ARCHS="$CPU_ARCHS cpu_mips_instr_unaligned.o"
CPU_TOOLS="$CPU_TOOLS generate_mips_loadstore"
CPU_TOOLS="$CPU_TOOLS generate_mips_loadstore_multi"
# POWER/PowerPC
printf " add_cpu_family(ppc_cpu_family_init, ARCH_PPC);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_ppc.o"
CPU_TOOLS="$CPU_TOOLS generate_ppc_loadstore"
# RISC-V
printf " add_cpu_family(riscv_cpu_family_init, ARCH_RISCV);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_riscv.o memory_riscv.o"
# SuperH
printf " add_cpu_family(sh_cpu_family_init, ARCH_SH);" >> config.h
CPU_ARCHS="$CPU_ARCHS cpu_sh.o memory_sh.o"
printf "\n" >> config.h
###############################################################################
#
# Create the Makefile header:
#
###############################################################################
rm -f _Makefile.header
printf "#
# DO NOT EDIT THIS FILE! It is automagically created by
# the configure script, based on Makefile.skel.
#\n\n" >> _Makefile.header
# Try with the simplest possible test program. Actually, test static variables
# as well, because GXemul uses things like NULL-initialized global pointers,
# and it is important that they work. (Some versions of GCC on Solaris are
# known to be completely broken, for instance.)
echo '#include <stdio.h>
#include <stdbool.h>
int main(int argc, char* argv[])
{
static int s = 0;
int x = 2; // make sure that BCPL style comments work,
x ++; // that code and variable declarations can be
int y = -2; // mixed, and that the bool type behaves
bool a = x; // reasonably.
bool b = y;
bool c = a + b;
int d = a + b;
printf("%i,%i,%i,%i,%i", s, a, b, c, d);
for (int i = 0; i < 10; ++i) ;
return 0;
}
' > _testprog.c
# Try to detect which C compiler to use, if CC is not set:
printf "checking which C compiler to use... "
rm -f _testprog
if [ z"$CC" = z ]; then
CC=cc
fi
printf "#!/bin/sh\n$CC $CFLAGS _testprog.c -o _testprog >" > _test.sh
printf " /dev/null 2> /dev/null\n" >> _test.sh
chmod 755 _test.sh
./_test.sh > /dev/null 2> /dev/null
OK=0
if [ -x _testprog ]; then
OK=1
if [ z`./_testprog` = z0,1,1,1,2 ]; then
OK=2
fi
fi
if [ z$OK = z0 ]; then
printf "broken cc detected: $CC $CFLAGS\n"
printf "The test program:\n\n"
cat _testprog.c
printf "could not be compiled at all.\n"
fi
if [ z$OK = z1 ]; then
printf "broken cc detected: $CC $CFLAGS\n"
printf "The test program:\n\n"
cat _testprog.c
printf "should have resulted in 0,1,1,1,2 but the result was: "
./_testprog
fi
if [ z$OK != z2 ]; then
printf "\nPlease set the CC environment variable to a working C "
printf "compiler before running\nthe configure script, and make"
printf " sure that the CFLAGS environment variable is\nalso valid"
printf " for that compiler (e.g. -std=c99 if needed).\n"
exit
fi
rm -f _testprog
rm -f _test.sh
echo "$CC $CFLAGS"
if [ z"$DEBUG" != zYES ]; then
CFLAGS="-DNDEBUG $CFLAGS"
fi
if [ z$NOX11 = z ]; then
printf "checking for X11 headers and libs\n"
# Try to compile a small X11 test program:
printf "#include <X11/Xlib.h>
#include <stdio.h>
Display *dis;
void f(void) {
dis = XOpenDisplay(NULL);
}
int main(int argc, char *argv[])
{ printf(\"1\"); return 0; }
" > _test_x11.c
XOK=0
XINCLUDE=-I/usr/X11R6/include
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/X11R6/lib -lX11 -Wl,-rpath,/usr/X11R6/lib"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
if [ 1 = `./_test_x11` ]; then
XOK=1
fi
fi
rm -f _test_x11 _test_x11.o
if [ z$XOK = z0 ]; then
XINCLUDE=-I/usr/X11R7/include
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/X11R7/lib -lX11 -Wl,-rpath,/usr/X11R7/lib"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
if [ 1 = `./_test_x11` ]; then
XOK=1
fi
fi
fi
rm -f _test_x11 _test_x11.o
if [ z$XOK = z0 ]; then
XINCLUDE=-I/usr/local/include
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/local/lib -lX11 -Wl,-rpath,/usr/local/lib"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
if [ 1 = `./_test_x11` ]; then
XOK=1
fi
fi
fi
rm -f _test_x11 _test_x11.o
# MacOS:
if [ z$XOK = z0 ]; then
XINCLUDE=-I/opt/X11/include
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/opt/X11/lib -lX11"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
XOK=1
fi
fi
rm -f _test_x11 _test_x11.o
# Special case for some 64-bit Linux/x86_64 systems:
if [ z$XOK = z0 ]; then
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
XLIB="-L/usr/X11R6/lib64 -lX11"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
if [ 1 = `./_test_x11` ]; then
XOK=1
fi
fi
fi
rm -f _test_x11 _test_x11.o
if [ z$XOK = z0 ]; then
XINCLUDE=""
$CC $CFLAGS _test_x11.c -c -o _test_x11.o $XINCLUDE 2> /dev/null
# -lsocket for Solaris
XLIB="-lX11 -lsocket"
$CC $CFLAGS _test_x11.o -o _test_x11 $XLIB 2> /dev/null
if [ -x _test_x11 ]; then
if [ 1 = `./_test_x11` ]; then
XOK=1
fi
fi
rm -f _test_x11 _test_x11.o
fi
if [ z$XOK = z0 ]; then
echo "Failed to compile X11 test program." \
"Configuring without X11."
else
printf " headers: $XINCLUDE\n"
printf " libraries: $XLIB\n"
echo "XINCLUDE=$XINCLUDE" >> _Makefile.header
echo "XLIB=$XLIB" >> _Makefile.header
printf "#define WITH_X11\n" >> config.h
fi
rm -f _test_x11.c
fi
if [ z$HPUX = zYES ]; then
CFLAGS="-D_XOPEN_SOURCE_EXTENDED $CFLAGS"
printf "#define HPUX\n" >> config.h
fi
if [ z$OSF1 = zYES ]; then
CFLAGS="-D_XOPEN_SOURCE=500 -D_OSF_SOURCE -D_POSIX_PII_SOCKET $CFLAGS"
fi
# CWARNINGS:
printf "checking whether -Wall can be used... "
$CC $CFLAGS _testprog.c -o _testprog -Wall 2> /dev/null
if [ -x _testprog ]; then
printf "yes\n"
CWARNINGS="-Wall $CWARNINGS"
if [ z"$DEBUG" = zYES ]; then
printf "checking whether -Werror can be used... "
rm -f _testprog
$CC $CWARNINGS $CFLAGS _testprog.c -o _testprog -Werror 2> _testprog.err
if [ -x _testprog ]; then
printf "yes\n"
CWARNINGS="$CWARNINGS -Werror"
else
printf "no\n"
#printf "CFLAGS = $CFLAGS\n"
#cat _testprog.err
#printf "\n"
fi
fi
else
printf "no\n"
fi
rm -f _testprog _testprog.err
# -Wstrict-aliasing
printf "checking whether -Wstrict-aliasing can be used... "
$CC $CFLAGS -Wstrict-aliasing _testprog.c -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wstrict-aliasing $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wextra -Wno-unused-parameter -Wno-cast-align
printf "checking whether -Wextra -Wno-unused-parameter -Wno-cast-align can be used... "
$CC $CFLAGS -Wextra -Wno-unused-parameter -Wno-cast-align _testprog.c -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="$CWARNINGS -Wextra -Wno-unused-parameter -Wno-cast-align"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wcast-align
printf "checking whether -Wcast-align can be used... "
$CC $CFLAGS -Wcast-align _testprog.c -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wcast-align $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -Wshadow
printf "checking whether -Wshadow can be used... "
$CC $CFLAGS -Wshadow _testprog.c -o _testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CWARNINGS="-Wshadow $CWARNINGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
# -O optimization for non-debug builds. Try -O and -O3.
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -O3 or -O can be used (non-DEBUG build)... "
$CC $CFLAGS -O _testprog.c -o _testprog 2> /dev/null
if [ -x _testprog ]; then
rm -f _testprog
$CC $CFLAGS -O3 _testprog.c -o _testprog 2> /dev/null
if [ -x _testprog ]; then
CFLAGS="-O3 $CFLAGS"
printf "yes, -O3\n"
else
CFLAGS="-O $CFLAGS"
printf "yes, -O\n"
fi
else
printf "no\n"
fi
fi
rm -f _testprog
# -fpeephole
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fpeephole can be used... "
$CC $CFLAGS -fpeephole _testprog.c -o _testprog > _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep peephole _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CFLAGS="-fpeephole $CFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -fomit-frame-pointer
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fomit-frame-pointer can be used... "
$CC $CFLAGS -fomit-frame-pointer _testprog.c -o \
_testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep frame _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CFLAGS="-fomit-frame-pointer $CFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -fstrict-aliasing
if [ ! z"$DEBUG" = zYES ]; then
printf "checking whether -fstrict-aliasing can be used... "
$CC $CFLAGS -fstrict-aliasing _testprog.c -o \
_testprog 1> _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if grep strict _testprog.error > /dev/null 2>&1; then
printf "no\n"
else
if [ -x _testprog ]; then
CFLAGS="-fstrict-aliasing $CFLAGS"
printf "yes\n"
else
printf "no\n"
fi
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -g, for debug builds
if [ z"$DEBUG" = zYES ]; then
printf "checking whether -g can be used... "
$CC $CFLAGS -g _testprog.c -o _testprog > _testprog.stdout 2>&1
cat _testprog.stdout >> _testprog.error
if [ -x _testprog ]; then
CFLAGS="-g $CFLAGS"
printf "yes\n"
else
printf "no\n"
fi
rm -f _testprog _testprog.error _testprog.stdout
fi
# -lrt for nanosleep?
printf "checking whether -lrt is required for nanosleep... "
printf "#include <time.h>\n#include <stdio.h>
int main(int argc, char *argv[]){nanosleep(NULL,NULL);return 0;}\n" > _testns.c
$CC $CFLAGS _testns.c -o _testns 2> /dev/null
if [ ! -x _testns ]; then
$CC $CFLAGS -lrt _testns.c -o _testns 2> /dev/null
if [ ! -x _testns ]; then
printf "WARNING! COULD NOT COMPILE WITH nanosleep AT ALL!\n"
else
# -lrt for nanosleep
OTHERLIBS="-lrt $OTHERLIBS"
printf "yes\n"
fi
else
printf "no\n"
fi
rm -f _testns.c _testns
# -lresolv for inet_pton?
printf "checking whether -lresolv is required for inet_pton... "
printf "int inet_pton(void); int main(int argc, " > _testr.c
printf "char *argv[]) { return inet_pton(); }\n" >> _testr.c
$CC $CFLAGS _testr.c -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CC $CFLAGS _testr.c -lresolv -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CC $CFLAGS _testr.c -lresolv -lnsl -o _testr 2> /dev/null
if [ ! -x _testr ]; then
printf "no, using inet_aton\n"
else
# -lresolv -lnsl for inet_pton
OTHERLIBS="-lresolv -lnsl $OTHERLIBS"
printf "yes (and -lnsl)\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
else
# -lresolv for inet_pton
OTHERLIBS="-lresolv $OTHERLIBS"
printf "yes\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
else
printf "no\n"
printf "#define HAVE_INET_PTON\n" >> config.h
fi
rm -f _testr.c _testr.o _testr
# -lm?
printf "checking for math libs..."
printf "#include <math.h>\nint main(int argc, char *argv[]) { " > _testr.c
printf "double x = sqrt(sin((double)argc)); return (int)x; }\n" >> _testr.c
$CC $CFLAGS _testr.c -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CC $CFLAGS _testr.c -lm -o _testr 2> /dev/null
if [ ! -x _testr ]; then
$CC $CFLAGS _testr.c -lm -lcpml -o _testr 2> /dev/null
if [ ! -x _testr ]; then
printf "\nWARNING! Could not compile math test "
printf "at all!\nContinuing anyway.\n\n"
else
# -lm AND -lcpml
OTHERLIBS="-lm -lcpml $OTHERLIBS"
printf " -lm -lcpml\n"
fi
else
# Normal -lm
OTHERLIBS="-lm $OTHERLIBS"
printf " -lm\n"
fi
else
printf " none needed\n"
fi
rm -f _testr.c _testr.o _testr
# strlcpy missing?
printf "checking for strlcpy... "
printf "#include <string.h>
int main(int argc, char *argv[]) { char *p; char *q; size_t x;
x = strlcpy(p, q, 50); return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using mystrlcpy\n"
printf "#define strlcpy mystrlcpy\n" >> config.h
printf "#define strlcat mystrlcat\n" >> config.h
printf "#define USE_STRLCPY_REPLACEMENTS\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.c _tests.o _tests
# strtoull missing?
printf "checking for strtoull... "
printf "#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
int main(int argc, char *argv[]) {
long long x = strtoull(argv[1], NULL, 0); return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using mystrtoull\n"
printf "#define strtoull mystrtoull\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.c _tests.o _tests
# mkstemp missing?
printf "checking for mkstemp... "
printf "#include <unistd.h>
#include <stdlib.h>
int main(int argc, char *argv[]) { int x; char y[4] = \"abc\";
x = mkstemp(y); return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing, using workaround (perhaps not working properly)\n"
printf "#define mkstemp mymkstemp\n" >> config.h
else
printf "found\n"
fi
rm -f _tests.c _tests.o _tests
# fseeko missing?
printf "checking for fseeko... "
printf "#include <stdlib.h>
#include <limits.h>
#include <stdio.h>
#include <sys/types.h>
int main(int argc, char *argv[]) { fseeko(NULL, 0, 0); return 0;}\n" > _tests.c
$CC $CFLAGS $CWARNINGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
# Try with _LARGEFILE_SOURCE (hack to make fseeko
# work on 64-bit Linux):
$CC $CFLAGS -D_LARGEFILE_SOURCE $CWARNINGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "missing\n"
printf "WARNING! fseeko missing from libc. Using a hack, "
printf "which probably doesn't work.\n"
printf "#define HACK_FSEEKO\n" >> config.h
else
printf "using -D_LARGEFILE_SOURCE hack\n"
CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE"
fi
else
printf "found\n"
fi
rm -f _tests.c _tests.o _tests
# socklen_t missing?
# (for example really old OpenBSD/arc 2.3, inside the emulator)
printf "checking for socklen_t... "
printf "#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
int main(int argc, char *argv[]) { socklen_t x; return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "no, using int\n"
CFLAGS="$CFLAGS -Dsocklen_t=int"
else
printf "socklen_t\n"
fi
rm -f _tests.c _tests.o _tests
# MAP_ANON missing? (On some HP-UX systems? Use MAP_ANONYMOUS instead.)
printf "checking for MAP_ANON... "
rm -f _tests
printf "#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
int main(int argc, char *argv[]) { int x = MAP_ANON; return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "#include <stdio.h>
#include <sys/types.h>
#include <sys/mman.h>
int main(int argc, char *argv[])
{ int x = MAP_ANONYMOUS; return 0;}\n" > _tests.c
$CC $CFLAGS _tests.c -o _tests 2> /dev/null
if [ ! -x _tests ]; then
printf "no\n\n"
printf "WARNING! Neither MAP_ANON nor MAP_ANONYMOUS work on "
printf "this system.\nPlease try to compile anyway, and report"
printf " to me whether it builds/runs or not.\n\n"
printf "#define MAP_ANON 0\n" >> config.h
printf "#define NO_MAP_ANON\n" >> config.h
else
printf "using MAP_ANONYMOUS\n"
printf "#define MAP_ANON MAP_ANONYMOUS\n" >> config.h
fi
else
printf "yes\n"
fi
rm -f _tests.c _tests.o _tests
# Check for PRIx64 in inttypes.h:
printf "checking for PRIx64 in inttypes.h... "
printf "#include <inttypes.h>\nint main(int argc, char *argv[])\n
{\n#ifdef PRIx64\nreturn 0;\n#else\nreturn 1;\n#endif\n}\n" > _testpri.c
$CC $CFLAGS _testpri.c -o _testpri 2> /dev/null
if [ ! -x _testpri ]; then
printf "\nERROR! COULD NOT COMPILE PRIx64 TEST PROGRAM AT ALL!\n"
exit
else
if ./_testpri; then
printf "yes\n"
else
$CC $CFLAGS -D__STDC_FORMAT_MACROS _testpri.c -o _testpri 2> /dev/null
if [ -x _testpri ]; then
printf "using __STDC_FORMAT_MACROS\n"
CFLAGS="$CFLAGS -D__STDC_FORMAT_MACROS"
else
printf "no, using an ugly hack instead, "
printf "#define NO_C99_PRINTF_DEFINES\n" >> config.h
# Try llx first:
printf "#include <stdio.h>\n#include <inttypes.h>\nint main(int argc, char *argv[]){
printf(\"%%llx\\\n\", (int64_t)128);return 0;}\n" > _testpri.c
rm -f _testpri
$CC $CFLAGS $CWARNINGS _testpri.c -o _testpri 2> /dev/null
if [ z`./_testpri` = z80 ]; then
printf "PRIx64=llx\n"
printf "#define NO_C99_64BIT_LONGLONG\n" >> config.h
else
# Try lx too:
printf "#include <stdio.h>\n#include <inttypes.h>\nint main(int argc, char *argv[]){
printf(\"%%lx\\\n\", (int64_t)128);return 0;}\n" > _testpri.c
rm -f _testpri
$CC $CFLAGS $CWARNINGS _testpri.c -o _testpri 2> _testpri.result
if [ z`./_testpri` = z80 ]; then
printf "PRIx64=lx\n"
else
printf "\nFailed, neither lx nor llx worked!\n"
exit
fi
fi
fi
fi
fi
rm -f _testpri.c _testpri _testpri.result
# Check for 64-bit off_t:
printf "checking for 64-bit off_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(off_t));return 0;}\n" > _testoff.c
$CC $CFLAGS _testoff.c -o _testoff 2> /dev/null
if [ ! -x _testoff ]; then
printf "\nWARNING! COULD NOT COMPILE off_t TEST PROGRAM AT ALL!\n"
else
if [ z`./_testoff` = z8 ]; then
printf "yes\n"
else
$CC $CFLAGS -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
_testoff.c -o _testoff 2> /dev/null
if [ ! -x _testoff ]; then
printf "\nWARNING! COULD NOT COMPILE off_t TEST "
printf "PROGRAM!\n"
else
if [ z`./_testoff` = z8 ]; then
CFLAGS="-D_FILE_OFFSET_BITS=64 $CFLAGS"
CFLAGS="-D_LARGEFILE_SOURCE $CFLAGS"
printf "using -D_FILE_OFFSET_BITS=64"
printf " -D_LARGEFILE_SOURCE\n"
else
printf "NO\n"
printf "Warning! No 64-bit off_t. Continuing "
printf "anyway.\n"
fi
fi
fi
fi
rm -f _testoff.c _testoff
# Check for u_int8_t etc:
# These are needed because some header files in src/include/ use u_int*
# instead of uint*, and I don't have time to rewrite them all.
printf "checking for u_int8_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(u_int8_t));return 0;}\n" > _testuint.c
$CC $CFLAGS _testuint.c -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
rm -f _testuint*
printf "#include <stdio.h>\n#include <inttypes.h>
\n#include <sys/types.h>\nint main(int argc, char *argv[])
{printf(\"%%i\\\n\", (int)sizeof(uint8_t));return 0;}\n" > _testuint.c
$CC $CFLAGS _testuint.c -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
printf "no\n\nERROR: No u_int8_t or uint8_t. Aborting\n"
# TODO: Automagically detect using various combinations
# of char, int, short, long etc.
exit
fi
printf "typedef uint8_t u_int8_t;\n" >> config.h
printf "typedef uint16_t u_int16_t;\n" >> config.h
printf "typedef uint32_t u_int32_t;\n" >> config.h
printf "uint8_t\n"
else
printf "yes\n"
fi
rm -f _testuint.c _testuint
printf "checking for u_int64_t... "
printf "#include <stdio.h>\n#include <inttypes.h>\n#include <sys/types.h>\n
int main(int argc, char *argv[]){printf(\"%%i\\\n\",
(int)sizeof(u_int64_t));return 0;}\n" > _testuint.c
$CC $CFLAGS _testuint.c -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
rm -f _testuint*
printf "#include <stdio.h>\n#include <inttypes.h>
\n#include <sys/types.h>\nint main(int argc, char *argv[])
{printf(\"%%i\\\n\", (int)sizeof(uint64_t));return 0;}\n" > _testuint.c
$CC $CFLAGS _testuint.c -o _testuint 2> /dev/null
if [ ! -x _testuint ]; then
printf "no\n\nERROR: No u_int64_t or uint64_t. Aborting\n"
# TODO: Automagically detect using various combinations
# of char, int, short, long etc.
exit
fi
printf "typedef uint64_t u_int64_t;\n" >> config.h
printf "uint64_t\n"
else
printf "yes\n"
fi
rm -f _testuint*
printf "checking for __builtin_expect... "
printf "#include <stdio.h>\n\nint main(int argc, char *argv[]) {
if (__builtin_expect(!!(2), 1)) return 0;\n return 1;\n}\n" > _testexpect.c
$CC $CFLAGS _testexpect.c -o _testexpect 2> /dev/null
if [ ! -x _testexpect ]; then
printf "no\n"
printf "#define likely(x) (x)\n" >> config.h
printf "#define unlikely(x) (x)\n" >> config.h
else
printf "yes\n"
printf "#define likely(x) __builtin_expect(!!(x), 1)\n" >> config.h
printf "#define unlikely(x) __builtin_expect(!!(x), 0)\n" >> config.h
fi
rm -f _testexpect*
###############################################################################
# Host byte order?
printf "checking host endianness... "
rm -f _test_end*
printf '#include <stdio.h>
int main(int argc, char *argv[])
{ int x = 1; void *xp = (void *)&x; char *p = (char *)xp;
if (*p) printf("little\\\n"); else printf("big\\\n"); }
' > _test_end.c
$CC $CFLAGS _test_end.c -o _test_end 2> /dev/null
X=`./_test_end`
echo $X
if [ z$X = zlittle ]; then
printf "#define HOST_LITTLE_ENDIAN\n" >> config.h
else
if [ z$X = zbig ]; then
printf "#define HOST_BIG_ENDIAN\n" >> config.h
else
echo "Error! Could not determine host's endianness."
exit
fi
fi
rm -f _test_end*
###############################################################################
if [ "z$PREFIX" = z ]; then
PREFIX="$DEFAULTPREFIX"
fi
echo "checking for 'make install' prefix: $PREFIX"
###############################################################################
if [ z"$MANDIR" = z ]; then
# Guess either $PREFIX/share/man or $PREFIX/man, depending on existing
# directories. Fallback is $PREFIX/man.
TRY=$PREFIX/share/man
if [ -d "$TRY" ]; then
MANDIR="$TRY"
else
MANDIR="$PREFIX"/man
fi
fi
echo "checking for 'make install' man dir: $MANDIR"
###############################################################################
INCLUDE=-Iinclude/
DINCLUDE=-I../include/
INCLUDE2=-I../../include/
rm -f _testprog.c*
echo C compiler flags: $CFLAGS $CWARNINGS
echo Linker flags: $OTHERLIBS
if [ z"$DESTDIR" != z ]; then
echo "Destination dir: $DESTDIR"
fi
echo "CWARNINGS=$CWARNINGS" >> _Makefile.header
echo "COPTIM=$CFLAGS" >> _Makefile.header
echo "INCLUDE=$INCLUDE" >> _Makefile.header
echo "DINCLUDE=$DINCLUDE" >> _Makefile.header
echo "INCLUDE2=$INCLUDE2" >> _Makefile.header
echo "CC=$CC" >> _Makefile.header
echo "OTHERLIBS=$OTHERLIBS" >> _Makefile.header
echo "CPU_ARCHS=$CPU_ARCHS" >> _Makefile.header
echo "CPU_TOOLS=$CPU_TOOLS" >> _Makefile.header
echo "PREFIX=$PREFIX" >> _Makefile.header
echo "MANDIR=$MANDIR" >> _Makefile.header
echo "DESTDIR=$DESTDIR" >> _Makefile.header
echo "" >> _Makefile.header
# Create the Makefiles:
D=". src src/console src/cpus src/debugger src/devices src/core"
D="$D src/devices/fonts src/disk src/file src/include src/machines"
D="$D src/net src/promemul src/symbol"
echo "creating Makefiles..."
for a in $D; do
touch $a/Makefile
cat _Makefile.header > $a/Makefile
cat $a/Makefile.skel >> $a/Makefile
done
# Undefine 'mips', to enable build on OpenBSD's MIPS platforms:
printf "\n#undef mips\n" >> config.h
# Tail of config.h:
printf "\n#endif /* CONFIG_H */\n" >> config.h
# Remove temporary Makefile header, etc.:
rm -f _Makefile.header _test*
echo Configured. You may now run ' make ' to build gxemul.
|