download.sh 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #!/usr/bin/env bash
  2. # ===
  3. # This script defines and generates the bundled SQLite3 unit (sqlite3.c).
  4. #
  5. # The following steps are taken:
  6. # 1. populate the shell environment with the defined compile-time options.
  7. # 2. download and extract the SQLite3 source code into a temporary directory.
  8. # 3. run "sh configure" and "make sqlite3.c" within the source directory.
  9. # 4. copy the generated amalgamation into the output directory (./sqlite3).
  10. # 5. export the defined compile-time options to a gyp file (./defines.gypi).
  11. # 6. update the docs (../docs/compilation.md) with details of this distribution.
  12. #
  13. # When a user builds better-sqlite3, the following steps are taken:
  14. # 1. node-gyp loads the previously exported compile-time options (defines.gypi).
  15. # 2. the copy.js script copies the bundled amalgamation into the build folder.
  16. # 3. node-gyp compiles the copied sqlite3.c along with better_sqlite3.cpp.
  17. # 4. node-gyp links the two resulting binaries to generate better_sqlite3.node.
  18. # ===
  19. YEAR="2023"
  20. VERSION="3420000"
  21. # Defines below are sorted alphabetically
  22. DEFINES="
  23. HAVE_INT16_T=1
  24. HAVE_INT32_T=1
  25. HAVE_INT8_T=1
  26. HAVE_STDINT_H=1
  27. HAVE_UINT16_T=1
  28. HAVE_UINT32_T=1
  29. HAVE_UINT8_T=1
  30. SQLITE_DEFAULT_CACHE_SIZE=-16000
  31. SQLITE_DEFAULT_FOREIGN_KEYS=1
  32. SQLITE_DEFAULT_MEMSTATUS=0
  33. SQLITE_DEFAULT_WAL_SYNCHRONOUS=1
  34. SQLITE_DQS=0
  35. SQLITE_ENABLE_COLUMN_METADATA
  36. SQLITE_ENABLE_DESERIALIZE
  37. SQLITE_ENABLE_FTS3
  38. SQLITE_ENABLE_FTS3_PARENTHESIS
  39. SQLITE_ENABLE_FTS4
  40. SQLITE_ENABLE_FTS5
  41. SQLITE_ENABLE_GEOPOLY
  42. SQLITE_ENABLE_JSON1
  43. SQLITE_ENABLE_MATH_FUNCTIONS
  44. SQLITE_ENABLE_RTREE
  45. SQLITE_ENABLE_STAT4
  46. SQLITE_ENABLE_UPDATE_DELETE_LIMIT
  47. SQLITE_INTROSPECTION_PRAGMAS
  48. SQLITE_LIKE_DOESNT_MATCH_BLOBS
  49. SQLITE_OMIT_DEPRECATED
  50. SQLITE_OMIT_GET_TABLE
  51. SQLITE_OMIT_PROGRESS_CALLBACK
  52. SQLITE_OMIT_SHARED_CACHE
  53. SQLITE_OMIT_TCL_VARIABLE
  54. SQLITE_SOUNDEX
  55. SQLITE_THREADSAFE=2
  56. SQLITE_TRACE_SIZE_LIMIT=32
  57. SQLITE_USE_URI=0
  58. "
  59. # ========== START SCRIPT ========== #
  60. echo "setting up environment..."
  61. DEPS="$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)"
  62. TEMP="$DEPS/temp"
  63. OUTPUT="$DEPS/sqlite3"
  64. rm -rf "$TEMP"
  65. rm -rf "$OUTPUT"
  66. mkdir -p "$TEMP"
  67. mkdir -p "$OUTPUT"
  68. export CFLAGS=`echo $(echo "$DEFINES" | sed -e "/^\s*$/d" -e "s/^/-D/")`
  69. echo "downloading source..."
  70. curl -#f "https://www.sqlite.org/$YEAR/sqlite-src-$VERSION.zip" > "$TEMP/source.zip" || exit 1
  71. echo "extracting source..."
  72. unzip "$TEMP/source.zip" -d "$TEMP" > /dev/null || exit 1
  73. cd "$TEMP/sqlite-src-$VERSION" || exit 1
  74. echo "configuring amalgamation..."
  75. sh configure > /dev/null || exit 1
  76. echo "building amalgamation..."
  77. make sqlite3.c > /dev/null || exit 1
  78. echo "copying amalgamation..."
  79. cp sqlite3.c sqlite3.h sqlite3ext.h "$OUTPUT/" || exit 1
  80. echo "updating gyp configs..."
  81. GYP="$DEPS/defines.gypi"
  82. printf "# THIS FILE IS AUTOMATICALLY GENERATED BY deps/download.sh (DO NOT EDIT)\n\n{\n 'defines': [\n" > "$GYP"
  83. printf "$DEFINES" | sed -e "/^\s*$/d" -e "s/\(.*\)/ '\1',/" >> "$GYP"
  84. printf " ],\n}\n" >> "$GYP"
  85. echo "updating docs..."
  86. DOCS="$DEPS/../docs/compilation.md"
  87. MAJOR=`expr "${VERSION:0:1}" + 0`
  88. MINOR=`expr "${VERSION:1:2}" + 0`
  89. PATCH=`expr "${VERSION:3:2}" + 0`
  90. sed -Ei.bak -e "s/version [0-9]+\.[0-9]+\.[0-9]+/version $MAJOR.$MINOR.$PATCH/g" "$DOCS"
  91. sed -i.bak -e "/^SQLITE_/,\$d" "$DOCS"
  92. sed -i.bak -e "/^HAVE_/,\$d" "$DOCS"
  93. rm "$DOCS".bak
  94. printf "$DEFINES" | sed -e "/^\s*$/d" >> "$DOCS"
  95. printf "\`\`\`\n" >> "$DOCS"
  96. echo "cleaning up..."
  97. cd - > /dev/null || exit 1
  98. rm -rf "$TEMP"
  99. echo "done!"