BUILD 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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. #BUILD_DEBUG=
  116. #Until we have a stable kernel, debug mode is the default.
  117. BUILD_DEBUG="$CFLAGS_DEBUG"
  118. TEST_APP=
  119. while [ -n "$1" ]
  120. do
  121. case "$1" in
  122. "-g")
  123. BUILD_DEBUG="$CFLAGS_DEBUG"
  124. ;;
  125. "-t"*)
  126. #is -tSomething?
  127. TEST_APP=${1:2}
  128. if [ -z "$TEST_APP" ]
  129. then
  130. if [ -n "$2" ]
  131. then
  132. #form -t something
  133. TEST_APP="$2"
  134. shift
  135. else
  136. #-t nothing
  137. echo "Error. Use -t testapp"
  138. exit 1
  139. fi
  140. fi
  141. ;;
  142. "all")
  143. build_go_utils
  144. build_libs
  145. build_klibs
  146. build_cmds
  147. build_kernel
  148. printf "\n\nALL COMPONENTS COMPILED\n\n"
  149. ;;
  150. "libs")
  151. build_libs
  152. ;;
  153. "klibs")
  154. build_klibs
  155. ;;
  156. "utils")
  157. build_go_utils
  158. ;;
  159. "cmd")
  160. build_cmds
  161. ;;
  162. "cleanall"|"cleancmd"|"cleankernel"|"cleanklibs"|"cleanlibs")
  163. printf "\n\nALL COMPONENTS ARE CLEANED AT BUILD TIME\n\n"
  164. ;;
  165. "kernel")
  166. build_kernel
  167. ;;
  168. *)
  169. echo "Invalid option <$1>"
  170. exit 1
  171. ;;
  172. esac
  173. shift
  174. done
  175. fi