mkmsvcmin.tcl 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. #!/usr/bin/tcl
  2. #
  3. # This script reads the regular MSVC makefile (../Makefile.msc) and outputs
  4. # a revised version of that Makefile that is "minimal" in the sense that
  5. # it uses the sqlite3.c amalgamation as input and does not require tclsh.
  6. # The resulting "../Makefile.min.msc" is suitable for use in the amalgamation
  7. # tarballs.
  8. #
  9. if {$argc==0} {
  10. set basedir [file dir [file dir [file normalize $argv0]]]
  11. set fromFileName [file join $basedir Makefile.msc]
  12. set toFileName [file join $basedir autoconf Makefile.msc]
  13. } else {
  14. set fromFileName [lindex $argv 0]
  15. if {![file exists $fromFileName]} {
  16. error "input file \"$fromFileName\" does not exist"
  17. }
  18. set toFileName [lindex $argv 1]
  19. if {[file exists $toFileName]} {
  20. error "output file \"$toFileName\" already exists"
  21. }
  22. }
  23. proc readFile { fileName } {
  24. set file_id [open $fileName RDONLY]
  25. fconfigure $file_id -translation binary
  26. set result [read $file_id]
  27. close $file_id
  28. return $result
  29. }
  30. proc writeFile { fileName data } {
  31. set file_id [open $fileName {WRONLY CREAT TRUNC}]
  32. fconfigure $file_id -translation binary
  33. puts -nonewline $file_id $data
  34. close $file_id
  35. return ""
  36. }
  37. proc escapeSubSpec { data } {
  38. regsub -all -- {&} $data {\\\&} data
  39. regsub -all -- {\\(\d+)} $data {\\\\\1} data
  40. return $data
  41. }
  42. proc substVars { data } {
  43. return [uplevel 1 [list subst -nocommands -nobackslashes $data]]
  44. }
  45. #
  46. # NOTE: This block is used to replace the section marked <<block1>> in
  47. # the Makefile, if it exists.
  48. #
  49. set blocks(1) [string trimleft [string map [list \\\\ \\] {
  50. _HASHCHAR=^#
  51. !IF ![echo !IFNDEF VERSION > rcver.vc] && \\
  52. ![for /F "delims=" %V in ('type "$(SQLITE3H)" ^| "%SystemRoot%\System32\find.exe" "$(_HASHCHAR)define SQLITE_VERSION "') do (echo VERSION = ^^%V >> rcver.vc)] && \\
  53. ![echo !ENDIF >> rcver.vc]
  54. !INCLUDE rcver.vc
  55. !ENDIF
  56. RESOURCE_VERSION = $(VERSION:^#=)
  57. RESOURCE_VERSION = $(RESOURCE_VERSION:define=)
  58. RESOURCE_VERSION = $(RESOURCE_VERSION:SQLITE_VERSION=)
  59. RESOURCE_VERSION = $(RESOURCE_VERSION:"=)
  60. RESOURCE_VERSION = $(RESOURCE_VERSION:.=,)
  61. $(LIBRESOBJS): $(TOP)\sqlite3.rc rcver.vc $(SQLITE3H)
  62. echo #ifndef SQLITE_RESOURCE_VERSION > sqlite3rc.h
  63. echo #define SQLITE_RESOURCE_VERSION $(RESOURCE_VERSION) >> sqlite3rc.h
  64. echo #endif >> sqlite3rc.h
  65. $(LTRCOMPILE) -fo $(LIBRESOBJS) -DRC_VERONLY $(TOP)\sqlite3.rc
  66. }]]
  67. #
  68. # NOTE: This block is used to replace the section marked <<block2>> in
  69. # the Makefile, if it exists.
  70. #
  71. set blocks(2) [string trimleft [string map [list \\\\ \\] {
  72. Replace.exe:
  73. $(CSC) /target:exe $(TOP)\Replace.cs
  74. sqlite3.def: Replace.exe $(LIBOBJ)
  75. echo EXPORTS > sqlite3.def
  76. dumpbin /all $(LIBOBJ) \\
  77. | .\Replace.exe "^\s+/EXPORT:_?(sqlite3(?:session|changeset|changegroup|rebaser|rbu)?_[^@,]*)(?:@\d+|,DATA)?$$" $$1 true \\
  78. | sort >> sqlite3.def
  79. }]]
  80. set data "#### DO NOT EDIT ####\n"
  81. append data "# This makefile is automatically "
  82. append data "generated from the [file tail $fromFileName] at\n"
  83. append data "# the root of the canonical SQLite source tree (not the\n"
  84. append data "# amalgamation tarball) using the tool/[file tail $argv0]\n"
  85. append data "# script.\n#\n\n"
  86. append data [readFile $fromFileName]
  87. regsub -all -- {# <<mark>>\n.*?# <</mark>>\n} \
  88. $data "" data
  89. foreach i [lsort -integer [array names blocks]] {
  90. regsub -all -- [substVars \
  91. {# <<block${i}>>\n.*?# <</block${i}>>\n}] \
  92. $data [escapeSubSpec $blocks($i)] data
  93. }
  94. set data [string map [list " -I\$(TOP)\\src" ""] $data]
  95. set data [string map [list " libsqlite3.lib" ""] $data]
  96. set data [string map [list " \$(ALL_TCL_TARGETS)" ""] $data]
  97. set data [string map [list "\$(TOP)\\src\\" "\$(TOP)\\"] $data]
  98. writeFile $toFileName $data
  99. puts "generated $toFileName from $fromFileName"