BUILD 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. #ARGS:
  26. # $1 -> pass the $? return
  27. # $2 -> component name
  28. check_error()
  29. {
  30. if [ $1 -ne 0 ]
  31. then
  32. echo "ERROR $2"
  33. exit 1
  34. fi
  35. }
  36. compile_kernel()
  37. {
  38. export HARVEY="$_BUILD_DIR"
  39. cd "$KRL_DIR"
  40. $HARVEY/util/build $KERNEL_CONF.json
  41. cd "$PATH_ORI" > /dev/null
  42. }
  43. build_kernel()
  44. {
  45. compile_kernel
  46. if [ $? -ne 0 ]; then
  47. echo "SOMETHING WENT WRONG!"
  48. else
  49. echo "KERNEL COMPILED OK"
  50. fi
  51. }
  52. build_go_utils()
  53. {
  54. cd "${UTIL_DIR}"
  55. for i in `ls *.go`
  56. do
  57. go build $i
  58. if [ $? -ne 0 ]
  59. then
  60. printf "\nERROR compiling $i \n"
  61. exit 1
  62. fi
  63. done
  64. cd - > /dev/null
  65. }
  66. check_utils()
  67. {
  68. if [ -f "${UTIL_DIR}"/mksys ]
  69. then
  70. echo 0
  71. else
  72. echo 1
  73. fi
  74. }
  75. ## Be sure amd64/lib is there!! ##
  76. check_lib_dir()
  77. {
  78. if [ ! -d "$LIB_DIR" ]
  79. then
  80. mkdir "$LIB_DIR"
  81. if [ $? -ne 0 ]
  82. then
  83. echo "ERROR creating <$LIB_DIR> directory"
  84. fi
  85. fi
  86. }
  87. check_bin_dir()
  88. {
  89. if [ ! -d "$BIN_DIR" ]
  90. then
  91. mkdir "$BIN_DIR"
  92. if [ $? -ne 0 ]
  93. then
  94. echo "ERROR creating <$BIN_DIR> directory"
  95. fi
  96. fi
  97. }
  98. build_libs()
  99. {
  100. export HARVEY="$_BUILD_DIR"
  101. cd "$SRC_DIR"
  102. $HARVEY/util/build libs.json
  103. cd "$PATH_ORI" > /dev/null
  104. }
  105. build_klibs()
  106. {
  107. export HARVEY="$_BUILD_DIR"
  108. cd "$SRC_DIR"
  109. $HARVEY/util/build klibs.json
  110. cd "$PATH_ORI" > /dev/null
  111. }
  112. build_cmds()
  113. {
  114. export HARVEY="$_BUILD_DIR"
  115. cd "$CMD_DIR"
  116. $HARVEY/util/build cmds.json
  117. $HARVEY/util/build kcmds.json
  118. cd "$PATH_ORI" > /dev/null
  119. }
  120. show_help()
  121. {
  122. printf "\n\nBUILD script for Harvey\n\n"
  123. printf "OPTIONS:\n"
  124. printf " all \tBuild all components\n"
  125. printf " cleanall \tClean all components\n"
  126. printf " libs \tBuild the libraries\n"
  127. printf " libs <libname>\tBuild the library <libname>\n"
  128. printf " cleanlibs\tClean the libraries\n"
  129. printf " klibs \tBuild the Klibraries\n"
  130. printf " klibs <libname>\tBuild the Klibrary <libname>\n"
  131. printf " cleanklibs\tClean the Klibraries\n"
  132. printf " utils \tBuild go utils\n"
  133. printf " cmd \tBuild all cmds \n"
  134. printf " cmd <cmdname>\tBuild cmd named <cmdname>\n"
  135. printf " cleancmd \tClean the cmds\n"
  136. printf " kernel \tBuild kernel\n"
  137. printf " cleankernel\tClean kernel\n"
  138. printf "\nFLAGS:\n"
  139. printf " -g \tCompile with debugs flags\n"
  140. printf " -t <test> \tCompile <test> app and package it with the kernel"
  141. printf "\n"
  142. }
  143. ### MAIN SCRIPT ####
  144. if [ -z "$1" ]
  145. then
  146. show_help
  147. exit 1
  148. else
  149. #BUILD_DEBUG=
  150. #Until we have a stable kernel, debug mode is the default.
  151. BUILD_DEBUG="$CFLAGS_DEBUG"
  152. TEST_APP=
  153. while [ -n "$1" ]
  154. do
  155. case "$1" in
  156. "-g")
  157. BUILD_DEBUG="$CFLAGS_DEBUG"
  158. ;;
  159. "-t"*)
  160. #is -tSomething?
  161. TEST_APP=${1:2}
  162. if [ -z "$TEST_APP" ]
  163. then
  164. if [ -n "$2" ]
  165. then
  166. #form -t something
  167. TEST_APP="$2"
  168. shift
  169. else
  170. #-t nothing
  171. echo "Error. Use -t testapp"
  172. exit 1
  173. fi
  174. fi
  175. ;;
  176. "all")
  177. check_bin_dir
  178. check_lib_dir
  179. build_go_utils
  180. build_libs
  181. build_klibs
  182. build_cmds
  183. build_kernel
  184. printf "\n\nALL COMPONENTS COMPILED\n\n"
  185. ;;
  186. "libs")
  187. check_lib_dir
  188. if [ -z "$2" ]
  189. then
  190. build_libs
  191. fi
  192. ;;
  193. "klibs")
  194. check_lib_dir
  195. if [ -z "$2" ]
  196. then
  197. build_klibs
  198. fi
  199. ;;
  200. "utils")
  201. build_go_utils
  202. ;;
  203. "cmd")
  204. check_bin_dir
  205. build_cmds
  206. ;;
  207. "cleanall"|"cleancmd"|"cleankernel"|"cleanklibs"|"cleanlibs")
  208. printf "\n\nALL COMPONENTS ARE CLEANED AT BUILD TIME\n\n"
  209. ;;
  210. "kernel")
  211. build_kernel
  212. ;;
  213. *)
  214. echo "Invalid option <$1>"
  215. exit 1
  216. ;;
  217. esac
  218. shift
  219. done
  220. fi