Skip to content

Commit 889f887

Browse files
committed
build: Add NMake Makefiles for building libdatre
This adds a set of NMake Makefiles which can be used to build libdatrie with Visual Studio on Windows. It can be used to build -The libdatrie DLL -The trietool utility program (disabled with 'LIB_ONLY=1') -The test programs (with the 'tests' target)
1 parent fd341da commit 889f887

14 files changed

+600
-2
lines changed

Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ACLOCAL_AMFLAGS = -I m4
22

3-
SUBDIRS = datrie tools man doc tests
3+
SUBDIRS = datrie tools man doc tests win32
44

55
EXTRA_DIST = \
66
README.migration \

configure.ac

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,7 @@ AC_CONFIG_FILES([Makefile
141141
man/Makefile
142142
doc/Makefile
143143
doc/Doxyfile
144-
tests/Makefile])
144+
tests/Makefile
145+
win32/config-msvc.mak
146+
win32/Makefile])
145147
AC_OUTPUT

win32/Makefile.am

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
EXTRA_DIST = \
2+
build-rules-msvc.mak \
3+
config-msvc.mak \
4+
create-lists-msvc.mak \
5+
create-lists.bat \
6+
create-pc.bat \
7+
detectenv-msvc.mak \
8+
generate-msvc.mak \
9+
info-msvc.mak \
10+
install.mak \
11+
Makefile.vc \
12+
README.txt \
13+
$(NULL)

win32/Makefile.vc

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# NMake Makefile for building libdatrie on Windows
2+
3+
# The items below this line should not be changed, unless one is maintaining
4+
# the NMake Makefiles. Customizations can be done in the following NMake Makefile
5+
# portions (please see comments in the these files to see what can be customized):
6+
#
7+
# detectenv-msvc.mak
8+
# config-msvc.mak
9+
10+
!include detectenv-msvc.mak
11+
12+
# Include the Makefile portion that enables features based on user input
13+
!include config-msvc.mak
14+
15+
!if "$(VALID_CFGSET)" == "TRUE"
16+
17+
18+
all: $(DATRIE_LIBS) $(DATRIE_UTILS) all-build-info
19+
20+
# Include the Makefile portion to convert the source and header lists
21+
# into the lists we need for compilation and introspection
22+
!include create-lists-msvc.mak
23+
24+
tests: all $(datrie_tests)
25+
26+
# Include the build rules for sources, DLLs and executables
27+
!include build-rules-msvc.mak
28+
29+
# Include the rules for build directory creation and code generation
30+
!include generate-msvc.mak
31+
32+
!include install.mak
33+
34+
!else # "$(VALID_CFGSET)" == "TRUE"
35+
all: help
36+
@echo You need to specify a valid configuration, via
37+
@echo CFG=release or CFG=debug
38+
!endif # "$(VALID_CFGSET)" == "TRUE"
39+
40+
!include info-msvc.mak

win32/README.txt

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Instructions for building libdatrie on Visual Studio
2+
====================================================
3+
Building the libdatrie on Windows is now supported using Visual Studio.
4+
5+
You will need the following items to build libdatrie using Visual Studio:
6+
-libiconv (including the libcharset headers and libraries) if building trietool.exe
7+
8+
Invoke the build by issuing the command:
9+
nmake /f Makefile.vc CFG=[release|debug] [PREFIX=...] <option1=1 option2=1 ...>
10+
where:
11+
12+
CFG: Required. Choose from a release or debug build. Note that
13+
all builds generate a .pdb file for each .dll and .exe built--this refers
14+
to the C/C++ runtime that the build uses.
15+
16+
PREFIX: Optional. Base directory of where the third-party headers, libraries
17+
and needed tools can be found, i.e. headers in $(PREFIX)\include,
18+
libraries in $(PREFIX)\lib and tools in $(PREFIX)\bin. If not
19+
specified, $(PREFIX) is set as $(srcroot)\..\vs$(X)\$(platform), where
20+
$(platform) is win32 for 32-bit builds or x64 for 64-bit builds, and
21+
$(X) is the short version of the Visual Studio used, as follows:
22+
2008: 9
23+
2010: 10
24+
2012: 11
25+
2013: 12
26+
2015, 2017, 2019: 14
27+
28+
Explanation of options, set by <option>=1:
29+
------------------------------------------
30+
LIB_ONLY: Disables building trietool.exe, which eliminates the need for libiconv.
31+
32+
An 'install' target is provided to copy the built items and public headers to appropriate
33+
locations under $(PREFIX), a 'clean' target is provided to remove all the items that are
34+
created during the build, and a 'tests' target is provided to build the test programs.

