Makefile: make NO_ICONV really mean "no iconv"

The Makefile tweak NO_ICONV is meant to allow Git to be built without iconv in case iconv is not installed or is otherwise dysfunctional. However, NO_ICONV's disabling of iconv is incomplete and can incorrectly allow "-liconv" to slip into the linker flags when NEEDS_LIBICONV is defined, which breaks the build when iconv is not installed. On some platforms, iconv lives directly in libc, whereas, on others it resides in libiconv. For the latter case, NEEDS_LIBICONV instructs the Makefile to add "-liconv" to the linker flags. config.mak.uname automatically defines NEEDS_LIBICONV for platforms which require it. The adding of "-liconv" is done unconditionally, despite NO_ICONV. Work around this problem by making NO_ICONV take precedence over NEEDS_LIBICONV. Reported by: Mahmoud Al-Qudsi <mqudsi@neosmart.net> Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jun 14, 2018 at 22:25 UTC fdb1fbbc7d313253ca9fac5b0be3d0573dcb5419
1 file changed +12 -10
Makefile
+12 -10
@@ -1288,17 +1288,19 @@ ifdef APPLE_COMMON_CRYPTO
1288 LIB_4_CRYPTO += -framework Security -framework CoreFoundation
1289 endif
1290 endif
1291 -ifdef NEEDS_LIBICONV
1292 - ifdef ICONVDIR
1293 - BASIC_CFLAGS += -I$(ICONVDIR)/include
1294 - ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
1295 - else
1296 - ICONV_LINK =
1297 - endif
1298 - ifdef NEEDS_LIBINTL_BEFORE_LIBICONV
1299 - ICONV_LINK += -lintl
1291 +ifndef NO_ICONV
1292 + ifdef NEEDS_LIBICONV
1293 + ifdef ICONVDIR
1294 + BASIC_CFLAGS += -I$(ICONVDIR)/include
1295 + ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
1296 + else
1297 + ICONV_LINK =
1298 + endif
1299 + ifdef NEEDS_LIBINTL_BEFORE_LIBICONV
1300 + ICONV_LINK += -lintl
1301 + endif
1302 + EXTLIBS += $(ICONV_LINK) -liconv
1303 endif
1301 - EXTLIBS += $(ICONV_LINK) -liconv
1304 endif
1305 ifdef NEEDS_LIBGEN
1306 EXTLIBS += -lgen