Skip to content

Commit 95dc7ff

Browse files
committed
Auto SPICE & CDF dependency download/build
Will download & build CDF and SPICE utilities as needed when the following environment variables are not defined: CSPICE_INC - If not set CSPICE is downloaded CSPICE_LIB - If not set CSPICE is built CDF_INC - If not set CDF libraries are downloaded CDF_LIB - If not set CDF libs are built For larger projects incorporating das2C, define the variables above before calling make.
1 parent 4430754 commit 95dc7ff

File tree

4 files changed

+160
-80
lines changed

4 files changed

+160
-80
lines changed

Makefile

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@ INST_DOC=$(INST_SHARE)/doc
2121
endif
2222

2323
ifeq ($(N_ARCH),)
24-
N_ARCH=$(shell uname).$(shell uname -m)
25-
N_ARCH:=$(subst /,_,$(N_ARCH))
24+
N_ARCH=/
25+
#N_ARCH=$(shell uname).$(shell uname -m)
26+
#N_ARCH:=$(subst /,_,$(N_ARCH))
2627
endif
2728

2829
ifeq ($(INST_INC),)
@@ -37,12 +38,27 @@ ifeq ($(INST_NAT_LIB),)
3738
INST_NAT_LIB=$(PREFIX)/lib/$(N_ARCH)
3839
endif
3940

41+
BLD_CSPICE=0
4042
ifeq ($(SPICE),yes)
43+
ifeq ($(CSPICE_INC),)
44+
$(info CSPICE_INC not set, download CSPICE sources if needed)
45+
BLD_CSPICE=1
46+
endif
4147
ifeq ($(CSPICE_LIB),)
42-
$(error To add spice support set CSPICE_LIB to the absolute path of your cspice.a file)
48+
$(info CSPICE_LIB not set, build CSPICE from source if needed)
49+
BLD_CSPICE=1
4350
endif
44-
ifeq ($(CSPICE_INC),)
45-
$(error To add spice support set CSPICE_INC to your cspice header directory)
51+
endif
52+
53+
BLD_CDF=0
54+
ifeq ($(CDF),yes)
55+
ifeq ($(CDF_INC),)
56+
$(info CDF_INC not set, download CDF sources if needed)
57+
BLD_CDF=1
58+
endif
59+
ifeq ($(CDF_LIB),)
60+
$(info CDF_LIB not set, build CDF lib from sources if needed)
61+
BLD_CDF=1
4662
endif
4763
endif
4864

README.md

Lines changed: 55 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,19 @@ server by a client program and a self-describing stream of data values covering
88
the requested time range, at the requested time resolution, is provided in the
99
response body.
1010

11-
This package, *das2C*, provides a portable C libraries and programs for:
11+
This package, *das2C*, contains a portable C library and utility
12+
programs that provide:
1213

13-
* Reading and writing dasStream versions 2.x and 3.X
14+
* XML schema definitions defining das2 and das3 headers.
15+
* Libs for Reading and writing dasStream versions 2.x and 3.X
1416
* General SI unit manipulation
1517
* Dataset accumulation
1618
* Generating spectrograms from time series data
1719
* Time averaging long duration spectrograms
1820
* Performing SPICE operations on data streams
1921
* Converting streams into export formats such as CSV and CDF.
2022