win32/build-rules-msvc.mak

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# NMake Makefile portion for compilation rules
2+
# Items in here should not need to be edited unless
3+
# one is maintaining the NMake build files. The format
4+
# of NMake Makefiles here are different from the GNU
5+
# Makefiles. Please see the comments about these formats.
6+
7+
# Inference rules for compiling the .obj files.
8+
# Used for libs and programs with more than a single source file.
9+
# Format is as follows
10+
# (all dirs must have a trailing '\'):
11+
#
12+
# {$(srcdir)}.$(srcext){$(destdir)}.obj::
13+
# $(CC)|$(CXX) $(cflags) /Fo$(destdir) /c @<<
14+
# $<
15+
# <<
16+
{..\datrie\}.c{vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\}.obj::
17+
$(CC) $(CFLAGS) $(LIBDATRIE_BASE_CFLAGS) /Fovs$(PDBVER)\$(CFG)\$(PLAT)\datrie\ /Fdvs$(PDBVER)\$(CFG)\$(PLAT)\datrie\ /c @<<
18+
$<
19+
<<
20+
21+
{..\tools\}.c{vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\}.obj::
22+
$(CC) $(CFLAGS) $(TRIETOOL_CFLAGS) /Fovs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ /Fdvs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ /c @<<
23+
$<
24+
<<
25+
26+
{..\tests\}.c{vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\}.obj::
27+
@if not exist vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ $(MAKE) /f Makefile.vc CFG=$(CFG) vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests
28+
$(CC) $(CFLAGS) $(LIBDATRIE_BASE_CFLAGS) /Fovs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ /Fdvs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ /c @<<
29+
$<
30+
<<
31+
32+
# Rules for building .lib files
33+
vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.lib: vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.dll
34+
35+
# Rules for linking DLLs
36+
# Format is as follows (the mt command is needed for MSVC 2005/2008 builds):
37+
# $(dll_name_with_path): $(dependent_libs_files_objects_and_items)
38+
# link /DLL [$(linker_flags)] [$(dependent_libs)] [/def:$(def_file_if_used)] [/implib:$(lib_name_if_needed)] -out:$@ @<<
39+
# $(dependent_objects)
40+
# <<
41+
# @-if exist [email protected] mt /manifest [email protected] /outputresource:$@;2
42+
vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.dll: \
43+
vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\datrie.def \
44+
vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-0.2.pc \
45+
$(libdatrie_dll_OBJS)
46+
link /DLL $(LDFLAGS) /implib:$(@R).lib /def:vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\datrie.def \
47+
-out:$@ @<<
48+
$(libdatrie_dll_OBJS)
49+
<<
50+
@-if exist [email protected] mt /manifest [email protected] /outputresource:$@;2
51+
52+
# Rules for linking Executables
53+
# Format is as follows (the mt command is needed for MSVC 2005/2008 builds):
54+
# $(dll_name_with_path): $(dependent_libs_files_objects_and_items)
55+
# link [$(linker_flags)] [$(dependent_libs)] -out:$@ @<<
56+
# $(dependent_objects)
57+
# <<
58+
# @-if exist [email protected] mt /manifest [email protected] /outputresource:$@;1
59+
60+
vs$(PDBVER)\$(CFG)\$(PLAT)\trietool.exe: vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.lib vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\config.h $(trietool_OBJS)
61+
link $(LDFLAGS) vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.lib $(TRIETOOL_DEP_LIBS) -out:$@ $(trietool_OBJS)
62+
@-if exist $@.manifest mt /manifest $@.manifest /outputresource:$@;1
63+
64+
$(datrie_tests):
65+
link $(LDFLAGS) $** -out:$@
66+
@-if exist $@.manifest mt /manifest $@.manifest /outputresource:$@;1
67+
68+
clean:
69+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-0.2.pc
70+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.exe
71+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.dll
72+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.pdb
73+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.ilk
74+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.exp
75+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\*.lib
76+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\vc$(PDBVER)0.pdb
77+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\*.obj
78+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests\ rd vs$(PDBVER)\$(CFG)\$(PLAT)\datrie-tests
79+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\vc$(PDBVER)0.pdb
80+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\*.obj
81+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\config.h
82+
@-if exist vs$(PDBVER)\$(CFG)\$(PLAT)\trietool\ rd vs$(PDBVER)\$(CFG)\$(PLAT)\trietool
83+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\vc$(PDBVER)0.pdb
84+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\datrie.def
85+
@-del /f /q vs$(PDBVER)\$(CFG)\$(PLAT)\datrie\*.obj
86+
@-rd vs$(PDBVER)\$(CFG)\$(PLAT)\datrie

