build_functions 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. # Auxiliary functions for build.sh
  2. # Copyright (c) 2002 Serge van den Boom
  3. #
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation; either version 2 of the License, or
  7. # (at your option) any later version.
  8. #
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. # GNU General Public License for more details.
  13. #
  14. # You should have received a copy of the GNU General Public License
  15. # along with this program; if not, write to the Free Software
  16. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. # Show usage information
  18. usage() {
  19. echo "Main build script"
  20. echo
  21. echo "Syntax:"
  22. echo " ./build <target>"
  23. echo " ./build <target> config"
  24. echo " ./build <target> depend"
  25. echo " ./build <target> clean"
  26. echo " ./build <target> install"
  27. echo " ./build cleanall"
  28. echo " ./build distclean"
  29. echo
  30. echo "Valid targets:"
  31. for TARGET in $TARGETS; do
  32. echo " $TARGET"
  33. done
  34. echo
  35. }
  36. # The actual recursing function
  37. build_recurse() {
  38. local FILES SUBDIRS
  39. # Perform an action for this dir
  40. eval FILES="\${$BUILD_FILES_VAR}"
  41. for FILE in $FILES; do
  42. $BUILD_REC_COMMAND "$BUILD_REC_PATH$FILE"
  43. done
  44. # Recurse for all subdirs
  45. eval SUBDIRS="\$${BUILD_PROJECT}_SUBDIRS"
  46. for DIR in $SUBDIRS; do
  47. BUILD_REC_PATH="$BUILD_REC_PATH$DIR/" $SH "$0"
  48. $BUILD_REC_DIR_COMMAND "$BUILD_REC_PATH$DIR"
  49. done
  50. }
  51. # Start the recursion
  52. build_do_recursive() {
  53. BUILD_COMMAND=build_recurse
  54. BUILD_REC_COMMAND="$1"
  55. BUILD_REC_DIR_COMMAND="$2"
  56. export BUILD_COMMAND BUILD_REC_COMMAND BUILD_REC_DIR_COMMAND
  57. build_recurse
  58. }
  59. # Build dependancy information for one file
  60. build_dependancies() {
  61. eval echo -n \${${BUILD_PROJECT}_OBJS}\$BUILD_REC_PATH
  62. eval \$MKDEPEND "\${${BUILD_PROJECT}_CFLAGS}" "\$1"
  63. }
  64. # Recursively build dependancy information
  65. build_rec_dependancies() {
  66. local DEPEND_FILE
  67. echo "Building dependancy information..." 1>&2
  68. BUILD_FILES_VAR=${BUILD_PROJECT}_CFILES
  69. export BUILD_FILES_VAR
  70. OFILES=`build_do_recursive build_collect_o_files :`
  71. eval DEPEND_FILE=".depend.\${${BUILD_PROJECT}_NAME}"
  72. {
  73. eval echo -n "target-\${${BUILD_PROJECT}_NAME}:"
  74. for OFILE in $OFILES; do
  75. echo -n " $OFILE"
  76. done
  77. echo
  78. build_do_recursive build_dependancies :
  79. } > "$DEPEND_FILE"
  80. }
  81. # Output the .o file for a .c file.
  82. build_collect_o_files() {
  83. eval echo "\${${BUILD_PROJECT}_OBJS}\${1%.c}.o"
  84. }
  85. # Recursively collect .o-files
  86. build_rec_collect_o_files() {
  87. BUILD_FILES_VAR=${BUILD_PROJECT}_CFILES
  88. export BUILD_FILES_VAR
  89. build_do_recursive build_collect_o_files :
  90. }
  91. # Start the configure program.
  92. build_config() {
  93. $SH build/build.config
  94. }
  95. # Compile the lot.
  96. # With the depend info set up, we can leave everything to make.
  97. build_compile() {
  98. eval CFLAGS="\${${BUILD_PROJECT}_CFLAGS}" \
  99. LDFLAGS="\${${BUILD_PROJECT}_LDFLAGS}" \
  100. DEPEND_FILE=".depend.\${${BUILD_PROJECT}_NAME%/}" \
  101. \$MAKE -f Makefile.build "target-\${${BUILD_PROJECT}_NAME}"
  102. }
  103. # Description: Remove the .o file for one .c file
  104. # Arguments: $1 - the .c file
  105. build_clean_file() {
  106. eval rm -f -- "\${${BUILD_PROJECT}_OBJS}\${1%.c}.o"
  107. }
  108. build_clean_dir() {
  109. eval rmdir -- "\${${BUILD_PROJECT}_OBJS}\${1}" 2> /dev/null
  110. return 0
  111. }
  112. build_clean() {
  113. local DEPEND_FILE
  114. eval DEPEND_FILE=".depend.\${${BUILD_PROJECT}_NAME%/}"
  115. rm -f "$DEPEND_FILE" build.vars config.state src/config.h
  116. BUILD_FILES_VAR=${BUILD_PROJECT}_CFILES
  117. export BUILD_FILES_VAR
  118. build_do_recursive build_clean_file build_clean_dir
  119. }
  120. build_cleanall() {
  121. for TARGET in $TARGETS; do
  122. build_clean "$TARGET"
  123. done
  124. }
  125. build_distclean() {
  126. build_cleanall
  127. rm configure
  128. }
  129. # Description: check if the config files are present and load them.
  130. # If they're not present, remake them.
  131. build_check_config() {
  132. [ ! -e build.vars -o -n "$BUILD_RUN_CONFIG" ] || return
  133. build_config || exit $?
  134. . build.vars
  135. . "${BUILD_REC_PATH}Makeinfo"
  136. unset BUILD_RUN_CONFIG
  137. }
  138. # Description: check if the necessary .depend file is present,
  139. # if not, build it.
  140. build_check_dependencies() {
  141. eval DEPEND_FILE=".depend.\${${BUILD_PROJECT}_NAME}"
  142. [ ! -e "$DEPEND_FILE" -o -n "$BUILD_RUN_DEPEND" ] || return
  143. build_rec_dependancies || exit $?
  144. }
  145. # Description: check if the program is compiled, and otherwise compile
  146. build_check_compile() {
  147. local NAME
  148. eval NAME="\${${BUILD_PROJECT}_NAME}"
  149. [ ! -e "$NAME" ] || return
  150. build_compile || exit $?
  151. }
  152. # Install the program
  153. build_install() {
  154. local BINS LIBS SRC DEST BINDIR LIBDIR
  155. echo "Installing libraries..." 2>&1
  156. eval LIBS="\${${BUILD_PROJECT}_INSTALL_LIBS}"
  157. eval LIBDIR="\${${BUILD_PROJECT}_INSTALL_LIBDIR%/}/"
  158. for LIB in $LIBS; do
  159. eval SRC="\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_SRC%/}"
  160. eval DEST="\$LIBDIR\${${BUILD_PROJECT}_INSTALL_LIB_${LIB}_DEST%/}"
  161. if [ ! -d "$DEST" ]; then
  162. mkdir -p -- "$DEST"
  163. fi
  164. cp -r -- "$SRC" "$DEST"
  165. done
  166. echo "Installing binaries..." 2>&1
  167. eval BINS="\${${BUILD_PROJECT}_INSTALL_BINS}"
  168. eval BINDIR="\${${BUILD_PROJECT}_INSTALL_BINDIR%/}/"
  169. for BIN in $BINS; do
  170. eval SRC="\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_SRC%/}"
  171. eval DEST="\$BINDIR\${${BUILD_PROJECT}_INSTALL_BIN_${BIN}_DEST%/}"
  172. if [ ! -d "$DEST" ]; then
  173. mkdir -p -- "$DEST"
  174. fi
  175. cp -r -- "$SRC" "$DEST"
  176. done
  177. }