BUILD 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. build_libs()
  88. {
  89. export HARVEY="$_BUILD_DIR"
  90. cd "$SRC_DIR"
  91. $HARVEY/util/build libs.json
  92. cd "$PATH_ORI" > /dev/null
  93. }
  94. build_klibs()
  95. {
  96. export HARVEY="$_BUILD_DIR"
  97. cd "$SRC_DIR"
  98. $HARVEY/util/build klibs.json
  99. cd "$PATH_ORI" > /dev/null
  100. }
  101. build_cmds()
  102. {
  103. export HARVEY="$_BUILD_DIR"
  104. cd "$CMD_DIR"
  105. $HARVEY/util/build cmds.json
  106. $HARVEY/util/build kcmds.json
  107. cd "$PATH_ORI" > /dev/null
  108. }
  109. show_help()
  110. {
  111. printf "\n\nBUILD script for Harvey\n\n"
  112. printf "OPTIONS:\n"
  113. printf " all \tBuild all components\n"
  114. printf " cleanall \tClean all components\n"
  115. printf " libs \tBuild the libraries\n"
  116. printf " libs <libname>\tBuild the library <libname>\n"
  117. printf " cleanlibs\tClean the libraries\n"
  118. printf " klibs \tBuild the Klibraries\n"
  119. printf " klibs <libname>\tBuild the Klibrary <libname>\n"
  120. printf " cleanklibs\tClean the Klibraries\n"
  121. printf " utils \tBuild go utils\n"
  122. printf " cmd \tBuild all cmds \n"
  123. printf " cmd <cmdname>\tBuild cmd named <cmdname>\n"
  124. printf " cleancmd \tClean the cmds\n"
  125. printf " kernel \tBuild kernel\n"
  126. printf " cleankernel\tClean kernel\n"
  127. printf "\nFLAGS:\n"
  128. printf " -g \tCompile with debugs flags\n"
  129. printf " -t <test> \tCompile <test> app and package it with the kernel"
  130. printf "\n"
  131. }
  132. ### MAIN SCRIPT ####
  133. if [ -z "$1" ]
  134. then
  135. show_help
  136. exit 1
  137. else
  138. #BUILD_DEBUG=
  139. #Until we have a stable kernel, debug mode is the default.
  140. BUILD_DEBUG="$CFLAGS_DEBUG"
  141. TEST_APP=
  142. while [ -n "$1" ]
  143. do
  144. case "$1" in
  145. "-g")
  146. BUILD_DEBUG="$CFLAGS_DEBUG"
  147. ;;
  148. "-t"*)
  149. #is -tSomething?
  150. TEST_APP=${1:2}
  151. if [ -z "$TEST_APP" ]
  152. then
  153. if [ -n "$2" ]
  154. then
  155. #form -t something
  156. TEST_APP="$2"
  157. shift
  158. else
  159. #-t nothing
  160. echo "Error. Use -t testapp"
  161. exit 1
  162. fi
  163. fi
  164. ;;
  165. "all")
  166. check_lib_dir
  167. build_go_utils
  168. build_libs
  169. build_klibs
  170. build_cmds
  171. build_kernel
  172. printf "\n\nALL COMPONENTS COMPILED\n\n"
  173. ;;
  174. "libs")
  175. check_lib_dir
  176. if [ -z "$2" ]
  177. then
  178. build_libs
  179. fi
  180. ;;
  181. "klibs")
  182. check_lib_dir
  183. if [ -z "$2" ]
  184. then
  185. build_klibs
  186. fi
  187. ;;
  188. "utils")
  189. build_go_utils
  190. ;;
  191. "cmd")
  192. build_cmds
  193. ;;
  194. "cleanall"|"cleancmd"|"cleankernel"|"cleanklibs"|"cleanlibs")
  195. printf "\n\nALL COMPONENTS ARE CLEANED AT BUILD TIME\n\n"
  196. ;;
  197. "kernel")
  198. build_kernel
  199. ;;
  200. *)
  201. echo "Invalid option <$1>"
  202. exit 1
  203. ;;
  204. esac
  205. shift
  206. done
  207. fi