autogen.sh 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #! /bin/sh
  2. # Copyright (C) 2003-2008 Gary Kramlich <grim@reaperworld.com>
  3. #
  4. # This program is free software; you can redistribute it and/or modify it
  5. # under the terms of the GNU General Public License as published by the Free
  6. # Software Foundation; either version 2 of the License, or (at your option)
  7. # any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful, but WITHOUT
  10. # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12. # more details.
  13. #
  14. # You should have received a copy of the GNU General Public License along with
  15. # this program; if not, write to the Free Software Foundation, Inc., 51
  16. # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  17. ###############################################################################
  18. # Usage
  19. ###############################################################################
  20. # This script uses a config file that can be used to stash common arguments
  21. # passed to configure or environment variables that need to be set before
  22. # configure is called. The configuration file is a simple shell script that
  23. # gets sourced.
  24. #
  25. # By default, the config file that is used is named 'autogen.args'. This can
  26. # be configured below.
  27. #
  28. # Available options that are handled are as follow:
  29. # ACLOCAL_FLAGS - command line arguments to pass to aclocal
  30. # AUTOCONF_FLAGS - command line arguments to pass to autoconf
  31. # AUTOHEADER_FLAGS - command line arguments to pass to autoheader
  32. # AUTOMAKE_FLAGS - command line arguments to pass to automake flags
  33. # CONFIGURE_FLAGS - command line arguments to pass to configure
  34. # GLIB_GETTEXTIZE_FLAGS - command line arguments to pass to glib-gettextize
  35. # LIBTOOLIZE_FLAGS - command line arguments to pass to libtoolize
  36. #
  37. # Other helpful notes:
  38. # If you're using a different c compiler, you can override the environment
  39. # variable in 'autogen.args'. For example, say you're using distcc, just add
  40. # the following to 'autogen.args':
  41. #
  42. # CC="distcc"
  43. #
  44. # This will work for any influential environment variable to configure.
  45. ###############################################################################
  46. PACKAGE="docsis"
  47. ARGS_FILE="autogen.args"
  48. export CFLAGS
  49. export LDFLAGS
  50. libtoolize="libtoolize"
  51. case $(uname -s) in
  52. Darwin*)
  53. libtoolize="glibtoolize"
  54. ;;
  55. *)
  56. esac
  57. ###############################################################################
  58. # Some helper functions
  59. ###############################################################################
  60. check () {
  61. CMD=$1
  62. printf "%s" "checking for ${CMD}... "
  63. BIN=`which ${CMD} 2>/dev/null`
  64. if [ x"${BIN}" = x"" ] ; then
  65. echo "not found."
  66. echo "${CMD} is required to build ${PACKAGE}!"
  67. exit 1;
  68. fi
  69. echo "${BIN}"
  70. }
  71. run_or_die () { # beotch
  72. CMD=$1
  73. shift
  74. OUTPUT=`mktemp autogen-XXXXXX`
  75. printf "running %s %s... " ${CMD} "$*"
  76. ${CMD} ${@} >${OUTPUT} 2>&1
  77. if [ $? != 0 ] ; then
  78. echo "failed."
  79. cat ${OUTPUT}
  80. rm -f ${OUTPUT}
  81. exit 1
  82. else
  83. echo "done."
  84. cat ${OUTPUT}
  85. rm -f ${OUTPUT}
  86. fi
  87. }
  88. cleanup () {
  89. rm -f autogen-??????
  90. echo
  91. exit 2
  92. }
  93. ###############################################################################
  94. # We really start here, yes, very sneaky!
  95. ###############################################################################
  96. trap cleanup 2
  97. FIGLET=`which figlet 2> /dev/null`
  98. if [ x"${FIGLET}" != x"" ] ; then
  99. ${FIGLET} -f small ${PACKAGE}
  100. echo "build system is being generated"
  101. else
  102. echo "autogenerating build system for '${PACKAGE}'"
  103. fi
  104. ###############################################################################
  105. # Look for our args file
  106. ###############################################################################
  107. printf "%s" "checking for ${ARGS_FILE}: "
  108. if [ -f ${ARGS_FILE} ] ; then
  109. echo "found."
  110. printf "%s" "sourcing ${ARGS_FILE}: "
  111. . "`dirname "$0"`"/${ARGS_FILE}
  112. echo "done."
  113. else
  114. echo "not found."
  115. fi
  116. ###############################################################################
  117. # Check for our required helpers
  118. ###############################################################################
  119. check "$libtoolize"; LIBTOOLIZE=${BIN};
  120. check "glib-gettextize"; GLIB_GETTEXTIZE=${BIN};
  121. check "sed"; SED=${BIN};
  122. check "aclocal"; ACLOCAL=${BIN};
  123. check "autoheader"; AUTOHEADER=${BIN};
  124. check "automake"; AUTOMAKE=${BIN};
  125. check "autoconf"; AUTOCONF=${BIN};
  126. ###############################################################################
  127. # Run all of our helpers
  128. ###############################################################################
  129. run_or_die ${LIBTOOLIZE} ${LIBTOOLIZE_FLAGS:-"-c -f --automake"}
  130. run_or_die ${GLIB_GETTEXTIZE} ${GLIB_GETTEXTIZE_FLAGS:-"--force --copy"}
  131. run_or_die ${ACLOCAL} ${ACLOCAL_FLAGS}
  132. run_or_die ${AUTOHEADER} ${AUTOHEADER_FLAGS}
  133. run_or_die ${AUTOMAKE} ${AUTOMAKE_FLAGS:-"-a -c --gnu"}
  134. run_or_die ${AUTOCONF} ${AUTOCONF_FLAGS}
  135. ###############################################################################
  136. # Run configure
  137. ###############################################################################
  138. echo "running ./configure ${CONFIGURE_FLAGS} $@"
  139. ./configure ${CONFIGURE_FLAGS} $@