main.c 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /***************************************************************************
  2. *
  3. * MODULE: g.version
  4. * AUTHOR(S): Michael Shapiro, CERL
  5. * Andreas Lange - <andreas.lange rhein-main.de>
  6. * Justin Hickey - Thailand - jhickey hpcc.nectec.or.th
  7. * Extended info by Martin Landa <landa.martin gmail.com>
  8. * PURPOSE: Output GRASS version number, date and copyright message.
  9. *
  10. * COPYRIGHT: (C) 2000-2015 by the GRASS Development Team
  11. *
  12. * This program is free software under the GPL (>=v2)
  13. * Read the file COPYING that comes with GRASS for details.
  14. *****************************************************************************/
  15. #include <stdlib.h>
  16. #include <stdio.h>
  17. #include <string.h>
  18. #include <grass/gis.h>
  19. #include <grass/glocale.h>
  20. #include "local_proto.h"
  21. #ifdef HAVE_PROJ_H
  22. #include <proj.h>
  23. #else
  24. #include <proj_api.h>
  25. #endif
  26. #ifdef HAVE_GDAL
  27. #include <gdal_version.h>
  28. #endif
  29. #ifdef HAVE_GEOS
  30. #include <geos_c.h>
  31. #endif
  32. #ifdef HAVE_SQLITE
  33. #include <sqlite3.h>
  34. #endif
  35. #ifndef GRASS_VERSION_UPDATE_PKG
  36. #define GRASS_VERSION_UPDATE_PKG "0.1"
  37. #endif
  38. /* TODO: remove this style of include */
  39. static const char COPYING[] =
  40. #include <grass/copying.h>
  41. ;
  42. static const char CITING[] =
  43. #include <grass/citing.h>
  44. ;
  45. static const char GRASS_CONFIGURE_PARAMS[] =
  46. #include <grass/confparms.h>
  47. ;
  48. int main(int argc, char *argv[])
  49. {
  50. struct GModule *module;
  51. struct Flag *copyright, *build, *gish_rev, *cite_flag, *shell, *extended;
  52. G_gisinit(argv[0]);
  53. module = G_define_module();
  54. G_add_keyword(_("general"));
  55. G_add_keyword(_("support"));
  56. G_add_keyword(_("citing"));
  57. G_add_keyword(_("copyright"));
  58. G_add_keyword(_("version"));
  59. G_add_keyword(_("license"));
  60. module->label = _("Displays GRASS GIS version info.");
  61. module->description = _("Optionally also prints build or copyright information.");
  62. copyright = G_define_flag();
  63. copyright->key = 'c';
  64. copyright->description = _("Print also the copyright message");
  65. copyright->guisection = _("Additional info");
  66. cite_flag = G_define_flag();
  67. cite_flag->key = 'x';
  68. cite_flag->description = _("Print also the citation options");
  69. cite_flag->guisection = _("Additional info");
  70. build = G_define_flag();
  71. build->key = 'b';
  72. build->description = _("Print also the build information");
  73. build->guisection = _("Additional info");
  74. gish_rev = G_define_flag();
  75. gish_rev->key = 'r';
  76. /* this was never the library revision number and date
  77. * it was the revision number and date of gis.h
  78. * now it is the git hash and date of all GRASS headers
  79. * (and anything else in include) */
  80. gish_rev->description =
  81. _("Print also the GIS library revision number and date");
  82. gish_rev->guisection = _("Additional info");
  83. extended = G_define_flag();
  84. extended->key = 'e';
  85. extended->label = _("Print also extended info for additional libraries");
  86. extended->description = _("GDAL/OGR, PROJ, GEOS");
  87. extended->guisection = _("Additional info");
  88. shell = G_define_flag();
  89. shell->key = 'g';
  90. shell->description = _("Print info in shell script style (including Git reference commit)");
  91. shell->guisection = _("Shell");
  92. if (G_parser(argc, argv))
  93. exit(EXIT_FAILURE);
  94. if (shell->answer) {
  95. fprintf(stdout, "version=%s\n", GRASS_VERSION_NUMBER);
  96. fprintf(stdout, "date=%s\n", GRASS_VERSION_DATE);
  97. fprintf(stdout, "revision=%s\n", GRASS_VERSION_GIT);
  98. fprintf(stdout, "build_date=%d-%02d-%02d\n", YEAR, MONTH, DAY);
  99. fprintf(stdout, "build_platform=%s\n", ARCH);
  100. fprintf(stdout, "build_off_t_size=%lu\n", sizeof(off_t));
  101. }
  102. else {
  103. fprintf(stdout, "GRASS %s (%s)\n",
  104. GRASS_VERSION_NUMBER, GRASS_VERSION_DATE);
  105. }
  106. if (copyright->answer) {
  107. fprintf(stdout, "\n");
  108. fputs(COPYING, stdout);
  109. }
  110. if (cite_flag->answer) {
  111. fprintf(stdout, "\n");
  112. fputs(CITING, stdout);
  113. }
  114. if (build->answer) {
  115. fprintf(stdout, "\n");
  116. fputs(GRASS_CONFIGURE_PARAMS, stdout);
  117. fprintf(stdout, "\n");
  118. }
  119. if (gish_rev->answer) {
  120. char *rev_ver = GIS_H_VERSION;
  121. char *rev_time = GIS_H_DATE;
  122. int no_libgis = FALSE;
  123. if (*rev_ver && *rev_time) {
  124. if (shell->answer) {
  125. fprintf(stdout, "libgis_revision=%s\n", rev_ver);
  126. fprintf(stdout, "libgis_date=%s\n", rev_time);
  127. }
  128. else {
  129. fprintf(stdout, "libgis revision: %s\n", rev_ver);
  130. fprintf(stdout, "libgis date: %s\n", rev_time);
  131. }
  132. }
  133. else {
  134. no_libgis = TRUE;
  135. if (shell->answer) {
  136. fprintf(stdout, "libgis_revision=\n");
  137. fprintf(stdout, "libgis_date=\n");
  138. G_warning("GRASS GIS libgis version and date number not available");
  139. /* this can be alternatively fatal error or it can cause
  140. fatal error later */
  141. }
  142. else {
  143. fprintf(stdout,
  144. _("Cannot determine GRASS libgis version and date number."
  145. " The GRASS build might be broken."
  146. " Report this to developers or packagers.\n"));
  147. }
  148. }
  149. if (no_libgis) {
  150. G_debug(1,
  151. _("GRASS GIS libgis version and date number don't have the expected format."
  152. " Trying to print the original strings..."));
  153. G_debug(1, _("GIS_H_VERSION=\"%s\""), GIS_H_VERSION);
  154. G_debug(1, _("GIS_H_DATE=\"%s\""), GIS_H_DATE);
  155. }
  156. }
  157. if (extended->answer) {
  158. char *proj = NULL;
  159. #ifdef HAVE_PROJ_H
  160. G_asprintf(&proj, "%d%d%d", PROJ_VERSION_MAJOR,
  161. PROJ_VERSION_MINOR,
  162. PROJ_VERSION_PATCH);
  163. #else
  164. G_asprintf(&proj, "%d", PJ_VERSION);
  165. #endif
  166. if (strlen(proj) == 3) {
  167. if (shell->answer)
  168. fprintf(stdout, "proj=%c.%c.%c\n", proj[0], proj[1], proj[2]);
  169. else
  170. fprintf(stdout, "PROJ: %c.%c.%c\n", proj[0], proj[1], proj[2]);
  171. }
  172. else {
  173. if (shell->answer)
  174. fprintf(stdout, "proj=%s\n", proj);
  175. else
  176. fprintf(stdout, "PROJ: %s\n", proj);
  177. }
  178. #ifdef HAVE_GDAL
  179. if (shell->answer)
  180. fprintf(stdout, "gdal=%s\n", GDAL_RELEASE_NAME);
  181. else
  182. fprintf(stdout, "GDAL/OGR: %s\n", GDAL_RELEASE_NAME);
  183. #else
  184. if (shell->answer)
  185. fprintf(stdout, "gdal=\n");
  186. else
  187. fprintf(stdout, "%s\n", _("GRASS not compiled with GDAL/OGR support"));
  188. #endif
  189. #ifdef HAVE_GEOS
  190. if (shell->answer)
  191. fprintf(stdout, "geos=%s\n", GEOS_VERSION);
  192. else
  193. fprintf(stdout, "GEOS: %s\n", GEOS_VERSION);
  194. #else
  195. if (shell->answer)
  196. fprintf(stdout, "geos=\n");
  197. else
  198. fprintf(stdout, "%s\n", _("GRASS not compiled with GEOS support"));
  199. #endif
  200. #ifdef HAVE_SQLITE
  201. if (shell->answer)
  202. fprintf(stdout, "sqlite=%s\n", SQLITE_VERSION);
  203. else
  204. fprintf(stdout, "SQLite: %s\n", SQLITE_VERSION);
  205. #else
  206. if (shell->answer)
  207. fprintf(stdout, "sqlite=\n");
  208. else
  209. fprintf(stdout, "%s\n", _("GRASS not compiled with SQLite support"));
  210. #endif
  211. }
  212. return (EXIT_SUCCESS);
  213. }