xref: /illumos-gate/usr/src/lib/libsqlite/main.mk (revision 598f4ceed9327d2d6c2325dd67cae3aa06f7fea6)
1#ident	"%Z%%M%	%I%	%E% SMI"
2#
3###############################################################################
4# The following macros should be defined before this script is
5# invoked:
6#
7# TOP              The toplevel directory of the source tree.  This is the
8#                  directory that contains this "Makefile.in" and the
9#                  "configure.in" script.
10#
11# BCC              C Compiler and options for use in building executables that
12#                  will run on the platform that is doing the build.
13#
14# USLEEP           If the target operating system supports the "usleep()" system
15#                  call, then define the HAVE_USLEEP macro for all C modules.
16#
17# THREADSAFE       If you want the SQLite library to be safe for use within a
18#                  multi-threaded program, then define the following macro
19#                  appropriately:
20#
21# THREADLIB        Specify any extra linker options needed to make the library
22#                  thread safe
23#
24# OPTS             Extra compiler command-line options.
25#
26# EXE              The suffix to add to executable files.  ".exe" for windows
27#                  and "" for Unix.
28#
29# TCC              C Compiler and options for use in building executables that
30#                  will run on the target platform.  This is usually the same
31#                  as BCC, unless you are cross-compiling.
32#
33# AR               Tools used to build a static library.
34# RANLIB
35#
36# TCL_FLAGS        Extra compiler options needed for programs that use the
37#                  TCL library.
38#
39# LIBTCL           Linker options needed to link against the TCL library.
40#
41# READLINE_FLAGS   Compiler options needed for programs that use the
42#                  readline() library.
43#
44# LIBREADLINE      Linker options needed by programs using readline() must
45#                  link against.
46#
47# ENCODING         "UTF8" or "ISO8859"
48#
49# Once the macros above are defined, the rest of this make script will
50# build the SQLite library and testing tools.
51################################################################################
52
53# This is how we compile
54#
55TCCX = $(TCC) $(OPTS) $(THREADSAFE) $(USLEEP) -I. -I$(TOP)/src
56
57# Object files for the SQLite library.
58#
59LIBOBJ = attach.o auth.o btree.o btree_rb.o build.o copy.o date.o delete.o \
60         expr.o func.o hash.o insert.o \
61         main.o opcodes.o os.o pager.o parse.o pragma.o printf.o random.o \
62         select.o table.o tokenize.o trigger.o update.o util.o \
63         vacuum.o vdbe.o vdbeaux.o where.o tclsqlite.o
64
65# All of the source code files.
66#
67SRC = \
68  $(TOP)/src/attach.c \
69  $(TOP)/src/auth.c \
70  $(TOP)/src/btree.c \
71  $(TOP)/src/btree.h \
72  $(TOP)/src/btree_rb.c \
73  $(TOP)/src/build.c \
74  $(TOP)/src/copy.c \
75  $(TOP)/src/date.c \
76  $(TOP)/src/delete.c \
77  $(TOP)/src/encode.c \
78  $(TOP)/src/expr.c \
79  $(TOP)/src/func.c \
80  $(TOP)/src/hash.c \
81  $(TOP)/src/hash.h \
82  $(TOP)/src/insert.c \
83  $(TOP)/src/main.c \
84  $(TOP)/src/os.c \
85  $(TOP)/src/pager.c \
86  $(TOP)/src/pager.h \
87  $(TOP)/src/parse.y \
88  $(TOP)/src/pragma.c \
89  $(TOP)/src/printf.c \
90  $(TOP)/src/random.c \
91  $(TOP)/src/select.c \
92  $(TOP)/src/shell.c \
93  $(TOP)/src/sqlite.h.in \
94  $(TOP)/src/sqliteInt.h \
95  $(TOP)/src/table.c \
96  $(TOP)/src/tclsqlite.c \
97  $(TOP)/src/tokenize.c \
98  $(TOP)/src/trigger.c \
99  $(TOP)/src/update.c \
100  $(TOP)/src/util.c \
101  $(TOP)/src/vacuum.c \
102  $(TOP)/src/vdbe.c \
103  $(TOP)/src/vdbe.h \
104  $(TOP)/src/vdbeaux.c \
105  $(TOP)/src/vdbeInt.h \
106  $(TOP)/src/where.c
107
108# Source code to the test files.
109#
110TESTSRC = \
111  $(TOP)/src/btree.c \
112  $(TOP)/src/func.c \
113  $(TOP)/src/os.c \
114  $(TOP)/src/pager.c \
115  $(TOP)/src/test1.c \
116  $(TOP)/src/test2.c \
117  $(TOP)/src/test3.c \
118  $(TOP)/src/test4.c \
119  $(TOP)/src/vdbe.c \
120  $(TOP)/src/md5.c
121
122# Header files used by all library source files.
123#
124HDR = \
125   sqlite.h  \
126   $(TOP)/src/btree.h \
127   config.h \
128   $(TOP)/src/hash.h \
129   opcodes.h \
130   $(TOP)/src/os.h \
131   $(TOP)/src/sqliteInt.h  \
132   $(TOP)/src/vdbe.h \
133   parse.h
134
135# Header files used by the VDBE submodule
136#
137VDBEHDR = \
138   $(HDR) \
139   $(TOP)/src/vdbeInt.h
140
141# This is the default Makefile target.  The objects listed here
142# are what get build when you type just "make" with no arguments.
143#
144all:	sqlite.h config.h libsqlite.a sqlite$(EXE)
145
146# Generate the file "last_change" which contains the date of change
147# of the most recently modified source code file
148#
149last_change:	$(SRC)
150	cat $(SRC) | grep '$$Id: ' | sort +4 | tail -1 \
151          | awk '{print $$5,$$6}' >last_change
152
153libsqlite.a:	$(LIBOBJ)
154	$(AR) libsqlite.a $(LIBOBJ)
155	$(RANLIB) libsqlite.a
156
157sqlite$(EXE):	$(TOP)/src/shell.c libsqlite.a sqlite.h
158	$(TCCX) $(READLINE_FLAGS) -o sqlite$(EXE) $(TOP)/src/shell.c \
159		libsqlite.a $(LIBREADLINE) $(THREADLIB)
160
161sqlite_analyzer$(EXE):	$(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC) \
162			$(TOP)/tool/spaceanal.tcl
163	sed \
164	  -e '/^#/d' \
165	  -e 's,\\,\\\\,g' \
166	  -e 's,",\\",g' \
167	  -e 's,^,",' \
168	  -e 's,$$,\\n",' \
169	  $(TOP)/tool/spaceanal.tcl >spaceanal_tcl.h
170	$(TCCX) $(TCL_FLAGS) -DTCLSH=2 -DSQLITE_TEST=1 -static -o \
171 		sqlite_analyzer$(EXE) $(TESTSRC) $(TOP)/src/tclsqlite.c \
172		libsqlite.a $(LIBTCL)
173
174
175# This target creates a directory named "tsrc" and fills it with
176# copies of all of the C source code and header files needed to
177# build on the target system.  Some of the C source code and header
178# files are automatically generated.  This target takes care of
179# all that automatic generation.
180#
181target_source:	$(SRC) $(VDBEHDR) opcodes.c
182	rm -rf tsrc
183	mkdir tsrc
184	cp $(SRC) $(VDBEHDR) tsrc
185	rm tsrc/sqlite.h.in tsrc/parse.y
186	cp parse.c opcodes.c tsrc
187
188# Rules to build the LEMON compiler generator
189#
190lemon:	$(TOP)/tool/lemon.c $(TOP)/tool/lempar.c
191	$(BCC) -o lemon $(TOP)/tool/lemon.c
192	cp $(TOP)/tool/lempar.c .
193
194btree.o:	$(TOP)/src/btree.c $(HDR) $(TOP)/src/pager.h
195	$(TCCX) -c $(TOP)/src/btree.c
196
197btree_rb.o:	$(TOP)/src/btree_rb.c $(HDR)
198	$(TCCX) -c $(TOP)/src/btree_rb.c
199
200build.o:	$(TOP)/src/build.c $(HDR)
201	$(TCCX) -c $(TOP)/src/build.c
202
203main.o:	$(TOP)/src/main.c $(HDR)
204	$(TCCX) -c $(TOP)/src/main.c
205
206pager.o:	$(TOP)/src/pager.c $(HDR) $(TOP)/src/pager.h
207	$(TCCX) -c $(TOP)/src/pager.c
208
209opcodes.o:	opcodes.c
210	$(TCCX) -c opcodes.c
211
212opcodes.c:	$(TOP)/src/vdbe.c
213	echo '/* Automatically generated file.  Do not edit */' >opcodes.c
214	echo 'char *sqliteOpcodeNames[] = { "???", ' >>opcodes.c
215	grep '^case OP_' $(TOP)/src/vdbe.c | \
216	  sed -e 's/^.*OP_/  "/' -e 's/:.*$$/", /' >>opcodes.c
217	echo '};' >>opcodes.c
218
219opcodes.h:	$(TOP)/src/vdbe.h
220	echo '/* Automatically generated file.  Do not edit */' >opcodes.h
221	grep '^case OP_' $(TOP)/src/vdbe.c | \
222	  sed -e 's/://' | \
223	  awk '{printf "#define %-30s %3d\n", $$2, ++cnt}' >>opcodes.h
224
225os.o:	$(TOP)/src/os.c $(HDR)
226	$(TCCX) -c $(TOP)/src/os.c
227
228parse.o:	parse.c $(HDR)
229	$(TCCX) -c parse.c
230
231parse.h:	parse.c
232
233parse.c:	$(TOP)/src/parse.y lemon
234	cp $(TOP)/src/parse.y .
235	./lemon parse.y
236
237# The config.h file will contain a single #define that tells us how
238# many bytes are in a pointer.  This only works if a pointer is the
239# same size on the host as it is on the target.  If you are cross-compiling
240# to a target with a different pointer size, you'll need to manually
241# configure the config.h file.
242#
243config.h:
244	echo '#include <stdio.h>' >temp.c
245	echo 'int main(){printf(' >>temp.c
246	echo '"#define SQLITE_PTR_SZ %d",sizeof(char*));' >>temp.c
247	echo 'exit(0);}' >>temp.c
248	$(BCC) -o temp temp.c
249	./temp >config.h
250	echo >>config.h
251	rm -f temp.c temp
252
253sqlite.h:	$(TOP)/src/sqlite.h.in
254	sed -e s/--VERS--/`cat ${TOP}/VERSION`/ \
255            -e s/--ENCODING--/$(ENCODING)/ \
256                 $(TOP)/src/sqlite.h.in >sqlite.h
257
258tokenize.o:	$(TOP)/src/tokenize.c $(HDR)
259	$(TCCX) -c $(TOP)/src/tokenize.c
260
261trigger.o:	$(TOP)/src/trigger.c $(HDR)
262	$(TCCX) -c $(TOP)/src/trigger.c
263
264util.o:	$(TOP)/src/util.c $(HDR)
265	$(TCCX) -c $(TOP)/src/util.c
266
267vacuum.o:	$(TOP)/src/vacuum.c $(HDR)
268	$(TCCX) -c $(TOP)/src/vacuum.c
269
270vdbe.o:	$(TOP)/src/vdbe.c $(VDBEHDR)
271	$(TCCX) -c $(TOP)/src/vdbe.c
272
273vdbeaux.o:	$(TOP)/src/vdbeaux.c $(VDBEHDR)
274	$(TCCX) -c $(TOP)/src/vdbeaux.c
275
276where.o:	$(TOP)/src/where.c $(HDR)
277	$(TCCX) -c $(TOP)/src/where.c
278
279copy.o:	$(TOP)/src/copy.c $(HDR)
280	$(TCCX) -c $(TOP)/src/copy.c
281
282date.o:	$(TOP)/src/date.c $(HDR)
283	$(TCCX) -c $(TOP)/src/date.c
284
285delete.o:	$(TOP)/src/delete.c $(HDR)
286	$(TCCX) -c $(TOP)/src/delete.c
287
288encode.o:	$(TOP)/src/encode.c
289	$(TCCX) -c $(TOP)/src/encode.c
290
291expr.o:	$(TOP)/src/expr.c $(HDR)
292	$(TCCX) -c $(TOP)/src/expr.c
293
294func.o:	$(TOP)/src/func.c $(HDR)
295	$(TCCX) -c $(TOP)/src/func.c
296
297hash.o:	$(TOP)/src/hash.c $(HDR)
298	$(TCCX) -c $(TOP)/src/hash.c
299
300insert.o:	$(TOP)/src/insert.c $(HDR)
301	$(TCCX) -c $(TOP)/src/insert.c
302
303random.o:	$(TOP)/src/random.c $(HDR)
304	$(TCCX) -c $(TOP)/src/random.c
305
306select.o:	$(TOP)/src/select.c $(HDR)
307	$(TCCX) -c $(TOP)/src/select.c
308
309table.o:	$(TOP)/src/table.c $(HDR)
310	$(TCCX) -c $(TOP)/src/table.c
311
312update.o:	$(TOP)/src/update.c $(HDR)
313	$(TCCX) -c $(TOP)/src/update.c
314
315tclsqlite.o:	$(TOP)/src/tclsqlite.c $(HDR)
316	$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/tclsqlite.c
317
318pragma.o:	$(TOP)/src/pragma.c $(HDR)
319	$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/pragma.c
320
321printf.o:	$(TOP)/src/printf.c $(HDR)
322	$(TCCX) $(TCL_FLAGS) -c $(TOP)/src/printf.c
323
324attach.o:	$(TOP)/src/attach.c $(HDR)
325	$(TCCX) -c $(TOP)/src/attach.c
326
327auth.o:	$(TOP)/src/auth.c $(HDR)
328	$(TCCX) -c $(TOP)/src/auth.c
329
330tclsqlite:	$(TOP)/src/tclsqlite.c libsqlite.a
331	$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -o tclsqlite \
332		$(TOP)/src/tclsqlite.c libsqlite.a $(LIBTCL)
333
334testfixture$(EXE):	$(TOP)/src/tclsqlite.c libsqlite.a $(TESTSRC)
335	$(TCCX) $(TCL_FLAGS) -DTCLSH=1 -DSQLITE_TEST=1 -o testfixture$(EXE) \
336		$(TESTSRC) $(TOP)/src/tclsqlite.c \
337		libsqlite.a $(LIBTCL) $(THREADLIB)
338
339fulltest:	testfixture$(EXE) sqlite$(EXE)
340	./testfixture$(EXE) $(TOP)/test/all.test
341
342test:	testfixture$(EXE) sqlite$(EXE)
343	./testfixture$(EXE) $(TOP)/test/quick.test
344
345index.html:	$(TOP)/www/index.tcl last_change
346	tclsh $(TOP)/www/index.tcl `cat $(TOP)/VERSION` >index.html
347
348sqlite.html:	$(TOP)/www/sqlite.tcl
349	tclsh $(TOP)/www/sqlite.tcl >sqlite.html
350
351c_interface.html:	$(TOP)/www/c_interface.tcl
352	tclsh $(TOP)/www/c_interface.tcl >c_interface.html
353
354changes.html:	$(TOP)/www/changes.tcl
355	tclsh $(TOP)/www/changes.tcl >changes.html
356
357lang.html:	$(TOP)/www/lang.tcl
358	tclsh $(TOP)/www/lang.tcl >lang.html
359
360vdbe.html:	$(TOP)/www/vdbe.tcl
361	tclsh $(TOP)/www/vdbe.tcl >vdbe.html
362
363arch.html:	$(TOP)/www/arch.tcl
364	tclsh $(TOP)/www/arch.tcl >arch.html
365
366arch.png:	$(TOP)/www/arch.png
367	cp $(TOP)/www/arch.png .
368
369opcode.html:	$(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c
370	tclsh $(TOP)/www/opcode.tcl $(TOP)/src/vdbe.c >opcode.html
371
372mingw.html:	$(TOP)/www/mingw.tcl
373	tclsh $(TOP)/www/mingw.tcl >mingw.html
374
375tclsqlite.html:	$(TOP)/www/tclsqlite.tcl
376	tclsh $(TOP)/www/tclsqlite.tcl >tclsqlite.html
377
378speed.html:	$(TOP)/www/speed.tcl
379	tclsh $(TOP)/www/speed.tcl >speed.html
380
381faq.html:	$(TOP)/www/faq.tcl
382	tclsh $(TOP)/www/faq.tcl >faq.html
383
384formatchng.html:	$(TOP)/www/formatchng.tcl
385	tclsh $(TOP)/www/formatchng.tcl >formatchng.html
386
387conflict.html:	$(TOP)/www/conflict.tcl
388	tclsh $(TOP)/www/conflict.tcl >conflict.html
389
390download.html:	$(TOP)/www/download.tcl
391	tclsh $(TOP)/www/download.tcl >download.html
392
393omitted.html:	$(TOP)/www/omitted.tcl
394	tclsh $(TOP)/www/omitted.tcl >omitted.html
395
396datatypes.html:	$(TOP)/www/datatypes.tcl
397	tclsh $(TOP)/www/datatypes.tcl >datatypes.html
398
399quickstart.html:	$(TOP)/www/quickstart.tcl
400	tclsh $(TOP)/www/quickstart.tcl >quickstart.html
401
402fileformat.html:	$(TOP)/www/fileformat.tcl
403	tclsh $(TOP)/www/fileformat.tcl >fileformat.html
404
405nulls.html:	$(TOP)/www/nulls.tcl
406	tclsh $(TOP)/www/nulls.tcl >nulls.html
407
408
409# Files to be published on the website.
410#
411DOC = \
412  index.html \
413  sqlite.html \
414  changes.html \
415  lang.html \
416  opcode.html \
417  arch.html \
418  arch.png \
419  vdbe.html \
420  c_interface.html \
421  mingw.html \
422  tclsqlite.html \
423  download.html \
424  speed.html \
425  faq.html \
426  formatchng.html \
427  conflict.html \
428  omitted.html \
429  datatypes.html \
430  quickstart.html \
431  fileformat.html \
432  nulls.html
433
434doc:	$(DOC)
435	mkdir -p doc
436	mv $(DOC) doc
437
438install:	sqlite libsqlite.a sqlite.h
439	mv sqlite /usr/bin
440	mv libsqlite.a /usr/lib
441	mv sqlite.h /usr/include
442
443clean:
444	rm -f *.o sqlite libsqlite.a sqlite.h opcodes.*
445	rm -f lemon lempar.c parse.* sqlite*.tar.gz
446	rm -f $(PUBLISH)
447	rm -f *.da *.bb *.bbg gmon.out
448	rm -rf tsrc
449