randomtest 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  1. #!/bin/sh
  2. # If not specified in environment...
  3. if ! test "$LIBC"; then
  4. # Select which libc to build against
  5. LIBC="glibc"
  6. LIBC="uclibc"
  7. fi
  8. # x86 32-bit:
  9. #CROSS_COMPILER_PREFIX="i486-linux-uclibc-"
  10. # My system has strange prefix for x86 64-bit uclibc:
  11. #CROSS_COMPILER_PREFIX="x86_64-pc-linux-gnu-"
  12. if test $# -lt 2 || ! test -d "$1" || test -e "$2"; then
  13. echo "Usage: $0 SRC_DIR TMP_DIR"
  14. echo
  15. echo "SRC_DIR will be copied to TMP_DIR directory."
  16. echo "Then a random build will be performed."
  17. echo
  18. echo "Useful variables:"
  19. echo "\$LIBC, \$CROSS_COMPILER_PREFIX, \$MAKEOPTS"
  20. exit 1
  21. fi
  22. cp -dpr -- "$1" "$2" || { echo "copy error"; exit 1; }
  23. cd -- "$2" || { echo "cd $dir error"; exit 1; }
  24. # Generate random config
  25. make randconfig >/dev/null || { echo "randconfig error"; exit 1; }
  26. # Tweak resulting config
  27. cat .config \
  28. | grep -v CONFIG_DEBUG_PESSIMIZE \
  29. | grep -v CONFIG_WERROR \
  30. | grep -v CONFIG_CROSS_COMPILER_PREFIX \
  31. | grep -v CONFIG_SELINUX \
  32. | grep -v CONFIG_EFENCE \
  33. | grep -v CONFIG_DMALLOC \
  34. \
  35. | grep -v CONFIG_RFKILL \
  36. >.config.new
  37. mv .config.new .config
  38. echo '# CONFIG_DEBUG_PESSIMIZE is not set' >>.config
  39. echo '# CONFIG_WERROR is not set' >>.config
  40. echo "CONFIG_CROSS_COMPILER_PREFIX=\"${CROSS_COMPILER_PREFIX}\"" >>.config
  41. echo '# CONFIG_SELINUX is not set' >>.config
  42. echo '# CONFIG_EFENCE is not set' >>.config
  43. echo '# CONFIG_DMALLOC is not set' >>.config
  44. echo '# CONFIG_RFKILL is not set' >>.config
  45. # If glibc, don't build static
  46. if test x"$LIBC" = x"glibc"; then
  47. cat .config \
  48. | grep -v CONFIG_STATIC \
  49. | grep -v CONFIG_FEATURE_LIBBUSYBOX_STATIC \
  50. \
  51. | grep -v CONFIG_FEATURE_2_4_MODULES \
  52. | grep -v CONFIG_FEATURE_USE_BSS_TAIL \
  53. | grep -v CONFIG_DEBUG_SANITIZE \
  54. | grep -v CONFIG_FEATURE_MOUNT_NFS \
  55. | grep -v CONFIG_FEATURE_INETD_RPC \
  56. >.config.new
  57. mv .config.new .config
  58. echo '# CONFIG_STATIC is not set' >>.config
  59. echo '# CONFIG_FEATURE_LIBBUSYBOX_STATIC is not set' >>.config
  60. # newer glibc (at least 2.23) no longer supply query_module() ABI.
  61. # People who target 2.4 kernels would likely use older glibc (and older bbox).
  62. echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
  63. echo '# CONFIG_FEATURE_USE_BSS_TAIL is not set' >>.config
  64. echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
  65. # 2018: current glibc versions no longer include rpc/rpc.h
  66. echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
  67. echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
  68. fi
  69. # If uclibc, build static, and remove some things
  70. # likely to not work on uclibc.
  71. if test x"$LIBC" = x"uclibc"; then
  72. cat .config \
  73. | grep -v CONFIG_STATIC \
  74. | grep -v CONFIG_BUILD_LIBBUSYBOX \
  75. | grep -v CONFIG_PIE \
  76. \
  77. | grep -v CONFIG_FEATURE_2_4_MODULES \
  78. | grep -v CONFIG_FEATURE_SYNC_FANCY \
  79. | grep -v CONFIG_NANDWRITE \
  80. | grep -v CONFIG_NANDDUMP \
  81. | grep -v CONFIG_BLKDISCARD \
  82. | grep -v CONFIG_NSENTER \
  83. | grep -v CONFIG_UNSHARE \
  84. | grep -v CONFIG_FALLOCATE \
  85. | grep -v CONFIG_UDHCPC6 \
  86. | grep -v CONFIG_NSLOOKUP \
  87. | grep -v CONFIG_ASH_INTERNAL_GLOB \
  88. >.config.new
  89. mv .config.new .config
  90. echo 'CONFIG_STATIC=y' >>.config
  91. echo '# CONFIG_BUILD_LIBBUSYBOX is not set' >>.config
  92. echo '# CONFIG_PIE is not set' >>.config
  93. echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
  94. echo '# CONFIG_FEATURE_SYNC_FANCY is not set' >>.config
  95. # My uclibc installation does not support some needed APIs...
  96. echo '# CONFIG_NANDWRITE is not set' >>.config
  97. echo '# CONFIG_NANDDUMP is not set' >>.config
  98. echo '# CONFIG_BLKDISCARD is not set' >>.config
  99. echo '# CONFIG_NSENTER is not set' >>.config
  100. echo '# CONFIG_UNSHARE is not set' >>.config
  101. echo '# CONFIG_FALLOCATE is not set' >>.config
  102. echo '# CONFIG_UDHCPC6 is not set' >>.config
  103. echo '# CONFIG_NSLOOKUP is not set' >>.config
  104. echo 'CONFIG_ASH_INTERNAL_GLOB=y' >>.config
  105. fi
  106. # If musl
  107. if test x"$LIBC" = x"musl"; then
  108. cat .config \
  109. | grep -v CONFIG_STATIC \
  110. | grep -v CONFIG_DEBUG_SANITIZE \
  111. | grep -v CONFIG_LFS \
  112. | grep -v CONFIG_EXTRA_COMPAT \
  113. | grep -v CONFIG_FEATURE_2_4_MODULES \
  114. | grep -v CONFIG_FEATURE_VI_REGEX_SEARCH \
  115. | grep -v CONFIG_FEATURE_MOUNT_NFS \
  116. | grep -v CONFIG_FEATURE_INETD_RPC \
  117. >.config.new
  118. mv .config.new .config
  119. echo 'CONFIG_STATIC=y' >>.config
  120. # "error: cannot specify -static with -fsanitize=address":
  121. echo '# CONFIG_DEBUG_SANITIZE is not set' >>.config
  122. # with LFS off, uoff_t will have wrong width:
  123. echo 'CONFIG_LFS=y' >>.config
  124. echo '# CONFIG_EXTRA_COMPAT is not set' >>.config
  125. echo '# CONFIG_FEATURE_2_4_MODULES is not set' >>.config
  126. echo '# CONFIG_FEATURE_VI_REGEX_SEARCH is not set' >>.config
  127. echo '# CONFIG_FEATURE_MOUNT_NFS is not set' >>.config
  128. echo '# CONFIG_FEATURE_INETD_RPC is not set' >>.config
  129. fi
  130. # If STATIC, remove some things.
  131. # PAM with static linking is probably pointless
  132. # (but I need to try - now I don't have libpam.a on my system, only libpam.so)
  133. if grep -q "^CONFIG_STATIC=y" .config; then
  134. cat .config \
  135. | grep -v CONFIG_PAM \
  136. >.config.new
  137. mv .config.new .config
  138. echo '# CONFIG_PAM is not set' >>.config
  139. fi
  140. # Regenerate .config with default answers for yanked-off options
  141. # (most of default answers are "no").
  142. { yes "" | make oldconfig >/dev/null; } || { echo "oldconfig error"; exit 1; }
  143. # Build!
  144. nice -n 10 make $MAKEOPTS 2>&1 | tee make.log
  145. grep 'Rerun make' make.log \
  146. && nice -n 10 make $MAKEOPTS 2>&1 | tee -a make.log
  147. # Return exitcode 1 if busybox executable does not exist
  148. test -x busybox