xref: /freebsd/contrib/sqlite3/tea/win/makefile.vc (revision 3c4ba5f55438f7afd4f4b0b56f88f2bb505fd6a6)
1# makefile.vc --                                               -*- Makefile -*-
2#
3# Microsoft Visual C++ makefile for use with nmake.exe v1.62+ (VC++ 5.0+)
4#
5# This makefile is based upon the Tcl 8.4 Makefile.vc and modified to
6# make it suitable as a general package makefile. Look for the word EDIT
7# which marks sections that may need modification. As a minumum you will
8# need to change the PROJECT, DOTVERSION and DLLOBJS variables to values
9# relevant to your package.
10#
11# See the file "license.terms" for information on usage and redistribution
12# of this file, and for a DISCLAIMER OF ALL WARRANTIES.
13#
14# Copyright (c) 1995-1996 Sun Microsystems, Inc.
15# Copyright (c) 1998-2000 Ajuba Solutions.
16# Copyright (c) 2001 ActiveState Corporation.
17# Copyright (c) 2001-2002 David Gravereaux.
18# Copyright (c) 2003 Pat Thoyts
19#
20#-------------------------------------------------------------------------
21# RCS: @(#)$Id: makefile.vc,v 1.4 2004/07/26 08:22:05 patthoyts Exp $
22#-------------------------------------------------------------------------
23
24!if !defined(MSDEVDIR) && !defined(MSVCDIR) && !defined(VCINSTALLDIR) && !defined(MSSDK) && !defined(WINDOWSSDKDIR)
25MSG = ^
26You will need to run vcvars32.bat from Developer Studio, first, to setup^
27the environment.  Jump to this line to read the new instructions.
28!error $(MSG)
29!endif
30
31#------------------------------------------------------------------------------
32# HOW TO USE this makefile:
33#
34# 1)  It is now necessary to have %MSVCDir% set in the environment.  This is
35#     used  as a check to see if vcvars32.bat had been run prior to running
36#     nmake or during the installation of Microsoft Visual C++, MSVCDir had
37#     been set globally and the PATH adjusted.  Either way is valid.
38#
39#     You'll need to run vcvars32.bat contained in the MsDev's vc(98)/bin
40#     directory to setup the proper environment, if needed, for your current
41#     setup.  This is a needed bootstrap requirement and allows the swapping of
42#     different environments to be easier.
43#
44# 2)  To use the Platform SDK (not expressly needed), run setenv.bat after
45#     vcvars32.bat according to the instructions for it.  This can also turn on
46#     the 64-bit compiler, if your SDK has it.
47#
48# 3)  Targets are:
49#	all       -- Builds everything.
50#       <project> -- Builds the project (eg: nmake sample)
51#	test      -- Builds and runs the test suite.
52#	install   -- Installs the built binaries and libraries to $(INSTALLDIR)
53#		     in an appropriate subdirectory.
54#	clean/realclean/distclean -- varying levels of cleaning.
55#
56# 4)  Macros usable on the commandline:
57#	INSTALLDIR=<path>
58#		Sets where to install Tcl from the built binaries.
59#		C:\Progra~1\Tcl is assumed when not specified.
60#
61#	OPTS=static,msvcrt,staticpkg,threads,symbols,profile,loimpact,none
62#		Sets special options for the core.  The default is for none.
63#		Any combination of the above may be used (comma separated).
64#		'none' will over-ride everything to nothing.
65#
66#		static  =  Builds a static library of the core instead of a
67#			   dll.  The shell will be static (and large), as well.
68#		msvcrt  =  Effects the static option only to switch it from
69#			   using libcmt(d) as the C runtime [by default] to
70#			   msvcrt(d). This is useful for static embedding
71#			   support.
72#		staticpkg = Effects the static option only to switch
73#			   tclshXX.exe to have the dde and reg extension linked
74#			   inside it.
75#		threads =  Turns on full multithreading support.
76#		thrdalloc = Use the thread allocator (shared global free pool).
77#		symbols =  Adds symbols for step debugging.
78#		profile =  Adds profiling hooks.  Map file is assumed.
79#		loimpact =  Adds a flag for how NT treats the heap to keep memory
80#			   in use, low.  This is said to impact alloc performance.
81#
82#	STATS=memdbg,compdbg,none
83#		Sets optional memory and bytecode compiler debugging code added
84#		to the core.  The default is for none.  Any combination of the
85#		above may be used (comma separated).  'none' will over-ride
86#		everything to nothing.
87#
88#		memdbg   = Enables the debugging memory allocator.
89#		compdbg  = Enables byte compilation logging.
90#
91#	MACHINE=(IX86|IA64|ALPHA)
92#		Set the machine type used for the compiler, linker, and
93#		resource compiler.  This hook is needed to tell the tools
94#		when alternate platforms are requested.  IX86 is the default
95#		when not specified.
96#
97#	TMP_DIR=<path>
98#	OUT_DIR=<path>
99#		Hooks to allow the intermediate and output directories to be
100#		changed.  $(OUT_DIR) is assumed to be
101#		$(BINROOT)\(Release|Debug) based on if symbols are requested.
102#		$(TMP_DIR) will de $(OUT_DIR)\<buildtype> by default.
103#
104#	TESTPAT=<file>
105#		Reads the tests requested to be run from this file.
106#
107#	CFG_ENCODING=encoding
108#		name of encoding for configuration information. Defaults
109#		to cp1252
110#
111# 5)  Examples:
112#
113#	Basic syntax of calling nmake looks like this:
114#	nmake [-nologo] -f makefile.vc [target|macrodef [target|macrodef] [...]]
115#
116#                        Standard (no frills)
117#       c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
118#       Setting environment for using Microsoft Visual C++ tools.
119#       c:\tcl_src\win\>nmake -f makefile.vc all
120#       c:\tcl_src\win\>nmake -f makefile.vc install INSTALLDIR=c:\progra~1\tcl
121#
122#                         Building for Win64
123#       c:\tcl_src\win\>c:\progra~1\micros~1\vc98\bin\vcvars32.bat
124#       Setting environment for using Microsoft Visual C++ tools.
125#       c:\tcl_src\win\>c:\progra~1\platfo~1\setenv.bat /pre64 /RETAIL
126#       Targeting Windows pre64 RETAIL
127#       c:\tcl_src\win\>nmake -f makefile.vc MACHINE=IA64
128#
129#------------------------------------------------------------------------------
130#==============================================================================
131###############################################################################
132#------------------------------------------------------------------------------
133
134!if !exist("makefile.vc")
135MSG = ^
136You must run this makefile only from the directory it is in.^
137Please `cd` to its location first.
138!error $(MSG)
139!endif
140
141#-------------------------------------------------------------------------
142# Project specific information (EDIT)
143#
144# You should edit this with the name and version of your project. This
145# information is used to generate the name of the package library and
146# it's install location.
147#
148# For example, the sample extension is  going to build sample04.dll and
149# would install it into $(INSTALLDIR)\lib\sample04
150#
151# You need to specify the object files that need to be linked into your
152# binary here.
153#
154#-------------------------------------------------------------------------
155
156PROJECT = sqlite3
157!include "rules.vc"
158
159# nmakehelp -V <file> <tag> will search the file for tag, skips until a
160#	number and returns all character until a character not in [0-9.ab]
161#	is read.
162
163!if [echo REM = This file is generated from Makefile.vc > versions.vc]
164!endif
165# get project version from row "AC_INIT([sqlite], [3.x.y])"
166!if [echo DOTVERSION = \>> versions.vc] \
167   && [nmakehlp -V ..\configure.ac AC_INIT >> versions.vc]
168!endif
169!include "versions.vc"
170
171VERSION         = $(DOTVERSION:.=)
172STUBPREFIX      = $(PROJECT)stub
173
174#-------------------------------------------------------------------------
175# Target names and paths ( shouldn't need changing )
176#-------------------------------------------------------------------------
177
178BINROOT		= .
179ROOT            = ..
180
181PRJIMPLIB	= $(OUT_DIR)\$(PROJECT)$(VERSION)$(SUFX).lib
182PRJLIBNAME	= $(PROJECT).$(EXT)
183PRJLIB		= $(OUT_DIR)\$(PRJLIBNAME)
184
185PRJSTUBLIBNAME	= $(STUBPREFIX)$(VERSION).lib
186PRJSTUBLIB	= $(OUT_DIR)\$(PRJSTUBLIBNAME)
187
188### Make sure we use backslash only.
189PRJ_INSTALL_DIR         = $(_INSTALLDIR)\$(PROJECT)$(DOTVERSION)
190LIB_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
191BIN_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
192DOC_INSTALL_DIR		= $(PRJ_INSTALL_DIR)
193SCRIPT_INSTALL_DIR	= $(PRJ_INSTALL_DIR)
194INCLUDE_INSTALL_DIR	= $(_TCLDIR)\include
195
196### The following paths CANNOT have spaces in them.
197GENERICDIR	= $(ROOT)\generic
198WINDIR		= $(ROOT)\win
199LIBDIR          = $(ROOT)\library
200DOCDIR		= $(ROOT)\doc
201TOOLSDIR	= $(ROOT)\tools
202COMPATDIR	= $(ROOT)\compat
203
204### Figure out where the primary source code file(s) is/are.
205!if exist("$(ROOT)\..\..\sqlite3.c") && exist("$(ROOT)\..\..\src\tclsqlite.c")
206SQL_INCLUDES = -I"$(ROOT)\..\.."
207SQLITE_SRCDIR = $(ROOT)\..\..
208TCLSQLITE_SRCDIR = $(ROOT)\..\..\src
209DLLOBJS = $(TMP_DIR)\sqlite3.obj $(TMP_DIR)\tclsqlite.obj
210!else
211TCLSQLITE_SRCDIR = $(ROOT)\generic
212DLLOBJS = $(TMP_DIR)\tclsqlite3.obj
213!endif
214
215#---------------------------------------------------------------------
216# Compile flags
217#---------------------------------------------------------------------
218
219!if !$(DEBUG)
220!if $(OPTIMIZING)
221### This cranks the optimization level to maximize speed
222cdebug	= -O2 -Op -Gs
223!else
224cdebug	=
225!endif
226!else if "$(MACHINE)" == "IA64"
227### Warnings are too many, can't support warnings into errors.
228cdebug	= -Z7 -Od -GZ
229!else
230cdebug	= -Z7 -WX -Od -GZ
231!endif
232
233### Declarations common to all compiler options
234cflags = -nologo -c -W3 -D_CRT_SECURE_NO_WARNINGS -YX -Fp$(TMP_DIR)^\
235
236!if $(MSVCRT)
237!if $(DEBUG)
238crt = -MDd
239!else
240crt = -MD
241!endif
242!else
243!if $(DEBUG)
244crt = -MTd
245!else
246crt = -MT
247!endif
248!endif
249
250INCLUDES	= $(SQL_INCLUDES) $(TCL_INCLUDES) -I"$(WINDIR)" \
251                  -I"$(GENERICDIR)" -I"$(ROOT)\.."
252BASE_CLFAGS	= $(cflags) $(cdebug) $(crt) $(INCLUDES) \
253                  -DSQLITE_3_SUFFIX_ONLY=1 -DSQLITE_ENABLE_RTREE=1 \
254                  -DSQLITE_ENABLE_FTS3=1 -DSQLITE_OMIT_DEPRECATED=1 \
255                  -DSQLITE_ENABLE_FTS4=1 \
256                  -DSQLITE_ENABLE_FTS5=1 \
257                  -DSQLITE_3_SUFFIX_ONLY=1 \
258                  -DSQLITE_ENABLE_RTREE=1 \
259                  -DSQLITE_ENABLE_GEOPOLY=1 \
260                  -DSQLITE_ENABLE_MATH_FUNCTIONS=1 \
261                  -DSQLITE_ENABLE_DESERIALIZE=1 \
262                  -DSQLITE_ENABLE_DBPAGE_VTAB=1 \
263                  -DSQLITE_ENABLE_BYTECODE_VTAB=1 \
264                  -DSQLITE_ENABLE_DBSTAT_VTAB=1
265
266CON_CFLAGS	= $(cflags) $(cdebug) $(crt) -DCONSOLE -DSQLITE_ENABLE_FTS3=1
267TCL_CFLAGS	= -DBUILD_sqlite -DUSE_TCL_STUBS \
268                  -DPACKAGE_VERSION="\"$(DOTVERSION)\"" $(BASE_CLFAGS) \
269                  $(OPTDEFINES)
270
271#---------------------------------------------------------------------
272# Link flags
273#---------------------------------------------------------------------
274
275!if $(DEBUG)
276ldebug	= -debug:full -debugtype:cv
277!else
278ldebug	= -release -opt:ref -opt:icf,3
279!endif
280
281### Declarations common to all linker options
282lflags	= -nologo -machine:$(MACHINE) $(ldebug)
283
284!if $(PROFILE)
285lflags	= $(lflags) -profile
286!endif
287
288!if $(ALIGN98_HACK) && !$(STATIC_BUILD)
289### Align sections for PE size savings.
290lflags	= $(lflags) -opt:nowin98
291!else if !$(ALIGN98_HACK) && $(STATIC_BUILD)
292### Align sections for speed in loading by choosing the virtual page size.
293lflags	= $(lflags) -align:4096
294!endif
295
296!if $(LOIMPACT)
297lflags	= $(lflags) -ws:aggressive
298!endif
299
300dlllflags = $(lflags) -dll
301conlflags = $(lflags) -subsystem:console
302guilflags = $(lflags) -subsystem:windows
303baselibs   = $(TCLSTUBLIB)
304
305#---------------------------------------------------------------------
306# TclTest flags
307#---------------------------------------------------------------------
308
309!IF "$(TESTPAT)" != ""
310TESTFLAGS = $(TESTFLAGS) -file $(TESTPAT)
311!ENDIF
312
313#---------------------------------------------------------------------
314# Project specific targets (EDIT)
315#---------------------------------------------------------------------
316
317all:	    setup $(PROJECT)
318$(PROJECT): setup $(PRJLIB)
319install:    install-binaries install-libraries install-docs
320
321# Tests need to ensure we load the right dll file we
322# have to handle the output differently on Win9x.
323#
324!if "$(OS)" == "Windows_NT"  || "$(MSVCDIR)" == "IDE"
325test: setup $(PROJECT)
326        set TCL_LIBRARY=$(ROOT)/library
327        $(TCLSH) <<
328load $(PRJLIB:\=/)
329cd "$(ROOT)/tests"
330set argv "$(TESTFLAGS)"
331source all.tcl
332<<
333!else
334test: setup $(PROJECT)
335        echo Please wait while the test results are collected
336        set TCL_LIBRARY=$(ROOT)/library
337        $(TCLSH) << >tests.log
338load $(PRJLIB:\=/)
339cd "$(ROOT)/tests"
340set argv "$(TESTFLAGS)"
341source all.tcl
342<<
343        type tests.log | more
344!endif
345
346setup:
347	@if not exist $(OUT_DIR)\nul mkdir $(OUT_DIR)
348	@if not exist $(TMP_DIR)\nul mkdir $(TMP_DIR)
349
350$(PRJLIB): $(DLLOBJS)
351	$(link32) $(dlllflags) -out:$@ $(baselibs) @<<
352$**
353<<
354	-@del $*.exp
355
356$(PRJSTUBLIB): $(PRJSTUBOBJS)
357	$(lib32) -nologo -out:$@ $(PRJSTUBOBJS)
358
359#---------------------------------------------------------------------
360# Implicit rules
361#---------------------------------------------------------------------
362
363$(TMP_DIR)\sqlite3.obj:		$(SQLITE_SRCDIR)\sqlite3.c
364	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
365		-c $(SQLITE_SRCDIR)\sqlite3.c
366
367$(TMP_DIR)\tclsqlite.obj:	$(TCLSQLITE_SRCDIR)\tclsqlite.c
368	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
369		-c $(TCLSQLITE_SRCDIR)\tclsqlite.c
370
371$(TMP_DIR)\tclsqlite3.obj:	$(TCLSQLITE_SRCDIR)\tclsqlite3.c
372	$(cc32) $(TCL_CFLAGS) -DBUILD_$(PROJECT) -Fo$(TMP_DIR)\ \
373		-c $(TCLSQLITE_SRCDIR)\tclsqlite3.c
374
375{$(WINDIR)}.rc{$(TMP_DIR)}.res:
376	$(rc32) -fo $@ -r -i "$(GENERICDIR)" -D__WIN32__ \
377!if $(DEBUG)
378	-d DEBUG \
379!endif
380!if $(TCL_THREADS)
381	-d TCL_THREADS \
382!endif
383!if $(STATIC_BUILD)
384	-d STATIC_BUILD \
385!endif
386	$<
387
388.SUFFIXES:
389.SUFFIXES:.c .rc
390
391#---------------------------------------------------------------------
392# Installation. (EDIT)
393#
394# You may need to modify this section to reflect the final distribution
395# of your files and possibly to generate documentation.
396#
397#---------------------------------------------------------------------
398
399install-binaries:
400	@echo Installing binaries to '$(SCRIPT_INSTALL_DIR)'
401	@if not exist "$(SCRIPT_INSTALL_DIR)" mkdir "$(SCRIPT_INSTALL_DIR)"
402	@$(CPY) $(PRJLIB) "$(SCRIPT_INSTALL_DIR)" >NUL
403
404install-libraries:
405        @echo Installing libraries to '$(SCRIPT_INSTALL_DIR)'
406        @if exist $(LIBDIR) $(CPY) $(LIBDIR)\*.tcl "$(SCRIPT_INSTALL_DIR)"
407        @echo Installing package index in '$(SCRIPT_INSTALL_DIR)'
408        @type << >"$(SCRIPT_INSTALL_DIR)\pkgIndex.tcl"
409package ifneeded $(PROJECT) $(DOTVERSION) \
410    [list load [file join $$dir $(PRJLIBNAME)] sqlite3]
411<<
412
413install-docs:
414	@echo Installing documentation files to '$(DOC_INSTALL_DIR)'
415	@if exist $(DOCDIR) $(CPY) $(DOCDIR)\*.n "$(DOC_INSTALL_DIR)"
416
417#---------------------------------------------------------------------
418# Clean up
419#---------------------------------------------------------------------
420
421clean:
422	@if exist $(TMP_DIR)\nul $(RMDIR) $(TMP_DIR)
423	@if exist $(WINDIR)\version.vc del $(WINDIR)\version.vc
424
425realclean: clean
426	@if exist $(OUT_DIR)\nul $(RMDIR) $(OUT_DIR)
427
428distclean: realclean
429	@if exist $(WINDIR)\nmakehlp.exe del $(WINDIR)\nmakehlp.exe
430	@if exist $(WINDIR)\nmakehlp.obj del $(WINDIR)\nmakehlp.obj
431