win32/config-msvc.mak.in

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# NMake Makefile portion for enabling features for Windows builds
2+
3+
# These are the base minimum libraries required for building libdatrie.
4+
BASE_INCLUDES = /I$(PREFIX)\include
5+
6+
# Adjust as needed to your setup for libiconv and libcharset
7+
TRIETOOL_DEP_LIBS = iconv.lib charset.lib
8+
9+
# Please do not change anything beneath this line unless maintaining the NMake Makefiles
10+
# Bare minimum features and sources built into libdatrie on Windows
11+
12+
DATRIE_VERSION = @VERSION@
13+
DATRIE_LIBS = vs$(PDBVER)\$(CFG)\$(PLAT)\datrie.lib
14+
LIBDATRIE_BASE_CFLAGS = /I.. /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_WARNINGS
15+
TRIETOOL_CFLAGS = /Ivs$(PDBVER)\$(CFG)\$(PLAT)\trietool $(LIBDATRIE_BASE_CFLAGS) $(BASE_INCLUDES)
16+
17+
# Disable building trietool.exe if requested
18+
!if "$(LIB_ONLY)" == "1"
19+
DATRIE_UTILS =
20+
!else
21+
DATRIE_UTILS = vs$(PDBVER)\$(CFG)\$(PLAT)\trietool.exe
22+
!endif

win32/create-lists-msvc.mak

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Convert the source listing to object (.obj) listing in
2+
# another NMake Makefile module, include it, and clean it up.
3+
# This is a "fact-of-life" regarding NMake Makefiles...
4+
# This file does not need to be changed unless one is maintaining the NMake Makefiles
5+
6+
# For those wanting to add things here:
7+
# To add a list, do the following:
8+
# # $(description_of_list)
9+
# if [call create-lists.bat header $(makefile_snippet_file) $(variable_name)]
10+
# endif
11+
#
12+
# if [call create-lists.bat file $(makefile_snippet_file) $(file_name)]
13+
# endif
14+
#
15+
# if [call create-lists.bat footer $(makefile_snippet_file)]
16+
# endif
17+
# ... (repeat the if [call ...] lines in the above order if needed)
18+
# !include $(makefile_snippet_file)
19+
#
20+
# (add the following after checking the entries in $(makefile_snippet_file) is correct)
21+
# (the batch script appends to $(makefile_snippet_file), you will need to clear the file unless the following line is added)
22+
#!if [del /f /q $(makefile_snippet_file)]
23+
#!endif
24+
25+
# In order to obtain the .obj filename that is needed for NMake Makefiles to build DLLs/static LIBs or EXEs, do the following
26+
# instead when doing 'if [call create-lists.bat file $(makefile_snippet_file) $(file_name)]'
27+
# (repeat if there are multiple $(srcext)'s in $(source_list), ignore any headers):
28+
# !if [for %c in ($(source_list)) do @if "%~xc" == ".$(srcext)" @call create-lists.bat file $(makefile_snippet_file) $(intdir)\%~nc.obj]
29+
#
30+
# $(intdir)\%~nc.obj needs to correspond to the rules added in build-rules-msvc.mak
31+
# %~xc gives the file extension of a given file, %c in this case, so if %c is a.cc, %~xc means .cc
32+
# %~nc gives the file name of a given file without extension, %c in this case, so if %c is a.cc, %~nc means a
33+
34+
NULL=
35+
36+
# For libdatrie
37+
!if [call create-lists.bat header datrie_objs.mak libdatrie_dll_OBJS]
38+
!endif
39+
40+
!if [for %c in (..\datrie\*.c) do @call create-lists.bat file datrie_objs.mak vs^$(PDBVER)\^$(CFG)\^$(PLAT)\datrie\%~nc.obj]
41+
!endif
42+
43+
!if [call create-lists.bat footer datrie_objs.mak]
44+
!endif
45+
46+
# For trietool
47+
!if [call create-lists.bat header datrie_objs.mak trietool_OBJS]
48+
!endif
49+
50+
!if [for %c in (..\tools\*.c) do @call create-lists.bat file datrie_objs.mak vs^$(PDBVER)\^$(CFG)\^$(PLAT)\trietool\%~nc.obj]
51+
!endif
52+
53+
!if [call create-lists.bat footer datrie_objs.mak]
54+
!endif
55+
56+
# For test programs
57+
!if [call create-lists.bat header datrie_objs.mak datrie_tests]
58+
!endif
59+
60+
!if [for %c in (..\tests\*.c) do @if not "%~nc" == "utils" @call create-lists.bat file datrie_objs.mak vs^$(PDBVER)\^$(CFG)\^$(PLAT)\%~nc.exe]
61+
!endif
62+
63+
!if [call create-lists.bat footer datrie_objs.mak]
64+
!endif
65+
66+
!if [for %c in (..\tests\*.c) do @if not "%~nc" == "utils" @echo vs^$(PDBVER)\^$(CFG)\^$(PLAT)\%~nc.exe: vs^$(PDBVER)\^$(CFG)\^$(PLAT)\datrie.lib vs^$(PDBVER)\^$(CFG)\^$(PLAT)\datrie-tests\%~nc.obj vs^$(PDBVER)\^$(CFG)\^$(PLAT)\datrie-tests\utils.obj>>datrie_objs.mak]
67+
!endif
68+
69+
!include datrie_objs.mak
70+
71+
!if [del /f /q datrie_objs.mak]
72+
!endif

