BUILD 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. GOPATH="$UTIL_DIR/third_party" go install github.com/rminnich/go9p
  54. cp $UTIL_DIR/third_party/bin/* $UTIL_DIR/
  55. cd - > /dev/null
  56. }
  57. check_utils()
  58. {
  59. if [ -f "${UTIL_DIR}"/mksys ]
  60. then
  61. echo 0
  62. else
  63. echo 1
  64. fi
  65. }
  66. build_libs()
  67. {
  68. export HARVEY="$_BUILD_DIR"
  69. cd "$SRC_DIR"
  70. $HARVEY/util/build libs.json
  71. cd "$PATH_ORI" > /dev/null
  72. }
  73. build_klibs()
  74. {
  75. export HARVEY="$_BUILD_DIR"
  76. cd "$SRC_DIR"
  77. $HARVEY/util/build klibs.json
  78. cd "$PATH_ORI" > /dev/null
  79. }
  80. build_cmds()
  81. {
  82. export HARVEY="$_BUILD_DIR"
  83. cd "$CMD_DIR"
  84. $HARVEY/util/build cmds.json
  85. $HARVEY/util/build kcmds.json
  86. cd "$PATH_ORI" > /dev/null
  87. }
  88. show_help()
  89. {
  90. printf "\n\nBUILD script for Harvey\n\n"
  91. printf "OPTIONS:\n"
  92. printf " all \tBuild all components\n"
  93. printf " cleanall \tClean all components\n"
  94. printf " libs \tBuild the libraries\n"
  95. printf " libs <libname>\tBuild the library <libname>\n"
  96. printf " cleanlibs\tClean the libraries\n"
  97. printf " klibs \tBuild the Klibraries\n"
  98. printf " klibs <libname>\tBuild the Klibrary <libname>\n"
  99. printf " cleanklibs\tClean the Klibraries\n"
  100. printf " utils \tBuild go utils\n"
  101. printf " cmd \tBuild all cmds \n"
  102. printf " cmd <cmdname>\tBuild cmd named <cmdname>\n"
  103. printf " cleancmd \tClean the cmds\n"
  104. printf " kernel \tBuild kernel\n"
  105. printf " cleankernel\tClean kernel\n"
  106. printf "\nFLAGS:\n"
  107. printf " -g \tCompile with debugs flags\n"
  108. printf " -t <test> \tCompile <test> app and package it with the kernel"
  109. printf "\n"
  110. }
  111. ### MAIN SCRIPT ####
  112. if [ -z "$1" ]
  113. then
  114. show_help
  115. exit 1
  116. else
  117. # We need our binary dir
  118. mkdir -p $BIN_DIR
  119. #BUILD_DEBUG=
  120. #Until we have a stable kernel, debug mode is the default.
  121. BUILD_DEBUG="$CFLAGS_DEBUG"
  122. TEST_APP=
  123. while [ -n "$1" ]
  124. do
  125. case "$1" in
  126. "-g")
  127. BUILD_DEBUG="$CFLAGS_DEBUG"
  128. ;;
  129. "-t"*)
  130. #is -tSomething?
  131. TEST_APP=${1:2}
  132. if [ -z "$TEST_APP" ]
  133. then
  134. if [ -n "$2" ]
  135. then
  136. #form -t something
  137. TEST_APP="$2"
  138. shift
  139. else
  140. #-t nothing
  141. echo "Error. Use -t testapp"
  142. exit 1
  143. fi
  144. fi
  145. ;;
  146. "all")
  147. build_go_utils
  148. build_libs
  149. build_klibs
  150. build_cmds
  151. build_kernel
  152. printf "\n\nALL COMPONENTS COMPILED\n\n"
  153. ;;
  154. "libs")
  155. build_klibs
  156. build_libs
  157. ;;
  158. "klibs")
  159. build_klibs
  160. ;;
  161. "utils")
  162. build_go_utils
  163. ;;
  164. "cmd")
  165. build_cmds
  166. ;;
  167. "cleanall"|"cleancmd"|"cleankernel"|"cleanklibs"|"cleanlibs")
  168. printf "\n\nALL COMPONENTS ARE CLEANED AT BUILD TIME\n\n"
  169. ;;
  170. "kernel")
  171. build_kernel
  172. ;;
  173. *)
  174. echo "Invalid option <$1>"
  175. exit 1
  176. ;;
  177. esac
  178. shift
  179. done
  180. fi