public inbox for util-linux@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] clean up term lib handling
@ 2013-09-29  4:44 Mike Frysinger
  2013-09-30 13:07 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Frysinger @ 2013-09-29  4:44 UTC (permalink / raw)
  To: util-linux

The ncurses package has been providing pkg-config files for a while now.
So let's start using them to get the proper linker & compiler flags.  It
can make a difference when ncurses is configured in a way that requires
extra link time flags but util-linux doesn't provide them, or when the
headers live in a weird place and util-linux can't find them.

Since the NCURSES_LIBS is always defined for the Makefile, there's no need
to gate on the HAVE_NCURSES conditional.  When it's disabled, the var will
simply be empty.

With a minor tweak to how tinfo is handled, we can do the same thing -- we
just always use TINFO_LIBS in the Makefile's.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
---
 configure.ac             | 53 ++++++++++++++++++++++++++++++++++++------------
 fdisks/Makemodule.am     |  7 +++----
 misc-utils/Makemodule.am | 12 ++---------
 term-utils/Makemodule.am |  7 ++-----
 text-utils/Makemodule.am | 27 +++++++-----------------
 5 files changed, 54 insertions(+), 52 deletions(-)

diff --git a/configure.ac b/configure.ac
index 553228a..db828ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -595,25 +595,50 @@ AM_CONDITIONAL([HAVE_NCURSES], [false])
 
 AS_IF([test "x$with_ncurses" != xno], [
   have_ncurses=no
-  AC_CHECK_HEADERS([ncurses.h ncurses/ncurses.h], [
-    AS_IF([test "x$with_ncurses" = xauto], [
-      UL_CHECK_LIB([ncursesw], [initscr], [ncurses])
-      AS_IF([test "x$have_ncurses" = xyes], [
-	AC_CHECK_HEADERS([ncursesw/ncurses.h])
-	NCURSES_LIBS="-lncursesw"
+
+  dnl First try to find the pkg-config module.
+  PKG_CHECK_MODULES(NCURSESW, [ncursesw], [
+    have_ncurses=yes
+    NCURSES_LIBS=${NCURSESW_LIBS}
+    NCURSES_CFLAGS=${NCURSESW_CFLAGS}
+    AC_DEFINE([HAVE_LIBNCURSESW])
+  ], [
+    PKG_CHECK_MODULES(NCURSES, [ncurses], [
+      have_ncurses=yes
+      AC_DEFINE([HAVE_LIBNCURSES])
+    ], [:])
+  ])
+
+  AS_IF([test "x$have_ncurses" = xyes], [
+    dnl If that worked, setup the defines that the code expects.
+    save_CPPFLAGS="$CPPFLAGS"
+    CPPFLAGS="$CPPFLAGS $NCURSES_CFLAGS"
+    AC_CHECK_HEADERS([ncurses.h])
+    CPPFLAGS="$save_CPPFLAGS"
+  ], [
+    dnl If that failed, fall back to classic searching.
+    AC_CHECK_HEADERS([ncurses.h ncurses/ncurses.h], [
+      AS_IF([test "x$with_ncurses" = xauto], [
+	UL_CHECK_LIB([ncursesw], [initscr], [ncurses])
+	AS_IF([test "x$have_ncurses" = xyes], [
+	  AC_CHECK_HEADERS([ncursesw/ncurses.h])
+	  NCURSES_LIBS="-lncursesw"
+	])
       ])
-    ])
-    AS_IF([test "x$have_ncurses" = xno], [
-      UL_CHECK_LIB(ncurses, initscr)
-      AS_IF([test "x$have_ncurses" = xyes], [
-	NCURSES_LIBS="-lncurses"
+      AS_IF([test "x$have_ncurses" = xno], [
+	UL_CHECK_LIB(ncurses, initscr)
+	AS_IF([test "x$have_ncurses" = xyes], [
+	  NCURSES_LIBS="-lncurses"
+	])
       ])
     ])
   ])
+
   AS_IF([test "x$have_ncurses" = xno], [
     AC_MSG_ERROR([ncurses or ncursesw selected, but library not found (--without-ncurses to disable)])
   ])
 ])
+AC_SUBST([NCURSES_CFLAGS])
 AC_SUBST([NCURSES_LIBS])
 
 
@@ -642,9 +667,11 @@ AM_CONDITIONAL([HAVE_SLANG], [test "x$have_slang" = xyes])
 AM_CONDITIONAL([BUILD_CFDISK], [test "x$have_slang" = xyes -o "x$have_ncurses" = xyes])
 
 
-have_tinfo=no
 AC_CHECK_LIB([tinfo], [tgetent], [have_tinfo=yes])
-AM_CONDITIONAL([HAVE_TINFO], [test "x$have_tinfo" = xyes])
+AS_IF([test "x$have_tinfo" = xyes], [
+  TINFO_LIBS="-ltinfo"
+])
+AC_SUBST([TINFO_LIBS])
 
 
 AC_ARG_WITH([utempter],
diff --git a/fdisks/Makemodule.am b/fdisks/Makemodule.am
index f2c594c..239e8ae 100644
--- a/fdisks/Makemodule.am
+++ b/fdisks/Makemodule.am
@@ -56,7 +56,7 @@ if BUILD_CFDISK
 sbin_PROGRAMS += cfdisk
 dist_man_MANS += fdisks/cfdisk.8
 cfdisk_SOURCES = fdisks/cfdisk.c
-cfdisk_CFLAGS =
+cfdisk_CFLAGS = $(AM_CFLAGS)
 cfdisk_LDADD = $(LDADD) libcommon.la
 
 if BUILD_LIBBLKID
@@ -67,9 +67,8 @@ endif
 if HAVE_SLANG
 cfdisk_LDADD += -lslang
 else
-if HAVE_NCURSES
-cfdisk_LDADD += @NCURSES_LIBS@
-endif
+cfdisk_CFLAGS += $(NCURSES_CFLAGS)
+cfdisk_LDADD += $(NCURSES_LIBS)
 endif
 endif # BUILD_CFDISK
 
diff --git a/misc-utils/Makemodule.am b/misc-utils/Makemodule.am
index fcfec7b..70bb339 100644
--- a/misc-utils/Makemodule.am
+++ b/misc-utils/Makemodule.am
@@ -10,19 +10,11 @@ if !HAVE_LANGINFO
 cal_SOURCES += lib/langinfo.c
 endif
 
-cal_LDADD = $(LDADD) libcommon.la
-
-if HAVE_TINFO
-cal_LDADD += -ltinfo @NCURSES_LIBS@
-else
-if HAVE_NCURSES
-cal_LDADD += @NCURSES_LIBS@
-else
+cal_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
+cal_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS) $(TINFO_LIBS)
 if HAVE_TERMCAP
 cal_LDADD += -ltermcap
 endif
-endif # !HAVE_NCURSES
-endif # !HAVE_TINFO
 
 
 usrbin_exec_PROGRAMS += logger
diff --git a/term-utils/Makemodule.am b/term-utils/Makemodule.am
index 4709873..b1c28f2 100644
--- a/term-utils/Makemodule.am
+++ b/term-utils/Makemodule.am
@@ -28,11 +28,8 @@ if BUILD_SETTERM
 usrbin_exec_PROGRAMS += setterm
 dist_man_MANS += term-utils/setterm.1
 setterm_SOURCES = term-utils/setterm.c
-if HAVE_TINFO
-setterm_LDADD = $(LDADD) -ltinfo
-else
-setterm_LDADD = $(LDADD) @NCURSES_LIBS@
-endif
+setterm_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
+setterm_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
 endif
 
 
diff --git a/text-utils/Makemodule.am b/text-utils/Makemodule.am
index d3ebfdc..a2b6fe9 100644
--- a/text-utils/Makemodule.am
+++ b/text-utils/Makemodule.am
@@ -53,11 +53,8 @@ if BUILD_PG
 usrbin_exec_PROGRAMS += pg
 dist_man_MANS += text-utils/pg.1
 pg_SOURCES = text-utils/pg.c
-pg_CFLAGS = $(AM_CFLAGS) $(BSD_WARN_CFLAGS)
-pg_LDADD = $(LDADD) libcommon.la @NCURSES_LIBS@
-if HAVE_TINFO
-pg_LDADD += -ltinfo
-endif
+pg_CFLAGS = $(AM_CFLAGS) $(BSD_WARN_CFLAGS) $(NCURSES_CFLAGS)
+pg_LDADD = $(LDADD) libcommon.la $(NCURSES_LIBS) $(TINFO_LIBS)
 endif # BUILD_PG
 
 
@@ -65,12 +62,8 @@ if BUILD_UL
 usrbin_exec_PROGRAMS += ul
 dist_man_MANS += text-utils/ul.1
 ul_SOURCES = text-utils/ul.c
-ul_LDADD = $(LDADD)
-if HAVE_TINFO
-ul_LDADD += -ltinfo
-else 
-ul_LDADD += @NCURSES_LIBS@
-endif
+ul_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
+ul_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
 endif # BUILD_UL
 
 
@@ -78,17 +71,11 @@ if BUILD_MORE
 bin_PROGRAMS += more
 dist_man_MANS += text-utils/more.1
 more_SOURCES = text-utils/more.c
-more_CFLAGS = $(AM_CFLAGS) $(BSD_WARN_CFLAGS)
-more_LDADD = $(LDADD)
-if HAVE_TINFO
-more_LDADD += -ltinfo
-else
-if HAVE_NCURSES
-more_LDADD += @NCURSES_LIBS@
-else
+more_CFLAGS = $(AM_CFLAGS) $(BSD_WARN_CFLAGS) $(NCURSES_CFLAGS)
+more_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
+if HAVE_TERMCAP
 more_LDADD += -ltermcap
 endif
-endif
 
 check_PROGRAMS += test_more
 test_more_SOURCES = $(more_SOURCES)
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] clean up term lib handling
  2013-09-29  4:44 [PATCH] clean up term lib handling Mike Frysinger
@ 2013-09-30 13:07 ` Karel Zak
  2013-10-04 11:35   ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2013-09-30 13:07 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux


 I have applied the patch, but now when play with it I see that

On Sun, Sep 29, 2013 at 12:44:43AM -0400, Mike Frysinger wrote:
> With a minor tweak to how tinfo is handled, we can do the same thing -- we
> just always use TINFO_LIBS in the Makefile's.

you have introduced unnecessary dependence on ncurses for utils where
was "ifdef tinfo *else* ncurses"

>  AC_CHECK_LIB([tinfo], [tgetent], [have_tinfo=yes])
> -AM_CONDITIONAL([HAVE_TINFO], [test "x$have_tinfo" = xyes])
> +AS_IF([test "x$have_tinfo" = xyes], [
> +  TINFO_LIBS="-ltinfo"
> +])
> +AC_SUBST([TINFO_LIBS])

...

> -if HAVE_TINFO
> -setterm_LDADD = $(LDADD) -ltinfo
> -else
> -setterm_LDADD = $(LDADD) @NCURSES_LIBS@
> -endif
> +setterm_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
> +setterm_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
>  endif

...

> -ul_LDADD = $(LDADD)
> -if HAVE_TINFO
> -ul_LDADD += -ltinfo
> -else 
> -ul_LDADD += @NCURSES_LIBS@
> -endif
> +ul_CFLAGS = $(AM_CFLAGS) $(NCURSES_CFLAGS)
> +ul_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
>  endif # BUILD_UL

...

> -if HAVE_TINFO
> -more_LDADD += -ltinfo
> -else
> -if HAVE_NCURSES
> -more_LDADD += @NCURSES_LIBS@
> -else
> +more_CFLAGS = $(AM_CFLAGS) $(BSD_WARN_CFLAGS) $(NCURSES_CFLAGS)
> +more_LDADD = $(LDADD) $(NCURSES_LIBS) $(TINFO_LIBS)
> +if HAVE_TERMCAP
>  more_LDADD += -ltermcap
>  endif
> -endif

 old version:

./more:
	linux-vdso.so.1 =>  (0x00007fff2af9d000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)
./setterm:
	linux-vdso.so.1 =>  (0x00007fff5cd5e000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)
./ul:
	linux-vdso.so.1 =>  (0x00007fffa070b000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)


your version:


./more:
	linux-vdso.so.1 =>  (0x00007ffff21fe000)
	libncursesw.so.5 => /lib64/libncursesw.so.5 (0x0000003e7ba00000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003e77600000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)
./setterm:
	linux-vdso.so.1 =>  (0x00007fff1455b000)
	libncursesw.so.5 => /lib64/libncursesw.so.5 (0x0000003e7ba00000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003e77600000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)
./ul:
	linux-vdso.so.1 =>  (0x00007fff274ee000)
	libncursesw.so.5 => /lib64/libncursesw.so.5 (0x0000003e7ba00000)
	libtinfo.so.5 => /lib64/libtinfo.so.5 (0x0000003e8d200000)
	libc.so.6 => /lib64/libc.so.6 (0x0000003e77200000)
	libdl.so.2 => /lib64/libdl.so.2 (0x0000003e77600000)
	/lib64/ld-linux-x86-64.so.2 (0x0000003e76e00000)


 Maybe we need to revert back to 

   AM_CONDITIONAL([HAVE_TINFO], [test "x$have_tinfo" = xyes])

 or introduce something like $TINFO_OR_CURSES_{LIBS,CFLAGS} to keep 
 the makefiles simple and define the variable in ./configure :-)

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] clean up term lib handling
  2013-09-30 13:07 ` Karel Zak
@ 2013-10-04 11:35   ` Karel Zak
  0 siblings, 0 replies; 3+ messages in thread
From: Karel Zak @ 2013-10-04 11:35 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: util-linux

On Mon, Sep 30, 2013 at 03:07:18PM +0200, Karel Zak wrote:
> 
>  I have applied the patch, but now when play with it I see that
> 
> On Sun, Sep 29, 2013 at 12:44:43AM -0400, Mike Frysinger wrote:
> > With a minor tweak to how tinfo is handled, we can do the same thing -- we
> > just always use TINFO_LIBS in the Makefile's.
> 
> you have introduced unnecessary dependence on ncurses for utils where
> was "ifdef tinfo *else* ncurses"

...

>  Maybe we need to revert back to 
> 
>    AM_CONDITIONAL([HAVE_TINFO], [test "x$have_tinfo" = xyes])

 Done. It also seems that we can use pkg-config for tinfo.

 Please, test the changes in your environment. Thanks!

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-10-04 11:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-29  4:44 [PATCH] clean up term lib handling Mike Frysinger
2013-09-30 13:07 ` Karel Zak
2013-10-04 11:35   ` Karel Zak

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox