I am working from Fossil sources, and the following two Makeheaders bugs
caused builds of Fossil to fail on the relevant platform; since I can’t
seem to find a specific place for discussing Makeheaders, I will try
reporting here.
Version info for both below bugs:
makeheaders.c version [7746e0ebf5b37495] (from Fossil sources).
Target/tested platform: MSVC 2010, as installed with Windows SDK 7.1
Microsoft (R) C/C++ Optimizing Compiler Version 16.00.30319.01 for x64
Run with: setenv /release /x64 /vista (also tried /win7)
For reference, this was observed when building the Fossil with manifest
version [d090292800] (2010-08-05).
== Bug #1: makeheaders.c assumes that WIN32 is #defined on Windows.
At lines 18–22, makeheaders.c contains the following #ifdefs which cause
failure building with MSVC on x64:
#ifndef WIN32
# include <unistd.h>
#else
# include <string.h>
#endif
A trivial test on my system proves that WIN32 is undefined in the
above-listed build environment.
Workaround: Compile makeheaders with /DWIN32. I don’t know if this has
any unwanted side effects for makeheaders itself; it could definitely have
destructive side effects if the same compile flag is used with code which
uses WIN32 to differentiate between 32-bit and 64-bit platforms.
Suggested change: According to [1], the macro _WIN32 (single underscore)
is “always defined” on Windows. The attached c file correctly detects my
system as Windows; I have not tested it on a 32-bit system, nor with
GCC/Mingw, nor with excluding code from non-Windows systems.
[1] http://msdn.microsoft.com/en-us/library/b0084kay.aspx
Burden of resolving: Trivial; add a single underscore. That is, of
course, if other platforms see _WIN32 the same way...
== Bug #2:
Makeheaders produces lines like this—note the location of the closing
parenthesis:
#if defined(__MINGW32__ /* This code is for win32 only */)
...which in turn, causes MSVC to choke when building Fossil:
main_.c
c:\path\main.h(2) : error C2004: expected 'defined(id)'
c:\path\main.h(2) : fatal error C1012: unmatched parenthesis : missing ')'
winhttp_.c
c:\path\winhttp.h(5) : error C2004: expected 'defined(id)'
c:\path\winhttp.h(5) : fatal error C1012: unmatched parenthesis : missing
')'
(Also affects winhttp.h(124).)
The observed case *appears* to stem from Fossil’s winhttp.c(21):
#ifdef __MINGW32__ /* This code is for win32 only */
Workaround: Manually edit the makeheaders output to put the closing
parenthesis *before* the comment. This defeats the purpose of
makeheaders, but stops cl.exe from dying with an error. I suppose a sed
script would also work, with accompanying dangers.
I do not know how to fix this in makeheaders.c.
N.b., I don’t know whether this technically constitutes a bug in
makeheaders.c, or a bug in MSVC. But whether or not the C standard
*technically* allows a comment inside parenthesis in #if statements, it
impairs usability for humans, and seems overall like a bad practice. And
of course, it causes builds to fail.
== End of bugs.
Samuel Adam
763 Montgomery Road
Hillsborough, NJ 08844-1304
United States
#include <stdio.h>
/* See http://msdn.microsoft.com/en-us/library/b0084kay.aspx */
int main(void) {
#ifdef _WIN32
printf("This is detected as a Windows target.");
return 0;
#else
printf("This is NOT detected as a Windows target.");
return 1;
#endif
}
_______________________________________________
fossil-users mailing list
fossil-users@lists.fossil-scm.org
http://lists.fossil-scm.org:8080/cgi-bin/mailman/listinfo/fossil-users