Fix build failures from a clean checkout
The compilation recipe expects the presence of a bin directory to
emit the output binary. That directory does not exist in a clean
checkout of the repository, causing the link recipe to fail. Fix that
recipe to make that directory if it doesn't already exist.
~~GCC 6.2.0 emits warnings due to the unknown %z format specifier in
printf calls. Remove the -Werror compiler option to prevent the
build from failing due to this.~~
Also ignore the build products in the bin directory in .gitignore.
The Makefile allows the test target rule to run parallel to the
$(TARGETS) rule (especially when recipe parallelization is enabled),
which results in several test failures due to the programs not yet
linked. Fix this by enlisting $(TARGETS) as a prerequisite of test.
Finally, fix a minor warning in mcp19 due to GCC thinking a variable
gets used without initialization. While GCC is incorrect here, the
warning does cause the build to fail.
Sample compiler warning that was causing the build to fail:
In file included from mcp6.c:1:0:
util-1.h: In function 'pool_report':
util-1.h:58:21: warning: unknown conversion type character 'z' in format [-Wformat=]
printf("pool has %zu bytes in %zu blocks\n", nbytes, nblocks);
^
util-1.h:58:34: warning: unknown conversion type character 'z' in format [-Wformat=]
printf("pool has %zu bytes in %zu blocks\n", nbytes, nblocks);
^
util-1.h:58:10: warning: too many arguments for format [-Wformat-extra-args]
printf("pool has %zu bytes in %zu blocks\n", nbytes, nblocks);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
That's very weird. %zu is the c99-standard format for a size_t, and has been supported by GCC since version ~3.
I should have mentioned, I am on a Windows 7 64-bit machine with GCC 6.2.0 from MinGW-w64. I ran the Makefile like this: mingw32-make bin/mcp6 CC=gcc
which invoked the following compiler command: gcc -std=c99 -Wall -Werror -Wextra -Wno-unused -pedantic -g -O3 -c -o mcp6.o mcp6.c.
A bit of Google-ing suggests that MinGW-w64 uses the MSVCRT which doesn't support the 'z' size modifier introduced in C99. Both cppreference.com and the Open Group's POSIX spec confirm its existence, and a test-compile with GCC 5.4.0 on a Lubuntu 16.04 VM worked.
So you're right, I'll revert the -Werror removal from this PR.
UPDATE: I was able to build it warning-free on MinGW-w64 by employing the __USE_MINGW_ANSI_STDIO macro, as follows:
mingw32-make bin/mcp6 CC=gcc CPPFLAGS=-D__USE_MINGW_ANSI_STDIO=1
However, while attempting a full build I encountered an unrelated warning on mcp19 (even on my Linux VM):
cc -std=c99 -Wall -Werror -Wextra -Wno-unused -pedantic -g -O3 -c -o mcp19.o mcp19.c
mcp19.c: In function ‘main’:
mcp19.c:54:13: error: ‘best’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
uint8_t best;
^
cc1: all warnings being treated as errors
<builtin>: recipe for target 'mcp19.o' failed
make: *** [mcp19.o] Error 1
I'll update this PR with a fix for this.