2
0

build-pkg.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #!/bin/sh
  2. # Copyright (C) 2018-2019 Nick Peng ([email protected])
  3. CURR_DIR=$(cd $(dirname $0);pwd)
  4. VER="`date +"1.%Y.%m.%d-%H%M"`"
  5. CODE_DIR="$CURR_DIR/.."
  6. IS_BUILD_SMARTDNS=1
  7. OUTPUTDIR=$CURR_DIR
  8. export CC
  9. export STRIP
  10. showhelp()
  11. {
  12. echo "Usage: $0 [OPTION]"
  13. echo "Options:"
  14. echo " --platform [luci|luci-compat|debian|openwrt|optware|linux] build for platform. "
  15. echo " --arch [all|armhf|arm64|x86-64|...] build for architecture, e.g. "
  16. echo " --cross-tool [cross-tool] cross compiler, e.g. mips-openwrt-linux-"
  17. echo ""
  18. echo "Advance Options:"
  19. echo " --static static link smartdns"
  20. echo " --only-package only package, not build source"
  21. echo " --filearch [arch] output file arch, default: equal --arch"
  22. echo " --outputdir [dir] output package to specific directory"
  23. echo " "
  24. echo "Example:"
  25. echo " build luci:"
  26. echo " $0 --platform luci"
  27. echo " build luci:"
  28. echo " $0 --platform luci-compat"
  29. echo " build debian:"
  30. echo " $0 --platform debian --arch x86-64"
  31. echo " build raspbian pi:"
  32. echo " $0 --platform debian --arch armhf"
  33. echo " build optware mips:"
  34. echo " $0 --platform optware --arch mipsbig"
  35. echo " build openwrt mips:"
  36. echo " $0 --platform openwrt --arch mips_24kc"
  37. echo " build generic linux:"
  38. echo " $0 --platform linux --arch x86-64"
  39. }
  40. build_smartdns()
  41. {
  42. if [ "$PLATFORM" != "luci" ]; then
  43. make -C $CODE_DIR clean $MAKE_ARGS
  44. make -C $CODE_DIR all -j8 VER=$VER $MAKE_ARGS
  45. if [ $? -ne 0 ]; then
  46. echo "make smartdns failed"
  47. exit 1
  48. fi
  49. fi
  50. $STRIP -d $CODE_DIR/src/smartdns >/dev/null 2>&1
  51. return 0
  52. }
  53. build()
  54. {
  55. echo "build package for $PLATFORM"
  56. if [ $IS_BUILD_SMARTDNS -eq 1 ]; then
  57. build_smartdns
  58. if [ $? -ne 0 ]; then
  59. return 1
  60. fi
  61. fi
  62. chmod +x $CODE_DIR/package/$PLATFORM/make.sh
  63. $CODE_DIR/package/$PLATFORM/make.sh -o $CURR_DIR --arch $ARCH --ver $VER --filearch $FILEARCH -o $OUTPUTDIR
  64. if [ $? -ne 0 ]; then
  65. echo "build package for $PLATFORM failed"
  66. return 1
  67. fi
  68. echo "build package for $PLATFORM success."
  69. return 0
  70. }
  71. main()
  72. {
  73. OPTS=`getopt -o o:h --long arch:,filearch:,ver:,platform:,cross-tool:,with-nftables,static,only-package,outputdir: \
  74. -n "" -- "$@"`
  75. if [ "$#" -le "1" ]; then
  76. showhelp
  77. exit 1
  78. fi
  79. if [ $? != 0 ] ; then echo "Terminating..." >&2 ; exit 1 ; fi
  80. # Note the quotes around `$TEMP': they are essential!
  81. eval set -- "$OPTS"
  82. while true; do
  83. case "$1" in
  84. --arch)
  85. ARCH="$2"
  86. shift 2;;
  87. --filearch)
  88. FILEARCH="$2"
  89. shift 2;;
  90. --platform)
  91. PLATFORM="$2"
  92. shift 2;;
  93. --cross-tool)
  94. CROSS_TOOL="$2"
  95. shift 2;;
  96. --static)
  97. export STATIC="yes"
  98. shift 1;;
  99. --only-package)
  100. IS_BUILD_SMARTDNS=0
  101. shift 1;;
  102. --outputdir)
  103. OUTPUTDIR="$2"
  104. shift 2;;
  105. --ver)
  106. VER="$2"
  107. shift 2;;
  108. -h | --help )
  109. showhelp
  110. return 0
  111. shift ;;
  112. -- ) shift; break ;;
  113. * ) break ;;
  114. esac
  115. done
  116. if [ -z "$PLATFORM" ]; then
  117. echo "please input platform"
  118. echo "run $0 -h for help."
  119. return 1
  120. fi
  121. if [ "$PLATFORM" = "luci" ]; then
  122. ARCH="all"
  123. fi
  124. if [ -z "$ARCH" ]; then
  125. echo "please input arch."
  126. echo "run $0 -h for help."
  127. return 1
  128. fi
  129. if [ -z "$FILEARCH" ]; then
  130. FILEARCH="$ARCH"
  131. fi
  132. if [ -z "$OUTPUTDIR" ]; then
  133. OUTPUTDIR=$CURR_DIR
  134. fi
  135. if [ ! -z "$CROSS_TOOL" ]; then
  136. CC="${CROSS_TOOL}gcc"
  137. STRIP="${CROSS_TOOL}strip"
  138. fi
  139. if [ -z "$CC" ]; then
  140. CC="gcc"
  141. fi
  142. if [ -z "$STRIP" ]; then
  143. if [ ! -z "`echo $CC | grep '\-gcc'`" ]; then
  144. STRIP="`echo "$CC" | sed 's/-gcc\$/-strip/g'`"
  145. else
  146. STRIP="strip"
  147. fi
  148. fi
  149. if [ ! -e "`which $CC`" ]; then
  150. echo "Cannot find compiler $CC"
  151. return 1
  152. fi
  153. build
  154. }
  155. main $@
  156. exit $?