1# -*- makefile -*-
2# Makefile for Generic Unix with GCC compiler
3
4FAULT_TOLERANT?=0
5DEBUG?=1
6
7# Default install directory
8PREFIX ?= /usr/local
9
10# Place where to copy FastDB header files
11INCSPATH=$(DESTDIR)$(PREFIX)/include/fastdb
12
13#Place where to copy Fastdb library
14LIBSPATH=$(DESTDIR)$(PREFIX)/lib
15
16#Place where to copy Fastdb subsql utility
17BINSPATH=$(DESTDIR)$(PREFIX)/bin
18
19ifdef NO_PTHREADS
20OBJS = class.o compiler.o database.o xml.o hashtab.o file.o symtab.o ttree.o rtree.o container.o \
21	cursor.o query.o wwwapi.o unisock.o sync.o localcli.o stdtp.o
22else
23OBJS = class.o compiler.o database.o xml.o hashtab.o file.o symtab.o ttree.o rtree.o container.o \
24	cursor.o query.o wwwapi.o unisock.o sync.o localcli.o stdtp.o server.o
25endif
26
27CLI_OBJS = cli.o unisock.o repsock.o stdtp.o
28
29INCS = inc/fastdb.h inc/stdtp.h inc/config.h inc/class.h inc/database.h inc/cursor.h inc/reference.h inc/wwwapi.h \
30	inc/cli.h inc/array.h inc/file.h inc/hashtab.h inc/ttree.h inc/rtree.h inc/container.h inc/sync.h inc/sync_unix.h \
31	inc/query.h inc/datetime.h inc/harray.h inc/rectangle.h inc/timeseries.h inc/exception.h
32
33#
34# threads settings - please comment this lines for single-threaded libs
35#
36ifdef NO_PTHREADS
37TFLAGS=-DNO_PTHREADS
38THRLIBS=
39SUFF=
40else
41TFLAGS=-D_REENTRANT
42THRLIBS=-lpthread
43SUFF=_r
44endif
45
46STDLIBS =  -lm  $(THRLIBS)
47SOCKLIBS =
48TFLAGS += -fPIC
49
50
51VERSION=2
52FASTDB_LIB = libfastdb$(SUFF).a
53FASTDB_SHARED = libfastdb$(SUFF).so.${VERSION}
54CLI_LIB = libcli$(SUFF).a
55JNI_LIB = libjnicli$(SUFF).so.${VERSION}
56CLI_SHARED = libcli$(SUFF).so.${VERSION}
57
58EXES = subsql forcerecovery cleanupsem inspectsem
59#FASTDB_LIBS=-L. -lfastdb$(SUFF)
60#CLI_LIBS=-L. -lcli$(SUFF)
61FASTDB_LIBS=$(FASTDB_LIB)
62CLI_LIBS=$(CLI_LIB)
63
64EXAMPLES = guess testdb testleak testfrag testjoin testddl testperf testpar testindex testarridx testudt testfuzzy testsync testconc testiref testtrav testidx clitest clitest2 testrect testalter testraw localclitest testharr testspat testtimeseries testwcs testtl
65
66WEB_EXAMPLES = cgistub bugdb clidb
67
68CC = ${CXX}
69
70# DEFS macro is deprecatred, edit config.h file instead
71DEFS = -Wno-invalid-offsetof -Wno-write-strings
72
73ifeq ($(DEBUG), 1)
74CFLAGS = -c -Iinc ${CXXFLAGS} -fPIC $(DEFS) $(TFLAGS)
75else
76CFLAGS = -c -Iinc -Wall -O5 -g -fPIC $(DEFS) $(TFLAGS)
77endif
78
79SHFLAGS=-shared -Wl,-soname,$@
80#SHFLAGS=-shared
81
82
83LD = $(CC)
84LDFLAGS = $(TFLAGS)
85
86AR = ar
87ARFLAGS = -cru
88
89ifneq (,$(findstring FreeBSD,$(OSTYPE)))
90RANLIB = ranlib
91else
92RANLIB = true
93endif
94
95ifneq (0,$(FAULT_TOLERANT))
96STDLIBS +=  $(SOCKLIBS)
97DEFS += -DREPLICATION_SUPPORT
98endif
99
100
101all: static shared bins
102
103static: $(FASTDB_LIB) $(CLI_LIB)
104
105shared: $(FASTDB_SHARED) $(CLI_SHARED)
106
107bins: $(EXES) $(EXAMPLES)
108
109www: $(FASTDB_SHARED) $(WEB_EXAMPLES)
110
111
112class.o: src/class.cpp inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
113	$(CC) $(CFLAGS) src/class.cpp
114
115compiler.o: src/compiler.cpp inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
116	$(CC) $(CFLAGS) src/compiler.cpp
117
118query.o: src/query.cpp inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
119	$(CC) $(CFLAGS) src/query.cpp
120
121database.o: src/database.cpp inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
122	$(CC) $(CFLAGS) src/database.cpp
123
124xml.o: src/xml.cpp inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
125	$(CC) $(CFLAGS) src/xml.cpp
126
127localcli.o: src/localcli.cpp inc/compiler.h inc/compiler.d inc/symtab.h inc/localcli.h $(INCS)
128	$(CC) $(CFLAGS) src/localcli.cpp
129
130cursor.o: src/cursor.cpp inc/compiler.h inc/compiler.d $(INCS)
131	$(CC) $(CFLAGS) src/cursor.cpp
132
133hashtab.o: src/hashtab.cpp $(INCS)
134	$(CC) $(CFLAGS) src/hashtab.cpp
135
136file.o: src/file.cpp $(INCS)
137	$(CC) $(CFLAGS) src/file.cpp
138
139stdtp.o: src/stdtp.cpp $(INCS)
140	$(CC) $(CFLAGS) src/stdtp.cpp
141
142sync.o: src/sync.cpp $(INCS)
143	$(CC) $(CFLAGS) src/sync.cpp
144
145symtab.o: src/symtab.cpp inc/symtab.h $(INCS)
146	$(CC) $(CFLAGS) src/symtab.cpp
147
148ttree.o: src/ttree.cpp $(INCS)
149	$(CC) $(CFLAGS) src/ttree.cpp
150
151rtree.o: src/rtree.cpp $(INCS)
152	$(CC) $(CFLAGS) src/rtree.cpp
153
154container.o: src/container.cpp $(INCS)
155	$(CC) $(CFLAGS) src/container.cpp
156
157wwwapi.o: src/wwwapi.cpp inc/wwwapi.h inc/sockio.h inc/stdtp.h inc/sync.h inc/config.h inc/sync_unix.h
158	$(CC) $(CFLAGS) src/wwwapi.cpp
159
160unisock.o: src/unisock.cpp inc/unisock.h inc/sockio.h inc/stdtp.h
161	$(CC) $(CFLAGS) src/unisock.cpp
162
163repsock.o: src/repsock.cpp inc/unisock.h inc/sockio.h inc/stdtp.h inc/sync.h inc/sync_unix.h inc/config.h
164	$(CC) $(CFLAGS) src/repsock.cpp
165
166cli.o: src/cli.cpp inc/cli.h inc/cliproto.h
167	$(CC) $(CFLAGS) src/cli.cpp
168
169$(FASTDB_LIB): $(OBJS)
170	rm -f $(FASTDB_LIB)
171	$(AR) $(ARFLAGS) $(FASTDB_LIB) $(OBJS)
172	$(RANLIB) $(FASTDB_LIB)
173
174$(FASTDB_SHARED): $(OBJS)
175	rm -f $(FASTDB_SHARED)
176	$(CC) $(SHFLAGS) -o $(FASTDB_SHARED) $(OBJS) $(THRLIBS)
177	ln -f -s $(FASTDB_SHARED) libfastdb$(SUFF).so
178
179$(CLI_LIB): $(CLI_OBJS)
180	rm -f $(CLI_LIB)
181	$(AR) $(ARFLAGS) $(CLI_LIB) $(CLI_OBJS)
182	$(RANLIB) $(CLI_LIB)
183
184$(CLI_SHARED): $(CLI_OBJS)
185	rm -f $(CLI_SHARED)
186	$(CC) $(SHFLAGS) -o  $(CLI_SHARED) $(CLI_OBJS) $(THRLIBS)
187	ln -f -s $(CLI_SHARED) libcli$(SUFF).so
188
189
190clitest.o: examples/clitest.c inc/cli.h
191	$(CC) $(CFLAGS) examples/clitest.c
192
193clitest: clitest.o $(CLI_LIB)
194	$(LD) $(LDFLAGS) -o clitest clitest.o $(CLI_LIBS) $(STDLIBS) $(SOCKLIBS)
195
196clitest2.o: examples/clitest2.c inc/cli.h
197	$(CC) $(CFLAGS) examples/clitest2.c
198
199clitest2: clitest2.o $(FASTDB_LIB)
200	$(LD) $(LDFLAGS) -o clitest2 clitest2.o $(FASTDB_LIB) $(STDLIBS)
201
202testalter.o: examples/testalter.c inc/cli.h
203	$(CC) $(CFLAGS) examples/testalter.c
204
205testalter: testalter.o $(FASTDB_LIB)
206	$(LD) $(LDFLAGS) -o testalter testalter.o $(FASTDB_LIB) $(STDLIBS)
207
208localclitest: clitest.o $(FASTDB_LIB)
209	$(LD) $(LDFLAGS) -o localclitest clitest.o $(FASTDB_LIB) $(STDLIBS)
210
211testrect.o: examples/testrect.c inc/cli.h
212	$(CC) $(CFLAGS) examples/testrect.c
213
214testrect: testrect.o $(FASTDB_LIB)
215	$(LD) $(LDFLAGS) -o testrect testrect.o $(FASTDB_LIB) $(STDLIBS)
216
217subsql.o: src/subsql.cpp inc/subsql.h inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
218	$(CC) $(CFLAGS) src/subsql.cpp
219
220server.o: src/server.cpp inc/server.h inc/cli.h inc/cliproto.h inc/subsql.h inc/compiler.h inc/compiler.d inc/symtab.h $(INCS)
221	$(CC) $(CFLAGS) src/server.cpp
222
223subsql: subsql.o $(FASTDB_LIB)
224	$(LD) $(LDFLAGS) -o subsql subsql.o $(FASTDB_LIBS) $(STDLIBS) $(SOCKLIBS)
225
226bugdb.o: examples/bugdb.cpp examples/bugdb.h $(INCS)
227	$(CC) $(CFLAGS) examples/bugdb.cpp
228
229bugdb: bugdb.o  $(FASTDB_LIB)
230	$(LD) $(LDFLAGS) -o bugdb bugdb.o $(FASTDB_LIBS) $(STDLIBS) $(SOCKLIBS)
231
232clidb.o: examples/clidb.cpp examples/clidb.h $(INCS)
233	$(CC) $(CFLAGS) examples/clidb.cpp
234
235clidb: clidb.o  $(FASTDB_LIB)
236	$(LD) $(LDFLAGS) -o clidb clidb.o $(FASTDB_LIBS) $(STDLIBS) $(SOCKLIBS)
237
238cgistub.o: src/cgistub.cpp inc/stdtp.h inc/sockio.h
239	$(CC) $(CFLAGS) src/cgistub.cpp
240
241cgistub: cgistub.o
242	$(LD) $(LDFLAGS) -o cgistub cgistub.o $(FASTDB_LIBS) $(STDLIBS) $(SOCKLIBS)
243
244
245forcerecovery.o: src/forcerecovery.cpp inc/database.h
246	$(CC) $(CFLAGS) src/forcerecovery.cpp
247
248forcerecovery: forcerecovery.o
249	$(LD) $(LDFLAGS)  -o forcerecovery forcerecovery.o
250
251cleanupsem.o: src/cleanupsem.cpp inc/database.h
252	$(CC) $(CFLAGS) src/cleanupsem.cpp
253
254cleanupsem: cleanupsem.o
255	$(LD) $(LDFLAGS)  -o cleanupsem cleanupsem.o
256
257inspectsem.o: src/inspectsem.cpp inc/database.h
258	$(CC) $(CFLAGS) src/inspectsem.cpp
259
260inspectsem: inspectsem.o
261	$(LD) $(LDFLAGS)  -o inspectsem inspectsem.o
262
263
264guess.o: examples/guess.cpp $(INCS)
265	$(CC) $(CFLAGS) examples/guess.cpp
266
267guess: guess.o $(FASTDB_LIB)
268	$(LD) $(LDFLAGS) -o guess guess.o $(FASTDB_LIBS) $(STDLIBS)
269
270testharr.o: examples/testharr.cpp $(INCS)
271	$(CC) $(CFLAGS) examples/testharr.cpp
272
273testharr: testharr.o $(FASTDB_LIB)
274	$(LD) $(LDFLAGS) -o testharr testharr.o $(FASTDB_LIBS) $(STDLIBS)
275
276testdb.o: examples/testdb.cpp $(INCS)
277	$(CC) $(CFLAGS) examples/testdb.cpp
278
279testdb: testdb.o $(FASTDB_LIB)
280	$(LD) $(LDFLAGS) -o testdb testdb.o $(FASTDB_LIBS) $(STDLIBS)
281
282testraw.o: examples/testraw.cpp $(INCS)
283	$(CC) $(CFLAGS) examples/testraw.cpp
284
285testraw: testraw.o $(FASTDB_LIB)
286	$(LD) $(LDFLAGS) -o testraw testraw.o $(FASTDB_LIBS) $(STDLIBS)
287
288testleak.o: examples/testleak.cpp $(INCS)
289	$(CC) $(CFLAGS) examples/testleak.cpp
290
291testleak: testleak.o $(FASTDB_LIB)
292	$(LD) $(LDFLAGS) -o testleak testleak.o $(FASTDB_LIBS) $(STDLIBS)
293
294testfrag.o: examples/testfrag.cpp $(INCS)
295	$(CC) $(CFLAGS) examples/testfrag.cpp
296
297testfrag: testfrag.o $(FASTDB_LIB)
298	$(LD) $(LDFLAGS) -o testfrag testfrag.o $(FASTDB_LIBS) $(STDLIBS)
299
300testjoin.o: examples/testjoin.cpp $(INCS)
301	$(CC) $(CFLAGS) examples/testjoin.cpp
302
303testjoin: testjoin.o $(FASTDB_LIB)
304	$(LD) $(LDFLAGS) -o testjoin testjoin.o $(FASTDB_LIBS) $(STDLIBS)
305
306testddl.o: examples/testddl.cpp $(INCS)
307	$(CC) $(CFLAGS) examples/testddl.cpp
308
309testddl: testddl.o $(FASTDB_LIB)
310	$(LD) $(LDFLAGS) -o testddl testddl.o $(FASTDB_LIBS) $(STDLIBS)
311
312testperf.o: examples/testperf.cpp $(INCS)
313	$(CC) $(CFLAGS) examples/testperf.cpp
314
315testperf: testperf.o $(FASTDB_LIB)
316	$(LD) $(LDFLAGS) -o testperf testperf.o $(FASTDB_LIBS) $(STDLIBS)
317
318testwcs.o: examples/testwcs.cpp $(INCS)
319	$(CC) $(CFLAGS) examples/testwcs.cpp
320
321testwcs: testwcs.o $(FASTDB_LIB)
322	$(LD) $(LDFLAGS) -o testwcs testwcs.o $(FASTDB_LIBS) $(STDLIBS)
323
324testpar.o: examples/testpar.cpp $(INCS)
325	$(CC) $(CFLAGS) examples/testpar.cpp
326
327testpar: testpar.o $(FASTDB_LIB)
328	$(LD) $(LDFLAGS) -o testpar testpar.o $(FASTDB_LIBS) $(STDLIBS)
329
330testindex.o: examples/testindex.cpp $(INCS)
331	$(CC) $(CFLAGS) examples/testindex.cpp
332
333testindex: testindex.o $(FASTDB_LIB)
334	$(LD) $(LDFLAGS) -o testindex testindex.o $(FASTDB_LIBS) $(STDLIBS)
335
336testarridx.o: examples/testarridx.cpp $(INCS)
337	$(CC) $(CFLAGS) examples/testarridx.cpp
338
339testarridx: testarridx.o $(FASTDB_LIB)
340	$(LD) $(LDFLAGS) -o testarridx testarridx.o $(FASTDB_LIBS) $(STDLIBS)
341
342testudt.o: examples/testudt.cpp $(INCS)
343	$(CC) $(CFLAGS) examples/testudt.cpp
344
345testudt: testudt.o $(FASTDB_LIB)
346	$(LD) $(LDFLAGS) -o testudt testudt.o $(FASTDB_LIBS) $(STDLIBS)
347
348testspat.o: examples/testspat.cpp $(INCS)
349	$(CC) $(CFLAGS) examples/testspat.cpp
350
351testspat: testspat.o $(FASTDB_LIB)
352	$(LD) $(LDFLAGS) -o testspat testspat.o $(FASTDB_LIBS) $(STDLIBS)
353
354testtimeseries.o: examples/testtimeseries.cpp $(INCS)
355	$(CC) $(CFLAGS) examples/testtimeseries.cpp
356
357testtimeseries: testtimeseries.o $(FASTDB_LIB)
358	$(LD) $(LDFLAGS) -o testtimeseries testtimeseries.o $(FASTDB_LIBS) $(STDLIBS)
359
360testfuzzy.o: examples/testfuzzy.cpp $(INCS)
361	$(CC) $(CFLAGS) examples/testfuzzy.cpp
362
363testfuzzy: testfuzzy.o $(FASTDB_LIB)
364	$(LD) $(LDFLAGS) -o testfuzzy testfuzzy.o $(FASTDB_LIBS) $(STDLIBS)
365
366testidx.o: examples/testidx.cpp $(INCS)
367	$(CC) $(CFLAGS) examples/testidx.cpp
368
369testidx: testidx.o $(FASTDB_LIB)
370	$(LD) $(LDFLAGS) -o testidx testidx.o $(FASTDB_LIBS) $(STDLIBS)
371
372testtl.o: examples/testtl.cpp $(INCS)
373	$(CC) $(CFLAGS) examples/testtl.cpp
374
375testtl: testtl.o $(FASTDB_LIB)
376	$(LD) $(LDFLAGS) -o testtl testtl.o $(FASTDB_LIBS) $(STDLIBS)
377
378testsync.o: examples/testsync.cpp $(INCS)
379	$(CC) $(CFLAGS) examples/testsync.cpp
380
381testsync: testsync.o $(FASTDB_LIB)
382	$(LD) $(LDFLAGS) -o testsync testsync.o $(FASTDB_LIBS) $(STDLIBS)
383
384testconc.o: examples/testconc.cpp $(INCS)
385	$(CC) $(CFLAGS) examples/testconc.cpp
386
387testconc: testconc.o $(FASTDB_LIB)
388	$(LD) $(LDFLAGS) -o testconc testconc.o $(FASTDB_LIBS) $(STDLIBS)
389
390testreplic.o: examples/testreplic.cpp $(INCS)
391	$(CC) $(CFLAGS) examples/testreplic.cpp
392
393testreplic: testreplic.o $(FASTDB_LIB)
394	$(LD) $(LDFLAGS) -o testreplic testreplic.o $(FASTDB_LIBS) $(STDLIBS)
395
396testiref.o: examples/testiref.cpp $(INCS)
397	$(CC) $(CFLAGS) examples/testiref.cpp
398
399testiref: testiref.o $(FASTDB_LIB)
400	$(LD) $(LDFLAGS) -o testiref testiref.o $(FASTDB_LIBS) $(STDLIBS)
401
402testtrav.o: examples/testtrav.cpp $(INCS)
403	$(CC) $(CFLAGS) examples/testtrav.cpp
404
405testtrav: testtrav.o $(FASTDB_LIB)
406	$(LD) $(LDFLAGS) -o testtrav testtrav.o $(FASTDB_LIBS) $(STDLIBS)
407
408
409java: javacli.jar jnicli.jar $(JNI_LIB) examples/JniTestIndex.class examples/JniTestRelations.class examples/TestIndex.class examples/CliTest.class
410
411jnicli.o: jnicli/jnicli.cpp
412	$(CC) $(CFLAGS) -I$(JAVA_HOME)/include -I$(JAVA_HOME)/include/linux -I. jnicli/jnicli.cpp
413
414$(JNI_LIB): jnicli.o $(GB_LIB)
415	$(CC) $(SHFLAGS) -o $(JNI_LIB) jnicli.o $(FASTDB_LIB)
416	ln -f -s $(JNI_LIB) libjnicli.so
417
418javacli.jar: javacli/*.java
419	javac -g javacli/*.java
420	jar cvf javacli.jar javacli/*.class
421	javadoc -d javacli/docs -public javacli/*.java
422
423jnicli.jar: jnicli/*.java
424	javac -g jnicli/*.java
425	jar cvf jnicli.jar jnicli/*.class
426	javadoc -d jnicli/docs -public jnicli/*.java
427
428examples/JniTestIndex.class: examples/JniTestIndex.java jnicli.jar
429	javac -classpath jnicli.jar examples/JniTestIndex.java
430
431examples/JniTestRelations.class: examples/JniTestRelations.java jnicli.jar
432	javac -classpath jnicli.jar examples/JniTestRelations.java
433
434examples/CliTest.class: examples/CliTest.java javacli.jar
435	javac -classpath .;javacli.jar examples/CliTest.java
436
437examples/TestIndex.class: examples/TestIndex.java javacli.jar
438	javac -classpath .;javacli.jar examples/TestIndex.java
439
440install: subsql cleanupsem inspectsem installlib
441	mkdir -p $(BINSPATH)
442	${BSD_INSTALL_PROGRAM} subsql $(BINSPATH)
443	${BSD_INSTALL_PROGRAM} cleanupsem $(BINSPATH)
444	${BSD_INSTALL_PROGRAM} inspectsem $(BINSPATH)
445
446installlib: $(FASTDB_LIB) $(CLI_LIB) $(FASTDB_SHARED) $(CLI_SHARED)
447	mkdir -p $(INCSPATH)
448	${BSD_INSTALL_DATA} $(INCS) $(INCSPATH)
449	mkdir -p $(LIBSPATH)
450	${BSD_INSTALL_LIB} $(FASTDB_LIB) $(CLI_LIB) $(FASTDB_SHARED) $(CLI_SHARED) $(LIBSPATH)
451	(cd $(LIBSPATH) && ln -f -s $(FASTDB_SHARED) libfastdb$(SUFF).so \
452	 && ln -f -s $(CLI_SHARED) libcli$(SUFF).so)
453	if [ -f $(JNI_LIB) ]; then cp $(JNI_LIB) $(LIBSPATH); \
454	  cd $(LIBSPATH) && ln -f -s $(JNI_LIB) libjnicli.so; fi
455
456uninstall:
457	rm -fr $(INCSPATH)
458	cd $(LIBSPATH); rm -f $(FASTDB_LIB) $(CLI_LIB) $(FASTDB_SHARED) $(CLI_SHARED) libfastdb$(SUFF).so libcli$(SUFF).so
459	rm $(BINSPATH)/subsql
460
461cleanobj:
462	rm -fr *.o *.tgz examples/*.class javacli/*~ javacli/*.class jnicli/*~ jnicli/*.class jnicli/*.o jnicli/*.so core *~ cxx_repository
463
464cleandbs:
465	rm -f *.fdb *.log
466
467
468clean: cleanobj cleandbs
469	rm -f *.a *.so *.so.* $(EXAMPLES) $(WEB_EXAMPLES) $(EXES)
470
471tgz:	clean
472	chmod +x configure genauto.sh
473	cd ..; tar cvzf fastdb.tgz fastdb
474
475copytgz: tgz
476	mcopy -o ../fastdb.tgz a:
477