summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon TURNEY <jon.turney@dronecode.org.uk>2013-08-06 16:35:28 +0100
committerJon TURNEY <jon.turney@dronecode.org.uk>2013-08-06 18:01:06 +0100
commitc253121aabd940107fac2ce85668993cc7e94237 (patch)
tree0390e58c550821617ae3dd7cd3c6eeda7c29cc40
parent6e6df220c717862a3ca1c2094aa37c7c4bc911b3 (diff)
Provide our own htmlhelp library codexlaunch-20130806-1
- libhtmlhelp.a we now provide ourself - htmlhelp.h comes from MinGW-w64 w32api - hhc.exe comes from the HTML Help Workshop We need to do this because: - w32api doesn't provde a libhtmlhelp.a, and we don't know where to get one for x86_64 that is actually useful - maybe there are some license issue with linking with htlphelp.lib from a Microsoft PSDK and the cygwin DLL?
-rw-r--r--.gitignore1
-rw-r--r--Makefile.am6
-rw-r--r--README4
-rw-r--r--configure.ac21
-rw-r--r--lib/Makefile.am4
-rw-r--r--lib/init.c83
-rw-r--r--lib/sub.c24
7 files changed, 125 insertions, 18 deletions
diff --git a/.gitignore b/.gitignore
index d568312..b4cf751 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
*.o
+*.a
.deps
.dirstamp
Makefile
diff --git a/Makefile.am b/Makefile.am
index 07279ac..397a830 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,8 +5,8 @@ if DEBUG
DEBUG_FLAGS=-D_DEBUG
endif
-AM_CXXFLAGS = $(DEBUG_FLAGS) -Wall $(HTMLHELP_CFLAGS) $(LIBXML2_CFLAGS) -DDOCDIR=\"`cygpath -m @docdir@`\"
-LDADD = -lcomctl32 $(LIBX11_LIBS) $(HTMLHELP_LDFLAGS) $(LIBXML2_LIBS)
+AM_CXXFLAGS = $(DEBUG_FLAGS) -Wall $(LIBXML2_CFLAGS) -DDOCDIR=\"`cygpath -m @docdir@`\"
+LDADD = -lcomctl32 lib/libhtmlhelp.a $(LIBX11_LIBS) $(LIBXML2_LIBS)
AM_LDFLAGS = -mwindows
xlaunch_SOURCES = \
@@ -56,4 +56,4 @@ EXTRA_DIST = \
window/window.h \
window/wizard.h
-SUBDIRS = htmlhelp man
+SUBDIRS = htmlhelp man lib
diff --git a/README b/README
index d54d1ef..00dcc70 100644
--- a/README
+++ b/README
@@ -11,8 +11,8 @@ building
g++, libX11, libxml-2.0 are required to build xlaunch.
-In addition, the "Microsoft HTML Help Workshop 1.3" is required, both for the htmlhelp SDK
-headers and library, and for the CHM compiler hhc.exe. It can be downloaded from [1].
+In addition, the "Microsoft HTML Help Workshop 1.3" is required for the CHM compiler hhc.exe.
+It can be downloaded from [1].
[1] http://msdn.microsoft.com/en-us/library/ms669985
diff --git a/configure.ac b/configure.ac
index 084237c..c04f4e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -26,7 +26,9 @@ AC_ARG_ENABLE(debug, AS_HELP_STRING([--enable-debug], [Enable debugging (default
[DEBUG=$enableval], [DEBUG=no])
AM_CONDITIONAL(DEBUG, [test "x$DEBUG" = xyes])
+AC_PROG_CC
AC_PROG_CXX
+AC_PROG_RANLIB
AC_CHECK_TOOL(WINDRES, windres)
PKG_CHECK_MODULES([LIBX11], [x11])
@@ -48,20 +50,13 @@ rm -f /tmp/HtmlHelpWorkshop
ln -sf "$htmlhelp_sdk" /tmp/HtmlHelpWorkshop
htmlhelp_sdk=/tmp/HtmlHelpWorkshop
-HTMLHELP_CFLAGS="-I$htmlhelp_sdk/include"
-HTMLHELP_LDFLAGS="-L$htmlhelp_sdk/lib -lhtmlhelp"
-HHC="$htmlhelp_sdk/hhc"
-AC_SUBST([HTMLHELP_CFLAGS])
-AC_SUBST([HTMLHELP_LDFLAGS])
-AC_SUBST([HHC])
-
-# check for the existence of htmlhelp.h
-save_CFLAGS=$CFLAGS
-CFLAGS="$CFLAGS $HTMLHELP_CFLAGS"
-AC_CHECK_HEADER([htmlhelp.h], , [AC_MSG_ERROR([HtmlHelp SDK is required])] , [#include <windows.h>])
-CFLAGS=$save_CFLAGS
+# check for the existence of hhc.exe
+AC_PATH_PROG(HHC, hhc, , $htmlhelp_sdk)
+if test -z "$HHC" ; then
+ AC_MSG_ERROR([HtmlHelp SDK is required])
+fi
PKG_CHECK_MODULES([LIBXML2], [libxml-2.0])
-AC_CONFIG_FILES([Makefile htmlhelp/Makefile man/Makefile])
+AC_CONFIG_FILES([Makefile htmlhelp/Makefile man/Makefile lib/Makefile])
AC_OUTPUT
diff --git a/lib/Makefile.am b/lib/Makefile.am
new file mode 100644
index 0000000..b74f086
--- /dev/null
+++ b/lib/Makefile.am
@@ -0,0 +1,4 @@
+
+noinst_LIBRARIES = libhtmlhelp.a
+
+libhtmlhelp_a_SOURCES = init.c
diff --git a/lib/init.c b/lib/init.c
new file mode 100644
index 0000000..6343e91
--- /dev/null
+++ b/lib/init.c
@@ -0,0 +1,83 @@
+/*
+ Copied from https://github.com/yumeyao/7zip
+ "building 7zip using vc8(x86) and vc11(x64) while still linking to msvcrt.dll"
+
+ To the best of my knowledge this file is licensed under the LGPL.
+
+ PSDK versions of htmlhelp.lib for x86_64 depend on bufferoverflowU.lib for __security_cookie,
+ since they are compiled with VC using the /GS flag
+
+ This also improves on the x86 library in previous SDK, since it adds functionality to expand
+ REG_EXPAND_SZ to a full path.
+*/
+
+#include <windows.h>
+
+static HMODULE g_hmodHHCtrl = NULL;
+static BOOL g_fTriedAndFailed = FALSE;
+typedef HWND (WINAPI *pHtmlHelpA_t)(HWND hwndCaller, LPCSTR pszFile, UINT uCommand, DWORD_PTR dwData);
+typedef HWND (WINAPI *pHtmlHelpW_t)(HWND hwndCaller, LPCWSTR pszFile, UINT uCommand, DWORD_PTR dwData);
+pHtmlHelpA_t pHtmlHelpA = NULL;
+pHtmlHelpW_t pHtmlHelpW = NULL;
+#define HtmlHelpAHint 14
+#define HtmlHelpWHint 15
+
+__attribute__((always_inline)) static LPSTR GetRegisteredLocation(LPSTR pszPath, LPSTR pszExpandedPath)
+{
+ LPSTR ret = NULL;
+ HKEY hKey;
+ DWORD cbData;
+ DWORD dwType;
+ if (ERROR_SUCCESS != RegOpenKeyExA(
+ HKEY_CLASSES_ROOT,
+ "CLSID\\{ADB880A6-D8FF-11CF-9377-00AA003B7A11}\\InprocServer32",
+ 0, KEY_READ, &hKey))
+ return ret;
+ cbData = MAX_PATH;
+ if (ERROR_SUCCESS == RegQueryValueExA(hKey, NULL, NULL, &dwType, (LPBYTE)pszPath, &cbData)) {
+ if (REG_EXPAND_SZ==dwType) {
+ if (MAX_PATH == ExpandEnvironmentStringsA(pszPath, pszExpandedPath, MAX_PATH)) {
+ ret = pszExpandedPath;
+ }
+ } else {
+ ret = pszPath;
+ }
+ }
+ RegCloseKey(hKey);
+ return ret;
+}
+
+__declspec(noinline) static HMODULE WINAPI TryLoadingModule()
+{
+ CHAR szPath[MAX_PATH];
+ CHAR szExpandedPath[MAX_PATH];
+ HMODULE hMod;
+ CHAR *pszPath;
+
+ if (pszPath = GetRegisteredLocation(szPath, szExpandedPath)) {
+ hMod = LoadLibraryA(pszPath);
+ if (!hMod)
+ goto LoadDefaultPath;
+ } else {
+LoadDefaultPath:
+ hMod = LoadLibraryA("hhctrl.ocx");
+ }
+ return hMod;
+}
+
+#define _mkFuncPtr(FuncName) p##FuncName
+#define _mkFuncPtrType(FuncName) p##FuncName##_t
+#define _mkFuncHint(FuncName) FuncName##Hint
+#define mkFuncPtr(FuncName) _mkFuncPtr(FuncName)
+#define mkFuncPtrType(FuncName) _mkFuncPtrType(FuncName)
+#define mkFuncHint(FuncName) _mkFuncHint(FuncName)
+
+#define FuncName HtmlHelpA
+#define StrType LPCSTR
+#include "sub.c"
+
+#undef FuncName
+#undef StrType
+#define FuncName HtmlHelpW
+#define StrType LPCWSTR
+#include "sub.c"
diff --git a/lib/sub.c b/lib/sub.c
new file mode 100644
index 0000000..352da94
--- /dev/null
+++ b/lib/sub.c
@@ -0,0 +1,24 @@
+
+HWND WINAPI FuncName(HWND hwndCaller, StrType pszFile, UINT uCommand, DWORD_PTR dwData)
+{
+ HMODULE hMod = g_hmodHHCtrl;
+ mkFuncPtrType(FuncName) pFunc;
+ if (!hMod && g_fTriedAndFailed == FALSE) {
+ if (hMod = TryLoadingModule())
+ g_hmodHHCtrl = hMod;
+ else
+ goto Fail;
+ }
+
+ pFunc = mkFuncPtr(FuncName);
+ if (pFunc) goto CallFunc;
+ if (pFunc = (mkFuncPtrType(FuncName))GetProcAddress(g_hmodHHCtrl, (LPCSTR)mkFuncHint(FuncName))) {
+ mkFuncPtr(FuncName) = pFunc;
+CallFunc:
+ return pFunc((HWND)hwndCaller, pszFile, uCommand, dwData);
+ }
+
+Fail:
+ g_fTriedAndFailed = ~FALSE;
+ return NULL;
+}