win32/create-lists.bat

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@echo off
2+
rem Simple .bat script for creating the NMake Makefile snippets.
3+
4+
if not "%1" == "header" if not "%1" == "file" if not "%1" == "footer" goto :error_cmd
5+
if "%2" == "" goto error_no_destfile
6+
7+
if "%1" == "header" goto :header
8+
if "%1" == "file" goto :addfile
9+
if "%1" == "footer" goto :footer
10+
11+
:header
12+
if "%3" == "" goto error_var
13+
echo %3 = \>>%2
14+
goto done
15+
16+
:addfile
17+
if "%3" == "" goto error_file
18+
echo. %3 \>>%2
19+
goto done
20+
21+
:footer
22+
echo. $(NULL)>>%2
23+
echo.>>%2
24+
goto done
25+
26+
:error_cmd
27+
echo Specified command '%1' was invalid. Valid commands are: header file footer.
28+
goto done
29+
30+
:error_no_destfile
31+
echo Destination NMake snippet file must be specified
32+
goto done
33+
34+
:error_var
35+
echo A name must be specified for using '%1'.
36+
goto done
37+
38+
:error_file
39+
echo A file must be specified for using '%1'.
40+
goto done
41+
42+
:done

win32/create-pc.bat

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
@echo off
2+
rem Simple .bat script for creating the NMake Makefile snippets.
3+
4+
if "%1" == "" goto :error_no_dest
5+
if "%2" == "" goto :error_no_ver
6+
if "%3" == "" goto :error_dst
7+
8+
set pfx=%~dnp3
9+
echo prefix=%pfx:\=/%>%1
10+
echo exec_prefix=^$^{prefix^}>>%1
11+
echo libdir=^$^{prefix^}/lib>>%1
12+
echo includedir=^$^{prefix^}/include>>%1
13+
echo.>>%1
14+
echo Name: datrie>>%1
15+
echo Description: Double-array trie library>>%1
16+
echo Version: %2>>%1
17+
echo Libs: -L^$^{libdir^} -ldatrie>>%1
18+
echo Cflags: -I^$^{includedir^}>>%1
19+
goto done
20+
21+
:error_no_dest
22+
echo No output file specified
23+
goto done
24+
25+
:error_no_ver
26+
echo No version specified
27+
goto done
28+
29+
:error_dst
30+
echo A prefix path must be specified
31+
goto done
32+
33+
:done

0 commit comments

Comments
 (0)