DavidGriffith / minipro-import-test

An open source program for controlling the MiniPRO TL866xx series of chip programmers
GNU General Public License v3.0
3 stars 0 forks source link

gcc options in Makefile #193

Open DavidGriffith opened 3 years ago

DavidGriffith commented 3 years ago

In GitLab by @hgxl64 on Nov 22, 2020, 05:31

Minipro does not build with the provided Makefile. The error is:

gcc -g -O0 -Wall -DSHARE_INSTDIR="\"/usr/local/share/minipro\"" -I/usr/include/libusb-1.0    -c -o ihex.o ihex.c
ihex.c: In function ‘parse_record’:
ihex.c:104:15: error: redeclaration of ‘i’ with no linkage
   for (size_t i = 0; i < rec.count; i++) {
               ^
ihex.c:68:10: note: previous declaration of ‘i’ was here
   size_t i;
          ^
ihex.c:104:3: error: ‘for’ loop initial declarations are only allowed in C99 or C11 mode
   for (size_t i = 0; i < rec.count; i++) {
   ^
ihex.c:104:3: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code
<builtin>: recipe for target 'ihex.o' failed

Indeed the code uses C constructs that are only available in more recent C standards, but does not announce that to the compiler. I also notice that optimization is turned off which doesn't make much sense to me. I changed the Makefile like so:

diff --git a/Makefile b/Makefile
index b3807b4..d9744ff 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,7 @@ CC=gcc
 #CC=clang

 # Compiler options
-CFLAGS = -g -O0 -Wall -DSHARE_INSTDIR="\"$(SHARE_INSTDIR)\""
+CFLAGS = -g -O2 -std=gnu99 -Wall -DSHARE_INSTDIR="\"$(SHARE_INSTDIR)\""

 # Normally minipro is installed to /usr/local.  If you want to put it
 # somewhere else, define that location here.

Now the program builds (with some warnings though) and works for me (tested reading/writing an ATTiny45). Please consider modifying the Makefile accordingly.

PS: my build environment is Debian 8.11, gcc is version 4.9.2 (Debian 4.9.2-10+deb8u2)

DavidGriffith commented 3 years ago

In GitLab by @radiomanV on Nov 22, 2020, 16:40

The earlier version of gcc will throw an error if we use constructs like for(int i = 0...) and the standard is not specified.

Sometimes i tend to use this kind of construction because of c#. I should replace these couples of lines with this kind of construction instead of forcing a C standard. As for the GCC optimization level perhaps we should change it indeed.

DavidGriffith commented 2 years ago

In GitLab by @Franck78 on Jul 30, 2022, 08:31

Hello radioman

On my old but not so old opensuse, gcc version 4.8.5 (SUSE Linux) out of the git make:

ihex.c:104:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
srec.c:135:5: error: ‘for’ loop initial declarations are only allowed in C99 mode

tl866iiplus.c:609:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:617:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:641:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:733:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:928:3: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:1027:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:1031:5: error: ‘for’ loop initial declarations are only allowed in C99 mode
tl866iiplus.c:1033:7: error: ‘for’ loop initial declarations are only allowed in C99 mode

database.c:588:5: warning: missing braces around initializer [-Wmissing-braces]

retry with -std=c99

jedec.c:55:3: warning: implicit declaration of function ‘strncasecmp’ [-Wimplicit-function-declaration]
minipro.c:193:5: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
tl866a.c:514:5: warning: implicit declaration of function ‘usleep’ [-Wimplicit-function-declaration]
tl866iiplus.c:544:3: error: unknown type name ‘off_t’

retry with -std=gnu99, no errors , some warnings.

Strange you do not have any warnings.