OSGeo / libgeotiff

Official repository of the libgeotiff project
180 stars 69 forks source link

Local-directory -I flags mis-passed in Makefile.am #52

Open dmacks opened 3 years ago

dmacks commented 3 years ago

Building libgeotiff-1.6.0 on OS X 10.13:

$ CPPFLAGS=-I/sw/include LDFLAGS=-L/sw/lib ./configure --prefix=/sw --with-zip=/usr/include --with-jpeg=/sw --disable-doxygen-doc
[...]
  zlib support......: yes
  jpeg support......: yes
  TIFF support......: yes
    -INCLUDE .......: -I/sw/include
    -PREFIX ........: 
  PROJ support......: yes
    -INCLUDE .......: 
  LIBS.....................: -L/sw/lib -ljpeg -lz -lm -L/sw/lib  -L/sw/lib -ltiff -L/sw/lib -lproj
$ make
[...]
make[2]: Entering directory '/sw/build.build/libgeotiff5-1.6.0-1/libgeotiff-1.6.0/bin'
gcc -DHAVE_CONFIG_H -I. -I..   -Os -I/sw/include -I../  -I./.. -I./../libxtiff -I/sw/include -DHAVE_TIFF=1  -g -O2 -O3 -DNDEBUG -MT geotifcp.o -MD -MP -MF .deps/geotifcp.Tpo -c -o geotifcp.o geotifcp.c
[...]
/bin/sh ../libtool  --tag=CC   --mode=link gcc -I../  -I./.. -I./../libxtiff -I/sw/include -DHAVE_TIFF=1  -g -O2 -O3 -DNDEBUG  -L/sw/lib -o geotifcp geotifcp.o ../libgeotiff.la -L/sw/lib -ljpeg -lz -lm -L/sw/lib  -L/sw/lib -ltiff -L/sw/lib -lproj

The weird is that there are -I flags going to the linker. The bug is "-I/sw/include -I../ -I./.. -O../../libxtiff", which causes build failure because externally installed headers will be found in preference to ones in the source distro. Local -I should always come before any global/external ones. The same thing happens for all compiling in bin/ and the top-level dir.

All of this is because Makefile.am are passing local -I via AM_CFLAGS instead of AM_CPPFLAGS. "CFLAGS" is the "C compiler" (.c→.o and linking), whereas "CPPFLAGS" is "the →.o stage".