Skip to content

Commit

Permalink
lib/external: Add parson library for JSON (#3028)
Browse files Browse the repository at this point in the history
* lib/external: Added documentation to adding new external libraries
* Updated GRASS Programmer's manual docs
* update parson from 1.5.2 to 1.5.3 released Oct 31st
  • Loading branch information
cwhite911 committed Jan 5, 2024
1 parent da06dd1 commit 53c362d
Show file tree
Hide file tree
Showing 13 changed files with 3,557 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ $(ARCH_DISTDIR)/%: %
$(INSTALL_DATA) $< $@

LIBDIRS = \
lib/external/parson \
lib/external/shapelib \
lib/datetime \
lib/gis \
Expand Down
18 changes: 17 additions & 1 deletion grasslib.dox
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ href="https://grass.osgeo.org">https://grass.osgeo.org</a>
\subsection misclibs Miscellaneous Libraries

- datetime: \ref datetime (DateTime library)
- external: \ref external (External libraries from other projects such as shapelib and \ref ccmathlib)
- external: \ref external (External libraries from other projects such as shapelib, parson and \ref ccmathlib)
- fonts: \ref fonts (GRASS fonts library)
- init: \ref init (GRASS initialization code + scripts)
- iostream: \ref iostream (fast I/O library)
Expand All @@ -131,6 +131,22 @@ href="https://grass.osgeo.org">https://grass.osgeo.org</a>
- manage: \ref managelib
- symbol: \ref symbol (Drawing symbols for %point %vector data library)

\subsection external Adding External Libraries

The following files must be added or updated when including a new external library.

- <b>add:</b> lib/external/<b>newlib</b>
- <b>add:</b> lib/external/<b>newlib</b>/*.c
- <b>add:</b> lib/external/<b>newlib</b>/*.h
- <b>add:</b> lib/external/<b>newlib</b>/LICENSE
- <b>add:</b> lib/external/<b>newlib</b>/Makefile
- <b>update:</b> lib/external/Makefile
- <b>update:</b> lib/external/README.license
- <b>update:</b> lib/README.md
- <b>update:</b> include/Make/Install.make
- <b>update:</b> include/Make/Grass.make
- <b>update:</b> Makefile

\section location File structure of GRASS Location

A GRASS <b>raster map</b> consists of several files in several subdirectories in a mapset,
Expand Down
1 change: 1 addition & 0 deletions include/Make/Grass.make
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ libs = \
NVIZ:nviz \
OGSF:ogsf \
OPTRI:optri \
PARSON:parson \
PNGDRIVER:pngdriver \
PSDRIVER:psdriver \
QTREE:qtree \
Expand Down
1 change: 1 addition & 0 deletions include/Make/Install.make
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ srclibsdist: distclean
-cp -rL utils ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL demolocation ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL include ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL --parents lib/external/parson ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL --parents lib/external/shapelib ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL --parents lib/external/bwidget ./grass-lib-$(GRASS_VERSION_NUMBER)
-cp -rL --parents lib/datetime ./grass-lib-$(GRASS_VERSION_NUMBER)
Expand Down
1 change: 1 addition & 0 deletions lib/README
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Current directory layout
- display: library for CELL driver
- edit: curses library
- external: external libraries
- external/parson: JSON serialization and deserialization functions
- external/shapelib: SHAPE file management functions
- fonts: fonts
- fonts/fonts
Expand Down
1 change: 1 addition & 0 deletions lib/external/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MODULE_TOPDIR = ../..

SUBDIRS = \
ccmath \
parson \
shapelib

include $(MODULE_TOPDIR)/include/Make/Dir.make
Expand Down
4 changes: 4 additions & 0 deletions lib/external/README.license
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ comments carefully.
* shapelib/ (MIT/X)
Shapefile read/write functions.
Copyright (c) 2007, Frank Warmerdam

* parson/ (MIT/X)
JSON parsing and encoding functions version 1.5.2.
Copyright (c) 2022, Krzysztof Gabis
120 changes: 120 additions & 0 deletions lib/external/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
# How to add a new external library

The following procedure will walk you through adding a new third-party
library to GRASS GIS.

## License

Before you start, make sure that the library you want to include is in
compliance with the GRASS GIS licence.

### Approved Third-Party Licenses

* MIT/X
* GPLv2
* LGPL 2.1
* MPL 2.0
* BSD-3-Clause
* Public Domain

## Procedure

* Create a directory that will contain the new library's files
in `lib/external/<new-library>`

* Add the new libraries header and source files, license, and README to the newly
created directory.

* Add a new `Makefile` to the directory.

```make
MODULE_TOPDIR = ../../..

# replace SHAPE with new library name
LIB = SHAPE

include $(MODULE_TOPDIR)/include/Make/Lib.make

default: headers
$(MAKE) lib

# Update header file reference to the new library
headers: $(ARCH_INCDIR)/shapefil.h

$(ARCH_INCDIR)/%.h: %.h
$(INSTALL_DATA) $< $@
```

* Update `lib/external/Makefile` to include the new subdirectory.

```make
MODULE_TOPDIR = ../..

SUBDIRS = \
ccmath \
parson \
shapelib \
# Add new directory here

include $(MODULE_TOPDIR)/include/Make/Dir.make

default: parsubdirs
```

* Update the `lib/external/README.license` with a new entry containing
the *library name*, *license*, *description*, *version*, *copyright*,
and *authors name*.

```txt
* parson/ (MIT/X)
JSON parsing and encoding functions version 1.5.2.
Copyright (c) 2022, Krzysztof Gabis
```

* Update `lib/README` with a new entry under external libraries.

```md
external: external libraries
- external/parson: JSON serialization and deserialization functions
- external/shapelib: SHAPE file management functions
<!-- - Add new entry here -->
```

* Update `include/Make/Install.make`

```make
-cp -rL --parents lib/external/<new library> ./grass-lib-$(GRASS_VERSION_NUMBER)
```

* Add reference to library in `include/Make/Grass.make` in alphabetical order.

```make
<Uppercase library name>:<Lowercase library name>

# example for the parson library
PARSON:parson \
```

* Add reference to library in the root `Makefile`.

```make
LIBDIRS = \
lib/external/parson \
lib/external/shapelib \
# New reference
...
```

* The library should now be able to successfully compile.

To test run the `make` command.

```bash
make
```

* If no errors are found the library should now be able to be used in development.

```c
#include <grass/<new-library.h>
```
21 changes: 21 additions & 0 deletions lib/external/parson/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2012 - 2022 Krzysztof Gabis

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
13 changes: 13 additions & 0 deletions lib/external/parson/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
MODULE_TOPDIR = ../../..

LIB = PARSON

include $(MODULE_TOPDIR)/include/Make/Lib.make

default: headers
$(MAKE) lib

headers: $(ARCH_INCDIR)/parson.h

$(ARCH_INCDIR)/%.h: %.h
$(INSTALL_DATA) $< $@
Loading

0 comments on commit 53c362d

Please sign in to comment.