21-
The core library is used by [das2py](https://github.com/das-developers/das2py) and
22-
[das2dlm](https://github.com/das-developers/das2dlm).
23-
24-
Das2C utility programs are used by [dasFlex](https://github.com/das-developers/dasFlex)
25-
web-services for server-side processing.
26-
27-
Top level XML schema definition for das2 and das3 headers are also kept here.
23+
The core library is used by [das2py](https://github.com/das-developers/das2py) and [das2dlm](https://github.com/das-developers/das2dlm). The utility programs are used by [dasFlex](https://github.com/das-developers/dasFlex) web-services for server-side processing.
2824

2925
To find out more about das2 visit https://das2.org.
3026

@@ -49,8 +45,6 @@ build libdas2.3:
4945
* **expat** - XML Parsing library
5046
* **fftw3** - Fastest Fourier Transform in the West, version 3.
5147
* **openssl** - Secure network socket library
52-
* **libcdf** - NASA Common Data Format file creation (optional)
53-
* **cspice** - NAIF SPICE spacecraft position library (optional)
5448

5549
Though package names vary from system to system, commands for installing the
5650
prequisites are provided below \.\.\.
@@ -70,32 +64,22 @@ $ brew install fftw
7064
The expat library should already be present on MacOS once the compiler install
7165
command `xcode-select --install` has been run.
7266

73-
The cspice and libcdf libraries are maunal download and un-pack only. Here's
74-
where I typically put them:
75-
```bash
76-
/usr/local/cspice
77-
/usr/local/cdf
78-
```
79-
or on Windows
80-
```batchfile
81-
C:\opt\cspice
82-
C:\opt\cdf
83-
```
67+
If your system already has the NAIF CSpice Toolkit and the Goddard CDF libraries
68+
installed you can set environment variables to incorporate them into the build,
69+
otherwise the Makefiles will download them automatically.
8470

85-
## Manual Build and Install
86-
87-
Decide where you want to install the software. In the instructions below we've
88-
chosen `/usr/local` but anywhere is fine.
71+
## Manual Build
8972

9073
For POSIX compliant systems (Linux, MacOS, Android) issue the following commands
91-
to build, test and install the software.
74+
to build, and test the software.
9275

93-
```
94-
$ export PREFIX=/usr/local
95-
$ export N_ARCH=/ # For generic builds, omit per-OS sub-directories.
96-
$ make
97-
$ make test
98-
$ make install
76+
```bash
77+
$ make SPICE=yes CDF=yes
78+
$ make SPICE=yes CDF=yes test
79+
80+
# To rebuild
81+
$ make SPICE=yes CDF=yes clean # Removes only das2C output
82+
$ make SPICE=yes CDF=yes distclean # Removes CDF and SPICE libs as well
9983
```
10084

10185
For Windows systems issue the following commands in a command shell to build, test
@@ -105,32 +89,37 @@ and install the software.
10589
> set N_ARCH=\
10690
> set LIBRARY_INC= ::location of your vcpkg installed\x64-windows-static include
10791
> set LIBRARY_LIB= ::location of your vcpkg installed\x64-windows-static lib
108-
> set CSPICE_INC=C:\opt\cspice\include :: only if building with spice
109-
> set CSPICE_LIB=C:\opt\cspice\lib\cspice.lib :: only if building with spice
110-
> set CDF_INC=C:\opt\cdf\include\ :: only if building with cdf
111-
> set CDF_LIB=C:\opt\cdf\lib\libcdf.lib :: only if building with cdf
112-
> set INSTALL_PREFIX=C:\opt :: for example
11392
114-
> nmake.exe /nologo /f buildfiles\Windows.mak build
115-
> nmake.exe /nologo /f buildfiles\Windows.mak run_test
116-
> nmake.exe /nologo /f buildfiles\Windows.mak install
93+
> vcvars.bat ::puts nmake.exe, cl.exe, link.exe, etc. on your path
94+
95+
> nmake.exe /nologo /f buildfiles\Windows.mak spice=yes cdf=yes build
96+
> nmake.exe /nologo /f buildfiles\Windows.mak spice=yes cdf=yes run_test
97+
```
98+
99+
## Manual Install
117100

118-
:: Or with CDF and SPICE support
119-
> nmake.exe /nologo /f buildfiles\Windows.mak SPICE=yes CDF=yes build
120-
> nmake.exe /nologo /f buildfiles\Windows.mak SPICE=yes CDF=yes run_test
121-
> nmake.exe /nologo /f buildfiles\Windows.mak SPICE=yes CDF=yes test_spice
122-
> nmake.exe /nologo /f buildfiles\Windows.mak SPICE=yes CDF=yes test_cdf
123-
> nmake.exe /nologo /f buildfiles\Windows.mak SPICE=yes CDF=yes install
101+
If you wish to install directly from the source tree, set an install prefix and
102+
then run make install. For example on Linux:
124103

104+
```bash
105+
$ make PREFIX=/usr/local SPICE=yes CDF=yes install # adjust destination to taste
106+
```
107+
or on Windows:
108+
```
109+
> set INSTALL_PREFIX=C:\local :: for example
110+
> nmake /f buildfiles\Windows.mak SPICE=yes CDF=yes install
125111
```
126112

127-
## Usage
113+
## Using the Libray
128114

129115
By default all header files are copied into the subdirectory `das2` under
130-
`$PREFIX/include`. When writing code that uses das2 headers add the include
131-
directory to the compiler command line in a manner similar to the following:
116+
`$PREFIX/include`. When writing code that uses *das* headers add the top
117+
level include directory to the compiler command line in a manner similar to
118+
the following:
132119
```bash
133120
-I $PREFIX/include
121+
```
122+
```batchfile
134123
/I %PREFIX%/include
135124
```
136125
and use the das2 subdirectory in your include statements, for example:
@@ -141,25 +130,33 @@ Common linker arguments for building libdas dependent applications follow.
141130
For open source programs static linking is perfectly fine:
142131

143132
```make
144-
$(PREFIX)/lib/libdas3.0.a -lexpat -lssl -lcrypto -lz -lm -lpthread # gnu make
133+
$(PREFIX)/lib/libdas.a -lexpat -lssl -lcrypto -lz -lm -lpthread # gnu make
145134

146-
$(INSTALL_PREFIX)/lib/libdas3.0.lib Advapi32.lib User32.lib Crypt32.lib ws2_32.lib # win nmake
135+
$(INSTALL_PREFIX)/lib/libdas.lib Advapi32.lib User32.lib Crypt32.lib ws2_32.lib # win nmake
147136
```
148137

149-
For closed source applications, link against shared das2 objects (i.e. libdas3.0.so
150-
or das3.0dll) as required by the LGPL:
138+
For closed source applications, link against shared das2 objects (i.e. libdas.so.3
139+
or das.dll) as required by the LGPL:
151140

152141
```make
153-
-L$(PREFIX)/lib -ldas2.3 -lexpat -lssl -lcrypto -lz -lm -lpthread # gnu make
142+
-L$(PREFIX)/lib -ldas -lexpat -lssl -lcrypto -lz -lm -lpthread # gnu make
154143

155144
/L $(INSTALL_PREFIX)\bin das2.3.dll das2.3.lib Advapi32.lib User32.lib Crypt32.lib ws2_32.lib # win nmake
156145
```
157146

158-
Note that on Windows, `libdas3.0lib` is the full static library but the file
159-
`das3.0.lib` is merely a DLL import library.
147+
Note that on Windows, `libdas.lib` is the full static library but the file `das.lib`
148+
is merely a DLL import library.
149+
150+
151+
## Using the Utility programs
152+
153+
Most of the utility programs filters are designed to take a *das* stream
154+
on standard input and output a transformed stream to standard output. The
155+
**das3_cdf** program
156+
160157

161158

162-
## Building with XMake
159+
## Building with XMake (unsupported)
163160

164161
Two build systems are provided for das2C. Plain ole GNU Make and Microsoft NMake files, and an [xmake](https://github.com/xmake-io/xmake) file. Since xmake is both a package manager and a build tool, you do not need to install any prerequisites to build das2C with xmake, other then your compiler and xmake itself.
165162

buildfiles/Linux.mak

Lines changed: 84 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,34 @@
33
MD5SUM=md5sum
44
export MD5SUM
55

6+
BD=$(BUILD_DIR)
7+
8+
##############################################################################
9+
# Upstream Source dependencies
10+
11+
# You may already have libcdf.a and cspice.a in your build tree for other
12+
# parts of your project. If so use them by setting . If not, you can issue build depend first and dependency
13+
# sources will be downloaded and built.
14+
15+
LOC_CDF_DIST:=cdf39_0-dist
16+
LOC_CDF_URL:=https://spdf.gsfc.nasa.gov/pub/software/cdf/dist/cdf39_0/linux/$(LOC_CDF_DIST)-cdf.tar.gz
17+
LOC_CSPICE_URL:=https://naif.jpl.nasa.gov/pub/naif/toolkit//C/PC_Linux_GCC_64bit/packages/cspice.tar.Z
18+
19+
ifeq ($(BLD_CDF),1)
20+
CDF_INC:=$(BD)/$(LOC_CDF_DIST)/src/include
21+
CDF_LIB:=$(BD)/$(LOC_CDF_DIST)/src/lib/libcdf.a
22+
endif
23+
24+
ifeq ($(BLD_CSPICE),1)
25+
CSPICE_INC:=./$(BD)/cspice/include
26+
CSPICE_LIB:=./$(BD)/cspice/lib/cspice.a
27+
endif
28+
629

730
##############################################################################
831
# Project definitions
932

10-
TARG=libdas3.0
33+
TARG=libdas
1134

1235
SRCS:=das1.c array.c buffer.c builder.c cli.c codec.c credentials.c dataset.c \
1336
dataset_hdr2.c dataset_hdr3.c datum.c descriptor.c dft.c dimension.c dsdf.c \
@@ -47,8 +70,6 @@ ifeq ($(CDF),yes)
4770
UTIL_PROGS:=$(UTIL_PROGS) das3_cdf
4871
endif
4972

50-
BD=$(BUILD_DIR)
51-
5273
##############################################################################
5374
# Build definitions
5475

@@ -156,25 +177,32 @@ $(DESTDIR)$(INST_NAT_BIN)/%:$(BD)/%
156177

157178
# Direct make not to nuke the intermediate .o files
158179
.SECONDARY: $(BUILD_OBJS) $(UTIL_OBJS)
159-
.PHONY: test
180+
.PHONY: test build
160181

161182
## Explicit Rules ###########################################################
162183

163-
build:$(BD) $(BD)/$(TARG).a $(BD)/$(TARG).so \
164-
$(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS)
184+
# Building dependencies if needed
185+
#ifeq ($(BLD_CSPICE)$(BLD_CDF),00)
165186

166-
build_static:$(BD) $(BD)/$(TARG).a \
167-
$(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS)
187+
#build: $(BD)/$(TARG).a $(BD)/$(TARG).so $(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS) | $(BD)
188+
#build_static: $(BD) $(BD)/$(TARG).a $(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS) | $(BD)
168189

169-
$(BD)/$(TARG).a:$(BUILD_OBJS)
170-
ar rc $@ $(BUILD_OBJS)
171-
172-
$(BD)/$(TARG).so:$(BUILD_OBJS)
173-
gcc -shared -o $@ $(BUILD_OBJS)
190+
#else
191+
192+
build: build_dep $(BD)/$(TARG).a $(BD)/$(TARG).so $(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS) | $(BD)
193+
build_static:build_dep $(BD) $(BD)/$(TARG).a $(BUILD_UTIL_PROGS) $(BUILD_TEST_PROGS) | $(BD)
194+
195+
#endif
174196

175197
$(BD):
176198
@if [ ! -e "$(BD)" ]; then echo mkdir $(BD); \
177199
mkdir $(BD); chmod g+w $(BD); fi
200+
201+
$(BD)/$(TARG).a:$(BUILD_OBJS) | $(BD)
202+
ar rc $@ $(BUILD_OBJS)
203+
204+
$(BD)/$(TARG).so:$(BUILD_OBJS) | $(BD)
205+
gcc -shared -o $@ $(BUILD_OBJS)
178206

179207

180208
# Robert's tagged das1 reader breaks strict-aliasing expectations for C99
@@ -200,8 +228,45 @@ $(BD)/das3_cdf:utilities/das3_cdf.c $(BD)/$(TARG).a
200228
@if [ "$(CDF_LIB)" = "" ] ; then echo "CDF_LIB not set"; exit 3; fi
201229
$(CC) $(CFLAGS) -Wno-unused -I$(CDF_INC) -o $@ $< $(BD)/$(TARG).a $(CDF_LIB) $(LFLAGS)
202230

231+
232+
# Conditional rule
233+
ifeq ($(BLD_CSPICE)$(BLD_CDF),11)
234+
build_dep:$(CSPICE_LIB) $(CDF_LIB)
235+
else ifeq ($(BLD_CSPICE)$(BLD_CDF),10)
236+
build_dep:$(CSPICE_LIB) $(CDF_LIB)
237+
else ifeq ($(BLD_CSPICE)$(BLD_CDF),01)
238+
build_dep:$(CSPICE_LIB) $(CDF_LIB)
239+
else
240+
build_dep:
241+
endif
242+
243+
$(CSPICE_LIB): $(BD)/cspice.tar
244+
cd $(BD) && tar -mxvf cspice.tar
245+
246+
$(BD)/cspice.tar: | $(BD)
247+
curl $(LOC_CSPICE_URL) > $(BD)/cspice.tar.Z
248+
uncompress $(BD)/cspice.tar.Z
249+
250+
$(CDF_LIB): $(BD)/$(LOC_CDF_DIST)
251+
cd $(BUILD_DIR)/$(LOC_CDF_DIST) && $(MAKE) OS=linux ENV=gnu all
252+
253+
$(BD)/$(LOC_CDF_DIST): | $(BD)
254+
curl $(LOC_CDF_URL) > $(BD)/$(LOC_CDF_DIST)-cdf.tar.gz
255+
cd $(BD) && tar -xvf $(LOC_CDF_DIST)-cdf.tar.gz
256+
203257
# Run tests
204-
test: $(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
258+
ifeq ($(BLD_CSPICE)$(BLD_CDF),11)
259+
test:test_main test_spice test_cdf
260+
else ifeq ($(BLD_CSPICE)$(BLD_CDF),10)
261+
test:test_main test_spice
262+
else ifeq ($(BLD_CSPICE)$(BLD_CDF),01)
263+
test:test_main test_cdf
264+
else
265+
test:test_main
266+
endif
267+
268+
269+
test_main: $(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
205270
env DIFFCMD=diff test/das1_fxtime_test.sh $(BD)
206271
test/das2_ascii_test1.sh $(BD)
207272
test/das2_ascii_test2.sh $(BD)
@@ -232,7 +297,7 @@ test: $(BD) $(BD)/$(TARG).a $(BUILD_TEST_PROGS) $(BULID_UTIL_PROGS)
232297
@echo "INFO: Running unit test for ragged and unique iteration, $(BD)/TestIter..."
233298
$(BD)/TestIter
234299
@echo "INFO: Running unit test for CSVs with variable length item data, $(BD)/das3_csv"
235-
$(BD)/das3_csv < test/tracers_cdpu_status.d3b > $(BD)/tracers_cdpu_status.csv
300+
$(BD)/das3_csv < test/ex21_tracers_cdpu_status.d3b > $(BD)/ex21_tracers_cdpu_status.csv
236301
@echo "INFO: ==============================================="
237302
@echo "INFO: All core test programs completed without errors"
238303
@echo "INFO: ==============================================="
@@ -282,10 +347,12 @@ $(INST_DOC)/das2C:$(BD)/html
282347

283348
# Cleanup ####################################################################
284349
distclean:
285-
if [ -d "$(BD)" ]; then rm -r $(BD); fi
350+
if [ -d "$(BD)" ] ; then rm -r $(BD) ; fi
286351

287352
clean:
288-
rm -r $(BD)
353+
-rm $(BD)/das* $(BD)/Test* $(BD)/libdas*
354+
-rm $(BD)/*.o $(BD)/ex*
355+
-rm $(BD)/cred_test*
289356

290357

291358
## Automatic dependency tree generation for C code ###########################

0 commit comments

Comments
 (0)