gen_dll_res.ps1 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. param ([string]$BasePath = ".\")
  2. $Host.SetShouldExit(111) # Set non-zero return code until task successfully finished
  3. $ErrorActionPreference = "Stop" # Stop on any error
  4. Remove-Variable MHD_ver,MHD_ver_major,MHD_ver_minor,MHD_ver_patchlev -ErrorAction:SilentlyContinue
  5. Write-Output "Processing: ${BasePath}..\..\configure.ac"
  6. foreach($line in Get-Content "${BasePath}..\..\configure.ac")
  7. {
  8. if ($line -match '^AC_INIT\(\[(?:GNU )?libmicrohttpd\],\[((\d+).(\d+).(\d+))\]')
  9. {
  10. [string]$MHD_ver = $Matches[1].ToString()
  11. [string]$MHD_ver_major = $Matches[2].ToString()
  12. [string]$MHD_ver_minor = $Matches[3].ToString()
  13. [string]$MHD_ver_patchlev = $Matches[4].ToString()
  14. break
  15. }
  16. }
  17. if ("$MHD_ver" -eq "" -or "$MHD_ver_major" -eq "" -or "$MHD_ver_minor" -eq "" -or "$MHD_ver_patchlev" -eq "")
  18. {
  19. Throw "Can't find MHD version in ${BasePath}..\..\configure.ac"
  20. }
  21. Write-Output "Detected MHD version: $MHD_ver"
  22. Write-Output "Generating ${BasePath}microhttpd_dll_res_vc.rc"
  23. Get-Content "${BasePath}microhttpd_dll_res_vc.rc.in" | ForEach-Object {
  24. $_ -replace '@PACKAGE_VERSION_MAJOR@',"$MHD_ver_major" `
  25. -replace '@PACKAGE_VERSION_MINOR@', "$MHD_ver_minor" `
  26. -replace '@PACKAGE_VERSION_SUBMINOR@', "$MHD_ver_patchlev" `
  27. -replace '@PACKAGE_VERSION@', "$MHD_ver"
  28. } | Out-File -FilePath "${BasePath}microhttpd_dll_res_vc.rc" -Force
  29. $Host.SetShouldExit(0) # Reset return code
  30. Write-Output "${BasePath}microhttpd_dll_res_vc.rc was generated "
  31. exit 0 # Exit with success code