BUILD 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. #!/bin/bash
  2. #BUILD script
  3. #
  4. #Copyright (C) 2015 Rafael
  5. #
  6. #This program is free software; you can redistribute it and/or modify
  7. #it under the terms of the GNU General Public License as published by
  8. #the Free Software Foundation; either version 2 of the License, or
  9. #(at your option) any later version.
  10. #
  11. #This program is distributed in the hope that it will be useful,
  12. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. #GNU General Public License for more details.
  15. #
  16. #You should have received a copy of the GNU General Public License along
  17. #with this program; if not, write to the Free Software Foundation, Inc.,
  18. #51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19. #
  20. #
  21. #Search for config:
  22. _BUILD_DIR=`dirname $0`
  23. export _BUILD_DIR=$(cd "$_BUILD_DIR"; pwd)
  24. . ${_BUILD_DIR}/BUILD.conf
  25. compile_kernel()
  26. {
  27. export HARVEY="$_BUILD_DIR"
  28. cd "$KRL_DIR"
  29. $HARVEY/util/build $KERNEL_CONF.json
  30. cd "$PATH_ORI" > /dev/null
  31. }
  32. build_kernel()
  33. {
  34. compile_kernel
  35. if [ $? -ne 0 ]; then
  36. echo "SOMETHING WENT WRONG!"
  37. else
  38. echo "KERNEL COMPILED OK"
  39. fi
  40. }
  41. build_go_utils()
  42. {
  43. cd "${UTIL_DIR}"
  44. for i in `ls *.go`
  45. do
  46. go build $i
  47. if [ $? -ne 0 ]
  48. then
  49. printf "\nERROR compiling $i \n"
  50. exit 1
  51. fi
  52. done
  53. cd - > /dev/null
  54. }
  55. check_utils()
  56. {
  57. if [ -f "${UTIL_DIR}"/mksys ]
  58. then
  59. echo 0
  60. else
  61. echo 1
  62. fi
  63. }
  64. build_libs()
  65. {
  66. export HARVEY="$_BUILD_DIR"
  67. cd "$SRC_DIR"
  68. $HARVEY/util/build libs.json
  69. cd "$PATH_ORI" > /dev/null
  70. }
  71. build_klibs()
  72. {
  73. export HARVEY="$_BUILD_DIR"
  74. cd "$SRC_DIR"
  75. $HARVEY/util/build klibs.json
  76. cd "$PATH_ORI" > /dev/null
  77. }
  78. build_cmds()
  79. {
  80. export HARVEY="$_BUILD_DIR"
  81. cd "$CMD_DIR"
  82. $HARVEY/util/build cmds.json
  83. $HARVEY/util/build kcmds.json
  84. cd "$PATH_ORI" > /dev/null
  85. }
  86. show_help()
  87. {
  88. printf "\n\nBUILD script for Harvey\n\n"
  89. printf "OPTIONS:\n"
  90. printf " all \tBuild all components\n"
  91. printf " cleanall \tClean all components\n"
  92. printf " libs \tBuild the libraries\n"
  93. printf " libs <libname>\tBuild the library <libname>\n"
  94. printf " cleanlibs\tClean the libraries\n"
  95. printf " klibs \tBuild the Klibraries\n"
  96. printf " klibs <libname>\tBuild the Klibrary <libname>\n"
  97. printf " cleanklibs\tClean the Klibraries\n"
  98. printf " utils \tBuild go utils\n"
  99. printf " cmd \tBuild all cmds \n"
  100. printf " cmd <cmdname>\tBuild cmd named <cmdname>\n"
  101. printf " cleancmd \tClean the cmds\n"
  102. printf " kernel \tBuild kernel\n"
  103. printf " cleankernel\tClean kernel\n"
  104. printf "\nFLAGS:\n"
  105. printf " -g \tCompile with debugs flags\n"
  106. printf " -t <test> \tCompile <test> app and package it with the kernel"
  107. printf "\n"
  108. }
  109. ### MAIN SCRIPT ####
  110. if [ -z "$1" ]
  111. then
  112. show_help
  113. exit 1
  114. else
  115. # We need our binary dir
  116. mkdir -p $BIN_DIR
  117. #BUILD_DEBUG=
  118. #Until we have a stable kernel, debug mode is the default.
  119. BUILD_DEBUG="$CFLAGS_DEBUG"
  120. TEST_APP=
  121. while [ -n "$1" ]
  122. do
  123. case "$1" in
  124. "-g")
  125. BUILD_DEBUG="$CFLAGS_DEBUG"
  126. ;;
  127. "-t"*)
  128. #is -tSomething?
  129. TEST_APP=${1:2}
  130. if [ -z "$TEST_APP" ]
  131. then
  132. if [ -n "$2" ]
  133. then
  134. #form -t something
  135. TEST_APP="$2"
  136. shift
  137. else
  138. #-t nothing
  139. echo "Error. Use -t testapp"
  140. exit 1
  141. fi
  142. fi
  143. ;;
  144. "all")
  145. build_go_utils
  146. build_libs
  147. build_klibs
  148. build_cmds
  149. build_kernel
  150. printf "\n\nALL COMPONENTS COMPILED\n\n"
  151. ;;
  152. "libs")
  153. build_klibs
  154. build_libs
  155. ;;
  156. "klibs")
  157. build_klibs
  158. ;;
  159. "utils")
  160. build_go_utils
  161. ;;
  162. "cmd")
  163. build_cmds
  164. ;;
  165. "cleanall"|"cleancmd"|"cleankernel"|"cleanklibs"|"cleanlibs")
  166. printf "\n\nALL COMPONENTS ARE CLEANED AT BUILD TIME\n\n"
  167. ;;
  168. "kernel")
  169. build_kernel
  170. ;;
  171. *)
  172. echo "Invalid option <$1>"
  173. exit 1
  174. ;;
  175. esac
  176. shift
  177. done
  178. fi