build_osgeo4w.sh 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. #!/bin/sh
  2. #
  3. # Usage: build_osgeo4w.sh
  4. #
  5. # The following environment variables are supposed to be passed to the build script
  6. # - SRC: the directory where the grass source code lives
  7. # - OSGEO4W_ROOT_MSYS: the root directory of OSGeo4W
  8. # - UNITTEST: If this variable is defined, addition files for unittests are created
  9. #
  10. # By default, the script will look for the source code in the current directory
  11. # and create bin.x86_64-w64-mingw32\grass$ver.bat (run this batch file to start
  12. # GRASS GIS) and dist.x86_64-w64-mingw32\etc\env.bat.
  13. #
  14. # -p optionally install GRASS GIS to C:\OSGeo4W\opt\grass (run
  15. # C:\OSGeo4W64\opt\grass\grass$ver.bat) and create an unzippable package
  16. # grass$ver-x86_64-w64-mingw32-osgeo4w64-$date.zip
  17. #
  18. # path specify a path to the source code
  19. #
  20. # stop on errors
  21. set -e
  22. # compile
  23. export PATH=${OSGEO4W_ROOT_MSYS}/bin:/usr/bin:/mingw64/bin
  24. export C_INCLUDE_PATH=".:${OSGEO4W_ROOT_MSYS}/include:${SRC}/dist.${ARCH}/include:/c/msys64/mingw64/include"
  25. export PYTHONHOME=${OSGEO4W_ROOT_MSYS}/apps/Python39
  26. export ARCH=x86_64-w64-mingw32
  27. ./configure \
  28. --host=${ARCH} \
  29. --with-libs="${OSGEO4W_ROOT_MSYS}/lib ${OSGEO4W_ROOT_MSYS}/bin" \
  30. --with-includes=${OSGEO4W_ROOT_MSYS}/include \
  31. --libexecdir=${OSGEO4W_ROOT_MSYS}/bin \
  32. --prefix=${OSGEO4W_ROOT_MSYS}/apps/grass \
  33. --bindir=${OSGEO4W_ROOT_MSYS}/bin \
  34. --includedir=${OSGEO4W_ROOT_MSYS}/include \
  35. --without-x \
  36. --with-cxx \
  37. --enable-shared \
  38. --enable-largefile \
  39. --with-openmp \
  40. --with-fftw \
  41. --with-nls \
  42. --with-readline \
  43. --with-wxwidgets \
  44. --with-blas \
  45. --with-lapack-includes=/mingw64/include/lapack \
  46. --with-freetype \
  47. --with-freetype-includes=/mingw64/include/freetype2 \
  48. --with-proj-share=${OSGEO4W_ROOT_MSYS}/share/proj \
  49. --with-proj-includes=${OSGEO4W_ROOT_MSYS}/include \
  50. --with-proj-libs=${OSGEO4W_ROOT_MSYS}/lib \
  51. --with-postgres \
  52. --with-postgres-includes=${OSGEO4W_ROOT_MSYS}/include \
  53. --with-postgres-libs=${OSGEO4W_ROOT_MSYS}/lib \
  54. --with-gdal=${SRC}/mswindows/osgeo4w/gdal-config \
  55. --with-geos=${SRC}/mswindows/osgeo4w/geos-config \
  56. --with-sqlite \
  57. --with-sqlite-includes=${OSGEO4W_ROOT_MSYS}/include \
  58. --with-sqlite-libs=${OSGEO4W_ROOT_MSYS}/lib \
  59. --with-regex \
  60. --with-nls \
  61. --with-zstd \
  62. --with-odbc \
  63. --with-cairo \
  64. --with-cairo-includes=${SRC}/include \
  65. --with-cairo-ldflags="-L${SRC}/mswindows/osgeo4w/lib -lcairo -lfontconfig" \
  66. --with-opengl=windows \
  67. --with-bzlib \
  68. --with-liblas=${SRC}/mswindows/osgeo4w/liblas-config \
  69. --with-netcdf=${OSGEO4W_ROOT_MSYS}/bin/nc-config
  70. make
  71. # install
  72. bin=bin.${ARCH}
  73. dist=dist.${ARCH}
  74. ver=$(sed -n '/^INST_DIR[ \t]*=/{s/^.*grass//; p}' include/Make/Platform.make)
  75. rm -f $dist/grass$ver.tmp $dist/etc/fontcap
  76. if [ "$UNITTEST" ]; then
  77. # Add executables for bash scripts in unittests
  78. bash_bin=bash_bin
  79. mkdir "${SRC}/dist.${ARCH}/$bash_bin"
  80. for f in ${SRC}/dist.${ARCH}/scripts/*.py
  81. do
  82. bash_exe=$(echo $f | sed -e "s/\/scripts\//\/${bash_bin}\//;s/\.py$//")
  83. cp "$f" "$bash_exe"
  84. # dos2unix "$bash_exe"
  85. chmod ugo+x "$bash_exe"
  86. done
  87. bash_exe_path=$(echo "${SRC}/dist.${ARCH}/$bash_bin" | sed -e "s/^\/c/\;c:/;s/^\/d/d:/")
  88. export PATH="$PATH:${SRC}/dist.${ARCH}/$bash_bin"
  89. fi
  90. # create batch files
  91. src_esc=$(echo ${SRC} | sed 's#^/\([a-z]\)#\1:#; s#/#\\\\\\\\#g')
  92. dist_esc="$src_esc\\\\$dist"
  93. (
  94. sed 's/^\(set GISBASE=\).*/\1'$dist_esc'/' \
  95. mswindows/osgeo4w/env.bat.tmpl
  96. cat <<EOT
  97. set PATH=%PATH%;C:\\msys64\\mingw64\\bin;C:\\msys64\\usr\\bin
  98. if not exist %GISBASE%\etc\fontcap (
  99. pushd .
  100. %~d0
  101. cd %GISBASE%\lib
  102. set GISRC=dummy
  103. %GISBASE%\bin\g.mkfontcap.exe
  104. popd
  105. )
  106. EOT
  107. ) >$dist/etc/env.bat
  108. unix2dos $dist/etc/env.bat
  109. (
  110. sed -e 's/^\(call "\)%~dp0\(.*\)$/\1C:\\OSGeo4W\\bin\2/' \
  111. -e 's/^\(call "\).*\(\\etc\\env\.bat"\)$/\1'$dist_esc'\2/' \
  112. -e 's/^\(.* "\)%GISBASE%\\etc\(\\grass.*\)$/\1%GISBASE%\\..\\'$bin'\2/' \
  113. -e 's/@POSTFIX@/'$ver'/g' \
  114. mswindows/osgeo4w/grass.bat.tmpl
  115. ) >$bin/grass$ver.bat
  116. unix2dos $bin/grass$ver.bat
  117. opt_path=${OSGEO4W_ROOT_MSYS}/opt
  118. grass_path=$opt_path/grass
  119. if [ "$UNITTEST" ]; then
  120. msys_path=";C:/msys64/usr/bin;C:/msys64/mingw64/bin"
  121. fi
  122. mkdir -p $opt_path
  123. cp -a $dist $grass_path
  124. # have a versionless and versioned startup script
  125. cp -a $bin/grass.py $bin/grass$ver.py
  126. cp -a $bin/grass$ver.py $grass_path/etc
  127. cp -a $(ldd $dist/lib/*.dll | awk '/mingw64/{print $3}' |
  128. sort -u | grep -v 'lib\(crypto\|ssl\)') $grass_path/lib
  129. (
  130. sed -e 's/^\(set GISBASE=\).*/\1%OSGEO4W_ROOT%\\opt\\grass/' \
  131. mswindows/osgeo4w/env.bat.tmpl
  132. cat <<EOT
  133. set PATH=%OSGEO4W_ROOT%\\bin${msys_path};%PATH%;$bash_exe_path
  134. if not exist %GISBASE%\etc\fontcap (
  135. pushd .
  136. %~d0
  137. cd %GISBASE%\lib
  138. set GISRC=dummy
  139. %GISBASE%\bin\g.mkfontcap.exe
  140. popd
  141. )
  142. EOT
  143. ) >$grass_path/etc/env.bat
  144. unix2dos $grass_path/etc/env.bat
  145. cat $grass_path/etc/env.bat
  146. (
  147. sed -e 's/^\(call "%~dp0\)\(.*\)$/\1\\..\\..\\bin\2/' \
  148. -e 's/^\(call "%OSGEO4W_ROOT%\\\).*\(\\etc\\env\.bat"\)$/\1opt\\grass\2/' \
  149. -e 's/@POSTFIX@/'$ver'/g' \
  150. mswindows/osgeo4w/grass.bat.tmpl
  151. ) >$grass_path/grass$ver.bat
  152. unix2dos $grass_path/grass$ver.bat
  153. if [ "$UNITTEST" ]; then
  154. cp $grass_path/grass$ver.bat $grass_path/grass.bat
  155. cp -a $bin/grass.py ${SRC}/dist.${ARCH}/$bash_bin/grass
  156. dos2unix ${SRC}/dist.${ARCH}/$bash_bin/grass
  157. chmod ugo+x ${SRC}/dist.${ARCH}/$bash_bin/grass
  158. # Set path for bash if not called from OSGeo shell
  159. arch_esc=$(sed 's/[\/\*\.]/\\&/g' <<<"${ARCH}")
  160. src_esc=$(sed 's/[\/\*\.]/\\&/g' <<<"${SRC}")
  161. osgeo4w_esc=$(sed 's/[\/\*\.]/\\&/g' <<<"${OSGEO4W_ROOT_MSYS}")
  162. pythonhome_esc=$(sed 's/[\/\*\.]/\\&/g' <<<"${PYTHONHOME}")
  163. sed -i "5s/^/export PATH=\"${osgeo4w_esc}\/bin:\/usr\/bin:\/mingw64\/bin:$src_esc\/dist\.$arch_esc\/bin:$src_esc\/dist\.$arch_esc\/$bash_bin\"\nexport PYTHONHOME=\"${pythonhome_esc}\"/" ${SRC}/.github/workflows/test_simple.sh
  164. printf "export PATH=\"${OSGEO4W_ROOT_MSYS}/bin:/usr/bin:/mingw64/bin:${SRC}/dist.${ARCH}/bin:${SRC}/dist.${ARCH}/$bash_bin\"\nexport PYTHONHOME=\"${PYTHONHOME}\"\nexport PYTHONUTF8=1" > $HOME/.bash_profile
  165. printf "export PATH=\"${OSGEO4W_ROOT_MSYS}/bin:/usr/bin:/mingw64/bin:${SRC}/dist.${ARCH}/bin:${SRC}/dist.${ARCH}/$bash_bin\"\nexport PYTHONHOME=\"${PYTHONHOME}\"\nexport PYTHONUTF8=1" > $HOME/.profile
  166. printf "export PATH=\"${OSGEO4W_ROOT_MSYS}/bin:/usr/bin:/mingw64/bin:${SRC}/dist.${ARCH}/bin:${SRC}/dist.${ARCH}/$bash_bin\"\nexport PYTHONHOME=\"${PYTHONHOME}\"\nexport PYTHONUTF8=1" > $HOME/.bashrc
  167. fi