NoPaste

Re: ERROR: No C compiler found

von TRex
SNIPPET_DESC:
https://debianforum.de/forum/posting.php?mode=edit&f=34&p=1228572
SNIPPET_CREATION_TIME:
26.01.2020 18:19:38
SNIPPET_PRUNE_TIME:
Unendlich

SNIPPET_TEXT:
  1. #!/bin/bash
  2. #
  3. # Generic/Simple configure script
  4. #
  5. # Copyright (c) 2012 Adam Sutton <dev@adamsutton.me.uk>
  6. #
  7.  
  8. # ###########################################################################
  9. # Defaults
  10. # ###########################################################################
  11.  
  12. CONFIGURE_ARGS="$*"
  13.  
  14. # Compiler
  15. [ -z "$CC"       ] && CC=cc
  16. [ -z "$CFLAGS"   ] && CFLAGS=
  17. [ -z "$LDFLAGS"  ] && LDFLAGS=
  18.  
  19. # System setup
  20. [ -z "$PLATFORM" ] && PLATFORM=$(uname -s | tr "[:upper:]" "[:lower:]")
  21. [ -z "$CPU"      ] && CPU=generic
  22. [ -z "$ARCH"     ] && ARCH=$($CC -dumpmachine | cut -d '-' -f 1)
  23. [ -z "$ARCH"     ] && ARCH=$(uname -m)
  24. [ -z "$OSENV"    ] && OSENV=posix
  25. [ -z "$PYTHON"   ] && PYTHON=python
  26. [ -z "$GZIPCMD"  ] && GZIPCMD=gzip
  27. [ -z "$BZIP2"    ] && BZIP2=bzip2
  28. [ -z "$XGETTEXT" ] && XGETTEXT=xgettext
  29. [ -z "$MSGMERGE" ] && MSGMERGE=msgmerge
  30.  
  31. # Paths
  32. [ -z "$prefix"   ] && prefix=/usr/local
  33. [ -z "$bindir"   ] && bindir=\${prefix}/bin
  34. [ -z "$libdir"   ] && libdir=\${prefix}/lib
  35. [ -z "$datadir"  ] && datadir=\${prefix}/share
  36. [ -z "$mandir"   ] && mandir=\${datadir}/man
  37.  
  38. # Environment
  39. [ -z "$ROOTDIR"  ] && ROOTDIR=$(cd "$(dirname "$0")"; pwd)
  40. [ -z "$BUILDDIR" ] && BUILDDIR=$ROOTDIR/build.$PLATFORM
  41. [ -z "$TMPDIR"   ] && TMPDIR=/tmp
  42.  
  43. # Options/Package Lists
  44. [ -z "$OPTIONS"  ] && OPTIONS=()
  45. [ -z "$PACKAGES" ] && PACKAGES=()
  46.  
  47. # ###########################################################################
  48. # Utilities
  49. # ###########################################################################
  50.  
  51. # Output
  52. TAB="  %-50s"
  53.  
  54. # Text conversion
  55. toupper ()
  56. {
  57.   echo "$@" | tr abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ
  58. }
  59.  
  60. # Terminate
  61. die ()
  62. {
  63.   echo >&2 "ERROR: $@"
  64.   exit 1
  65. }
  66.  
  67. # ###########################################################################
  68. # Enable/Disable
  69. # ###########################################################################
  70.  
  71. # Enable/Disable option
  72. _enable ()
  73. {
  74.   local opt=$1 val=$2 ignore=$3 row= k= v=
  75.   for row in ${OPTIONS[*]}; do
  76.     k=${row%:*}
  77.     [ "$k" = "$opt" ] || continue
  78.     v=${row#*:}
  79.     if [ $v != "$val" ]; then
  80.       OPTIONS=(${OPTIONS[@]//$row/$k:$val})
  81.     fi
  82.     return
  83.   done
  84.   [ -z "$ignore" ] && OPTIONS=(${OPTIONS[@]} $opt:$val)
  85. }
  86.  
  87. # Enable option
  88. enable ()
  89. {
  90.   _enable $1 yes $2
  91. }
  92.  
  93. # Disable option
  94. disable ()
  95. {
  96.   _enable $1 no $2
  97. }
  98.  
  99. # Enable package
  100. enable_pkg ()
  101. {
  102.   local opt=$1 row= k= v=
  103.   for row in ${PACKAGES[*]}; do
  104.     [ "$row" = "$opt" ] && return
  105.   done
  106.   PACKAGES=(${PACKAGES[@]} $opt)
  107. }
  108.  
  109. # Get enabled state
  110. _enabled ()
  111. {
  112.   local opt=$1 row= k=
  113.   for row in ${OPTIONS[*]}; do
  114.     k=${row%:*}
  115.     [ "$k" = "$opt" ] || continue
  116.     echo ${row#*:}
  117.     return
  118.   done
  119.   echo "no"
  120. }
  121.  
  122. # Check if enabled
  123. enabled ()
  124. {
  125.   local val=$(_enabled $1)
  126.   [ "$val" = "yes" ] && return 0 || return 1
  127. }
  128.  
  129. # Check if disabled
  130. disabled ()
  131. {
  132.   local val=$(_enabled $1)
  133.   [ "$val" = "no" ] && return 0 || return 1
  134. }
  135.  
  136. # Check if enabled (or auto)
  137. enabled_or_auto ()
  138. {
  139.   local val=$(_enabled $1)
  140.   [ "$val" = "yes" -o "$val" = "auto" ] && return 0 || return 1
  141. }
  142.  
  143. # Check if disabled (or auto)
  144. disabled_or_auto ()
  145. {
  146.   local val=$(_enabled $1)
  147.   [ "$val" = "no" -o "$val" = "auto" ] && return 0 || return 1
  148. }
  149.  
  150. # ###########################################################################
  151. # Command Line
  152. # ###########################################################################
  153.  
  154. # Show help
  155. show_help ()
  156. {
  157.   local opt= val= fmt="%-30s"
  158.   echo "Usage: $0 [options]"
  159.   echo ""
  160.   echo "Miscellaneous"
  161.   printf "  $fmt Print this message\n" "--help"
  162.   echo ""
  163.   echo "Installation Paths"
  164.   printf "  $fmt Installation root [$prefix]\n" "--prefix=DIR$"
  165.   printf "  $fmt Install binaries in DIR [$bindir]\n" "--bindir=DIR"
  166.   printf "  $fmt Install libraries in DIR [$libdir]\n" "--libdir=DIR"
  167.   printf "  $fmt Install man pages in DIR [$mandir]\n" "--mandir=DIR"
  168.   printf "  $fmt Install data files in DIR [$datadir]\n" "--datadir=DIR"
  169.   echo ""
  170.   echo "Compiler/Arch"
  171.   printf "  $fmt Build using compiler [$CC]\n" "--cc=CC"
  172.   printf "  $fmt Build using C flags\n" "--cflags=CFLAGS"
  173.   printf "  $fmt Build using LD flags\n" "--ldflags=LDFLAGS"
  174.   printf "  $fmt Build and optimize for specific CPU\n" "--cpu=CPU"
  175.   printf "  $fmt Build for architecture [$ARCH]\n" "--arch=ARCH"
  176.   printf "  $fmt Build for platform [$PLATFORM]\n" "--platform=PLATFORM"
  177.   printf "  $fmt Build without -Werror CFLAGS\n" "--nowerror"
  178.   printf "  $fmt Use python binary [$PYTHON]\n" "--python=PYTHON"
  179.   echo ""
  180.   echo "Options"
  181.   for opt in ${OPTIONS[*]}; do
  182.     val=${opt#*:}
  183.     opt=${opt%:*}
  184.     if [ "$val" = "yes" ]; then
  185.       printf "  $fmt Disable ${opt}\n" "--disable-${opt}"
  186.     elif [ "$val" = "no" ]; then
  187.       printf "  $fmt Enable ${opt}\n" "--enable-${opt}"
  188.     else
  189.       printf "  $fmt Disable ${opt}\n" "--disable-${opt}"
  190.       printf "  $fmt Enable ${opt}\n" "--enable-${opt}"
  191.     fi
  192.   done
  193.   exit 0
  194. }
  195.  
  196. # ###########################################################################
  197. # Package tests
  198. # ###########################################################################
  199.  
  200. # Check package
  201. check_pkg ()
  202. {
  203.   local pkg=$1; shift
  204.   local ver=$*
  205.  
  206.   # Version test
  207.   cver=$(echo $ver | sed 's/>=/ --atleast-version /'\
  208.                   | sed 's/<=/ --max-version /'\
  209.                   | sed 's/==/ --exact-version /')
  210.  
  211.   printf "$TAB" "checking for pkg $pkg $ver ..."
  212.  
  213.   dver=$(${PKG_CONFIG} --modversion $pkg 2> /dev/null)
  214.   test -z "$dver" && dver="<none>"
  215.  
  216.   # Check for package
  217.   if ${PKG_CONFIG} $pkg $cver; then
  218.     echo "ok (detected ${dver})"
  219.     enable_pkg $pkg
  220.   else
  221.     echo "fail (detected ${dver})"
  222.     return 1
  223.   fi
  224. }
  225.  
  226. # ###########################################################################
  227. # Compiler Tests
  228. # ###########################################################################
  229.  
  230. # Check compiler
  231. check_cc ()
  232. {
  233.   local hdr=$1
  234.   local opt=$2
  235.   cat >$TMPDIR/$$.c <<EOF
  236. $hdr
  237. int main() {
  238. #ifdef TEST
  239.   return TEST();
  240. #else
  241.   return 0;
  242. #endif
  243. }
  244. EOF
  245.   $CC $CFLAGS $LDFLAGS $TMPDIR/$$.c -o $TMPDIR/$$.bin $opt > /dev/null 2>&1
  246.   RET=$?
  247.   rm -f $TMPDIR/$$.{c,bin}
  248.   return $RET
  249. }
  250.  
  251. # Check compiler header
  252. check_cc_header ()
  253. {
  254.   local hdr=$1
  255.   local nam=$2
  256.   [ -z "$nam" ] && nam=$hdr
  257.  
  258.   printf "$TAB" "checking for cc $hdr.h ..."
  259.  
  260.   # Enable if supported
  261.   if check_cc "#include <$1.h>"; then
  262.     echo "ok"
  263.     enable $nam
  264.   else
  265.     echo "fail"
  266.     return 1
  267.   fi
  268. }
  269.  
  270. # Check some compiler snippet
  271. check_cc_snippet ()
  272. {
  273.   local nam=$1
  274.   local snp=$2
  275.   local opt=$3
  276.  
  277.   printf "$TAB" "checking for cc $nam ..."
  278.  
  279.   # Check if supported
  280.   if check_cc "$snp" "$opt"; then
  281.     echo "ok"
  282.     enable $nam
  283.   else
  284.     echo "fail"
  285.     return 1
  286.   fi
  287. }
  288.  
  289. # Check compiler option
  290. check_cc_option ()
  291. {
  292.   local opt=$1
  293.   local nam=$2
  294.   [ -z "$nam" ] && nam=$opt
  295.  
  296.   printf "$TAB" "checking for cc -m$opt ..."
  297.  
  298.   # Enable if supported
  299.   if check_cc "" -m${opt}; then
  300.     echo "ok"
  301.     enable $nam
  302.   else
  303.     echo "fail"
  304.     return 1
  305.   fi
  306. }
  307.  
  308. # Check compiler option
  309. check_cc_optionW ()
  310. {
  311.   local opt=$1
  312.   local nam=$2
  313.   [ -z "$nam" ] && nam=$opt
  314.   nam=$(echo "W_$nam" | sed -e 's/-/_/')
  315.  
  316.   printf "$TAB" "checking for cc -W$opt ..."
  317.  
  318.   # Enable if supported
  319.   if check_cc "" -W${opt}; then
  320.     echo "ok"
  321.     enable $nam
  322.   else
  323.     echo "fail"
  324.     return 1
  325.   fi
  326. }
  327.  
  328. # Check compiler option
  329. check_cc_optionf ()
  330. {
  331.   local opt=$1
  332.   local nam=$2
  333.   [ -z "$nam" ] && nam=$opt
  334.   nam=$(echo "f_$nam" | sed -e 's/[-=]/_/g')
  335.  
  336.   printf "$TAB" "checking for cc -f$opt ..."
  337.  
  338.   # Enable if supported
  339.   if check_cc "" -f${opt}; then
  340.     echo "ok"
  341.     enable $nam
  342.   else
  343.     echo "fail"
  344.     return 1
  345.   fi
  346. }
  347.  
  348.  
  349. # Check compiler library
  350. check_cc_lib ()
  351. {
  352.   local opt=$1
  353.   local nam=$2
  354.   [ -z "$nam" ] && nam=$opt
  355.  
  356.   printf "$TAB" "checking for cc -l$opt ..."
  357.  
  358.   # Enable if supported
  359.   if check_cc "" -l${opt}; then
  360.     echo "ok"
  361.     enable $nam
  362.   else
  363.     echo "fail"
  364.     return 1
  365.   fi
  366. }
  367.  
  368. # ###########################################################################
  369. # Python tests
  370. # ###########################################################################
  371.  
  372. # Check python
  373. check_py ()
  374. {
  375.   local hdr=$1
  376.   cat >$TMPDIR/$$.py <<EOF
  377. $hdr
  378. EOF
  379.   $PYTHON $TMPDIR/$$.py > /dev/null 2>&1
  380.   RET=$?
  381.   rm -f $TMPDIR/$$.py
  382.   return $RET
  383. }
  384.  
  385. # Check python import
  386. check_py_import ()
  387. {
  388.   local hdr=$1
  389.   local nam=$2
  390.   [ -z "$nam" ] && nam=py_${hdr}
  391.  
  392.   printf "$TAB" "checking for py module $hdr ..."
  393.  
  394.   # Enable if supported
  395.   if check_py "import $hdr"; then
  396.     echo "ok"
  397.     enable $nam
  398.   else
  399.     echo "fail"
  400.     return 1
  401.   fi
  402. }
  403.  
  404. # ###########################################################################
  405. # Binary checks
  406. # ###########################################################################
  407.  
  408. check_bin ()
  409. {
  410.   local bin=$1
  411.   local nam=$2
  412.   [ -z "$nam" ] && nam=bin_${bin}
  413.   printf "$TAB" "checking for $bin ..."
  414.  
  415.   if which $bin &> /dev/null; then
  416.     echo "ok"
  417.     enable $nam
  418.   else
  419.     echo "fail"
  420.     return 1
  421.   fi
  422. }
  423.  
  424. # ###########################################################################
  425. # Config output
  426. # ###########################################################################
  427.  
  428. # Print config
  429. print_config ()
  430. {
  431.   local pkg= fmt="  %-40s %s\n"
  432.  
  433.   # Compiler settings
  434.   echo ""
  435.   echo "Compiler:"
  436.   printf "$fmt" "Using C compiler:" "${CC}"
  437.   if [ "${CFLAGS}" != "" ]; then
  438.      printf "$fmt" "Using C flags:" "${CFLAGS}"
  439.   fi
  440.   if [ "${LDFLAGS}" != "" ]; then
  441.      printf "$fmt" "Using LD flags:" "${LDFLAGS}"
  442.   fi
  443.   printf "$fmt" "Build for arch:" "${ARCH}"
  444.   echo ""
  445.  
  446.   echo "Binaries:"
  447.   printf "$fmt" "Using PYTHON:" "${PYTHON}"
  448.   printf "$fmt" "Using GZIP:" "${GZIPCMD}"
  449.   printf "$fmt" "Using BZIP2:" "${BZIP2}"
  450.   echo ""
  451.  
  452.   # Options
  453.   echo "Options:"
  454.   for opt in ${OPTIONS[*]}; do
  455.     k=${opt%:*}
  456.     v=${opt#*:}
  457.     if [ "$v" = "yes" ]; then
  458.       printf "$fmt" "$k" "yes"
  459.     else
  460.       printf "$fmt" "$k" "no"
  461.     fi
  462.   done
  463.   echo ""
  464.  
  465.   # Packages
  466.   echo "Packages:"
  467.   for pkg in ${PACKAGES[*]}; do
  468.     printf "$fmt" "${pkg}" "$(${PKG_CONFIG} --modversion $pkg)"
  469.   done
  470.   echo ""
  471.  
  472.   # Installation
  473.   echo "Installation paths:"
  474.   printf "$fmt" "Prefix:" "${prefix}"
  475.   printf "$fmt" "Binaries:" "${bindir}"
  476.   printf "$fmt" "Libraries:" "${libdir}"
  477.   printf "$fmt" "Data files:" "${datadir}"
  478.   printf "$fmt" "Man pages:" "${mandir}"
  479.   echo ""
  480. }
  481.  
  482. # Write configuration
  483. write_config ()
  484. {
  485.   local pkg= opt= k= v=
  486.  
  487.   # Create build directory
  488.   mkdir -p "${BUILDDIR}"
  489.   BUILDDIR=$(cd "${BUILDDIR}" && pwd)
  490.  
  491.   # Create make include
  492.   CONFIG_MK=${ROOTDIR}/.config.mk
  493.   cat > "${CONFIG_MK}" <<EOF
  494. # Automatically generated by configure - DO NOT EDIT!
  495. CONFIGURE_ARGS = ${CONFIGURE_ARGS}
  496. ROOTDIR  ?= ${ROOTDIR}
  497. BUILDDIR ?= ${BUILDDIR}
  498. PLATFORM ?= ${PLATFORM}
  499. OSENV    ?= ${OSENV}
  500. ARCH     ?= ${ARCH}
  501. CPU      ?= ${CPU}
  502. COMPILER ?= ${COMPILER}
  503. ifeq (\$(origin CC),default)
  504. CC        = ${CC}
  505. endif
  506. PYTHON   ?= ${PYTHON}
  507. GZIPCMD  ?= ${GZIPCMD}
  508. BZIP2    ?= ${BZIP2}
  509. XGETTEXT ?= ${XGETTEXT}
  510. MSGMERGE ?= ${MSGMERGE}
  511. PKG_CONFIG ?= ${PKG_CONFIG}
  512. CFLAGS   += ${CFLAGS}
  513. LDFLAGS  += ${LDFLAGS}
  514. prefix    = ${prefix}
  515. bindir    = ${bindir}
  516. mandir    = ${mandir}
  517. datadir   = ${datadir}
  518. libdir    = ${libdir}
  519. EOF
  520.  
  521.   # no -Werror
  522.   if test -n "${NOWERROR}"; then
  523.     echo "CFLAGS_NO_WERROR = yes" >> "${CONFIG_MK}"
  524.   fi
  525.  
  526.   # Create C include
  527.   CONFIG_H="${BUILDDIR}/build.h"
  528.   cat > "${CONFIG_H}" <<EOF
  529. // Automatically generated by configure - DO NOT EDIT!
  530. EOF
  531.  
  532.   # Create Platform defines
  533.   cat > ${CONFIG_H} <<EOF
  534. #define PLATFORM_$(toupper ${PLATFORM}) 1
  535. EOF
  536.  
  537.   # Add package config
  538.   for pkg in ${PACKAGES[*]}; do
  539.     cat >>"${CONFIG_MK}" <<EOF
  540. LDFLAGS += $(${PKG_CONFIG} --libs $pkg)
  541. CFLAGS  += $(${PKG_CONFIG} --cflags $pkg)
  542. EOF
  543.   done
  544.  
  545.   # Add configuration
  546.   for row in ${OPTIONS[*]}; do
  547.     k=$(toupper ${row%:*})
  548.     v=${row#*:}
  549.     if [ "$v" = "yes" ]; then
  550.       cat >>"${CONFIG_H}" <<EOF
  551. #define ENABLE_${k} 1
  552. #define CONFIG_${k} 1
  553. EOF
  554.       cat >>"${CONFIG_MK}" <<EOF
  555. CONFIG_${k} = yes
  556. EOF
  557.     else
  558.       cat >>"${CONFIG_H}" <<EOF
  559. #define ENABLE_${k} 0
  560. EOF
  561.       cat >>"${CONFIG_MK}" <<EOF
  562. CONFIG_${k} = no
  563. EOF
  564.     fi
  565.   done
  566.  
  567.   # Add build config string declaration
  568.   cat >> "${CONFIG_H}" <<EOF
  569. #define DESCRAMBLER_MAX_KEYS 8
  570. EOF
  571.  
  572.   # Add build config string declaration
  573.   cat >> "${CONFIG_H}" <<EOF
  574. extern const char* build_config_str;
  575. extern const char* build_timestamp;
  576. EOF
  577.  
  578.   # Create C source
  579.   CONFIG_C="${BUILDDIR}/build.c"
  580.   cat > "${CONFIG_C}" <<EOF
  581. // Automatically generated by configure - DO NOT EDIT!
  582.  
  583. #include "build.h"
  584.  
  585. const char* build_config_str =
  586. EOF
  587.  
  588.   # Add configure command
  589.   echo "  \"Configure arguments:\\n\"" >> "${CONFIG_C}"
  590.   echo "  ${CONFIGURE_ARGS}" | sed -e 's/"/\\"/g' | sed -e 's/.*/  "\0" "\\n"/g' >> "${CONFIG_C}"
  591.  
  592.   # Add build config string
  593.   print_config | sed -e 's/"/\\"/g' | sed -e 's/.*/  "\0" "\\n"/g' >> "${CONFIG_C}"
  594.   echo '  "";' >> "${CONFIG_C}"
  595. }

Quellcode

Hier kannst du den Code kopieren und ihn in deinen bevorzugten Editor einfügen. PASTEBIN_DOWNLOAD_SNIPPET_EXPLAIN