summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChun-wei Fan <fanchunwei@src.gnome.org>2015-10-16 13:13:38 +0800
committerDan Nicholson <dbn.lists@gmail.com>2015-10-26 09:16:56 -0700
commit5f70074d46be6887a3d8e6c02c7292350fdcbdd3 (patch)
treee80ea263bffd9add2544e4018649307c8280357a
parent1ed336759fdf3bfbb1f233e5a5c5b611530436ef (diff)
build: Add NMake makefiles for Visual Studio builds
This adds a set of NMake Makefiles that can be used to build pkg-config on Windows using Visual Studio. Note that, since the Visual Studio builds of GLib does not use pkg-config, this NMake Makefile set does not support the build of the bundled GLib sources, instead, having GLib built beforehand is required.
-rw-r--r--Makefile.am2
-rw-r--r--Makefile.vc96
-rw-r--r--detectenv-msvc.mak67
3 files changed, 165 insertions, 0 deletions
diff --git a/Makefile.am b/Makefile.am
index b7ead64..2417400 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -47,6 +47,8 @@ dist_doc_DATA = pkg-config-guide.html
dist_man_MANS = pkg-config.1
EXTRA_DIST = \
README.win32 \
+ detectenv-msvc.mak \
+ Makefile.vc \
config.h.win32
# gcov test coverage
diff --git a/Makefile.vc b/Makefile.vc
new file mode 100644
index 0000000..b8d5316
--- /dev/null
+++ b/Makefile.vc
@@ -0,0 +1,96 @@
+# Note: This does assume an existing GLib installation!
+# Visual Studio builds of GLib does not need an existing pkg-config
+# installation, so build GLib first before using this.
+
+# Change these if necessary. If building from GLib's included
+# Visual Studio projects, this should be able to locate the GLib build
+# out-of-the-box if they were not moved. GLib's headers will be found
+# in $(GLIB_PREFIX)\include\glib-2.0 and $(GLIB_PREFIX)\lib\glib-2.0\include
+# and its import library will be found in $(GLIB_PREFIX)\lib.
+
+GLIB_PREFIX = ..\vs$(VSVER)\$(PLAT)
+
+# The items below this line should not be changed, unless one is maintaining
+# the NMake Makefiles.
+
+!include detectenv-msvc.mak
+
+!if "$(VALID_CFGSET)" == "TRUE"
+CFLAGS = $(CFLAGS_ADD) /W3 /Zi /FImsvc_recommended_pragmas.h /I. \
+ /I$(GLIB_PREFIX)\include\glib-2.0 \
+ /I$(GLIB_PREFIX)\lib\glib-2.0\include
+
+# PKG_CONFIG_SYSTEM_INCLUDE_PATH and PKG_CONFIG_SYSTEM_LIBRARY_PATH only
+# work for GCC builds for now, so just set this to nothing for now
+
+pkg_config_CFLAGS = \
+ $(CFLAGS) \
+ /DHAVE_CONFIG_H \
+ /DPKG_CONFIG_SYSTEM_INCLUDE_PATH="\"\"" \
+ /DPKG_CONFIG_SYSTEM_LIBRARY_PATH="\"\""
+
+LDFLAGS_BASE = $(LDFLAGS_ARCH) /libpath:$(GLIB_PREFIX)\lib /DEBUG
+NULL=
+
+!if "$(CFG)" == "debug"
+LDFLAGS = $(LDFLAGS_BASE)
+!else
+LDFLAGS = $(LDFLAGS_BASE) /opt:ref /LTCG
+!endif
+
+!include Makefile.sources
+
+# Convert the source (*.c) listing to object (.obj) listing in
+# another NMake Makefile module, include it, and clean it up.
+
+!if [echo pkg_config_OBJS = \> objs.mak]
+!endif
+
+!if [for %c in ($(pkg_config_SOURCES)) do @if "%~xc" == ".c" echo. ^$(CFG)\^$(PLAT)\pkg-config\%~nc.obj \>> objs.mak]
+!endif
+
+!if [echo. ^$(NULL)>> objs.mak]
+!endif
+
+!include objs.mak
+
+!if [del /f /q objs.mak]
+!endif
+
+pkg_config_LIBS = glib-2.0.lib
+
+{}.c{$(CFG)\$(PLAT)\pkg-config\}.obj::
+ $(CC) $(pkg_config_CFLAGS) /Fo$(CFG)\$(PLAT)\pkg-config\ /c @<<
+$<
+<<
+
+all: $(CFG)\$(PLAT)\pkg-config.exe
+
+$(CFG)\$(PLAT)\pkg-config.exe: $(CFG)\$(PLAT)\pkg-config config.h $(pkg_config_OBJS)
+ link $(LDFLAGS) $(pkg_config_LIBS) -out:$@ @<<
+$(pkg_config_OBJS)
+<<
+ @-if exist $@.manifest mt /manifest $@.manifest /outputresource:$@;1
+
+$(CFG)\$(PLAT)\pkg-config:
+ @-mkdir $@
+
+config.h: config.h.win32
+ @-copy $@.win32 $@
+
+clean:
+ @-del /f /q $(CFG)\$(PLAT)\*.pdb
+ @-del /f /q $(CFG)\$(PLAT)\*.exe.manifest
+ @-del /f /q $(CFG)\$(PLAT)\*.exe
+ @-del /f /q $(CFG)\$(PLAT)\*.ilk
+ @-del /f /q $(CFG)\$(PLAT)\pkg-config\*.obj
+ @-rmdir /s /q $(CFG)\$(PLAT)
+ @-del vc$(VSVER)0.pdb
+ @-del config.h
+
+!else
+all:
+ @echo You need to specify a valid configuration, via
+ @echo CFG=release or CFG=debug
+!endif
+
diff --git a/detectenv-msvc.mak b/detectenv-msvc.mak
new file mode 100644
index 0000000..6cd1c52
--- /dev/null
+++ b/detectenv-msvc.mak
@@ -0,0 +1,67 @@
+# Check to see we are configured to build with MSVC (MSDEVDIR, MSVCDIR or
+# VCINSTALLDIR) or with the MS Platform SDK (MSSDK or WindowsSDKDir)
+!if !defined(VCINSTALLDIR) && !defined(WINDOWSSDKDIR)
+MSG = ^
+This Makefile is only for Visual Studio 2008 and later.^
+You need to ensure that the Visual Studio Environment is properly set up^
+before running this Makefile.
+!error $(MSG)
+!endif
+
+ERRNUL = 2>NUL
+_HASH=^#
+
+!if ![echo VCVERSION=_MSC_VER > vercl.x] \
+ && ![echo $(_HASH)if defined(_M_IX86) >> vercl.x] \
+ && ![echo PLAT=Win32 >> vercl.x] \
+ && ![echo $(_HASH)elif defined(_M_AMD64) >> vercl.x] \
+ && ![echo PLAT=x64 >> vercl.x] \
+ && ![echo $(_HASH)endif >> vercl.x] \
+ && ![cl -nologo -TC -P vercl.x $(ERRNUL)]
+!include vercl.i
+!if ![echo VCVER= ^\> vercl.vc] \
+ && ![set /a $(VCVERSION) / 100 - 6 >> vercl.vc]
+!include vercl.vc
+!endif
+!endif
+!if ![del $(ERRNUL) /q/f vercl.x vercl.i vercl.vc]
+!endif
+
+!if $(VCVERSION) > 1499 && $(VCVERSION) < 1600
+VSVER = 9
+!elseif $(VCVERSION) > 1599 && $(VCVERSION) < 1700
+VSVER = 10
+!elseif $(VCVERSION) > 1699 && $(VCVERSION) < 1800
+VSVER = 11
+!elseif $(VCVERSION) > 1799 && $(VCVERSION) < 1900
+VSVER = 12
+!elseif $(VCVERSION) > 1899 && $(VCVERSION) < 2000
+VSVER = 14
+!else
+VSVER = 0
+!endif
+
+!if "$(VSVER)" == "0"
+MSG = ^
+This NMake Makefile set supports Visual Studio^
+9 (2008) through 14 (2015). Your Visual Studio^
+version is not supported.
+!error $(MSG)
+!endif
+
+VALID_CFGSET = FALSE
+!if "$(CFG)" == "release" || "$(CFG)" == "debug"
+VALID_CFGSET = TRUE
+!endif
+
+!if "$(CFG)" == "release"
+CFLAGS_ADD = /MD /O2 /GL
+!else
+CFLAGS_ADD = /MDd /Od
+!endif
+
+!if "$(PLAT)" == "x64"
+LDFLAGS_ARCH = /machine:x64
+!else
+LDFLAGS_ARCH = /machine:x86
+!endif