copy_src.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #!/usr/bin/env bash
  2. set -eu
  3. VERSION="16.3"
  4. errexit() {
  5. echo $1
  6. exit 1
  7. }
  8. DIST="postgresql-$VERSION"
  9. mkdir -p build
  10. cd build
  11. echo cleanup
  12. rm -rf postgresql $DIST src_files
  13. rm -rf $DIST.tar.gz
  14. echo downloading sources
  15. wget -O $DIST.tar.gz "https://ftp.postgresql.org/pub/source/v$VERSION/$DIST.tar.gz" || errexit "Download failed"
  16. tar zxf $DIST.tar.gz
  17. mv $DIST postgresql
  18. cd postgresql
  19. echo patching postgresql sources
  20. patch -p0 < ../../source16.patch || errexit "Source patching failed"
  21. COMPILER=$(ya tool cc --print-path)
  22. TOOL_DIR=$(dirname $COMPILER)
  23. export PATH="$TOOL_DIR:$PATH"
  24. export CC=clang
  25. export AR=llvm-ar
  26. export CFLAGS="-ffunction-sections -fdata-sections -DWAIT_USE_SELF_PIPE"
  27. echo configuring
  28. ./configure \
  29. --with-openssl --with-icu --with-libxml --enable-debug --without-systemd \
  30. --without-gssapi --with-lz4 --with-ossp-uuid \
  31. || errexit "Configure failed"
  32. echo building
  33. make -C src/backend all || errexit "Compilation failed"
  34. cd ..
  35. echo collecting *.c file list
  36. for i in $(find postgresql -name "*.o" | sed -e 's/o$/c/'); do if [ -f $i ]; then realpath --relative-to=. $i; fi; done > src_files
  37. echo collecting *.h file list
  38. find postgresql -type f -name "*.h" | sort >> src_files
  39. find postgresql -type f -name "*.funcs.c" | sort >> src_files
  40. find postgresql -type f -name "*.switch.c" | sort >> src_files
  41. find postgresql -type f -name "regc_*.c" | sort >> src_files
  42. find postgresql -type f -name "rege_dfa.c" | sort >> src_files
  43. sort src_files > src_files.s
  44. mv src_files.s src_files
  45. echo copy data files...
  46. rm -f ../postgresql/src/include/catalog/*.dat ../postgresql/src/backend/catalog/*.sql
  47. cp postgresql/src/include/catalog/*.dat ../postgresql/src/include/catalog/
  48. cp postgresql/src/backend/catalog/*.sql ../postgresql/src/backend/catalog/
  49. cd ..
  50. echo copy and patch src files...
  51. python3 copy_src.py build