Curses detection in adk/config/Makefile is a mess - pkg-config was
designed to avoid exactly that, so make it a required tool on all host
OSs and use it to define the required curses LIBS and CFLAGS from
prereq.sh.
Since pkg-config output also contains the right arguments for libtinfo
(which depends on the chosen curses variant), no mismatches between the
two may happen anymore.
---
adk/config/Makefile | 51 ++-------------------------------------------
scripts/prereq.sh | 35 +++++++++++++++++++++----------
2 files changed, 26 insertions(+), 60 deletions(-)
diff --git a/adk/config/Makefile b/adk/config/Makefile
index 480c314474036..a328fbf59a5d9 100644
--- a/adk/config/Makefile
+++ b/adk/config/Makefile
@@ -8,58 +8,11 @@ include ${ADK_TOPDIR}/rules.mk
endif
CP=cp -fpR
-HOST_CFLAGS+=-DKBUILD_NO_NLS -w
+HOST_CFLAGS+= -DKBUILD_NO_NLS -w ${CURSES_CFLAGS}
+LIBS= ${CURSES_LIBS}
all: ncurses conf mconf
-LIBS=
-ifeq (/usr/lib/libtinfo.so, $(wildcard /usr/lib/libtinfo.so))
-LIBS= -ltinfo
-endif
-
-ifeq (/usr/include/ncursesw/curses.h, $(wildcard /usr/include/ncursesw/curses.h))
-HOST_CFLAGS+= -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"
-LIBS+= -lncursesw
-else
-ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
-HOST_CFLAGS+= -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
-HOST_CFLAGS+= -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
-HOST_CFLAGS+= -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/include/ncurses/ncurses.h, $(wildcard
/usr/local/include/ncurses/ncurses.h))
-HOST_CFLAGS+= -I/usr/local/include/ncurses -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/include/ncurses/curses.h, $(wildcard
/usr/local/include/ncurses/curses.h))
-HOST_CFLAGS+= -I/usr/local/include/ncurses
-DCURSES_LOC="<ncurses/curses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/opt/ncurses/include/ncursesw/ncurses.h, $(wildcard
/usr/local/opt/ncurses/include/ncursesw/ncurses.h))
-HOST_CFLAGS+= -I/usr/local/opt/ncurses/include
-DCURSES_LOC="<ncursesw/ncurses.h>"
-LIBS+= -L/usr/local/opt/ncurses/lib -Wl,-rpath -Wl,/usr/local/opt/ncurses/lib
-lncursesw
-else
-ifeq (/usr/pkg/include/ncurses.h, $(wildcard /usr/pkg/include/ncurses.h))
-HOST_CFLAGS+= -I/usr/pkg/include -DCURSES_LOC="<ncurses.h>"
-LIBS+= -L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib -lncurses
-else
-HOST_CFLAGS+= -DCURSES_LOC="<curses.h>"
-LIBS= -lcurses
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
CONF_SRC =conf.c
MCONF_SRC =mconf.c $(wildcard lxdialog/*.c)
SHARED_SRC=zconf.tab.c
diff --git a/scripts/prereq.sh b/scripts/prereq.sh
index b71adaac19e9e..356ad65ecbfa4 100755
--- a/scripts/prereq.sh
+++ b/scripts/prereq.sh
@@ -304,6 +304,28 @@ if ! which git >/dev/null 2>&1; then
fi
printf "found\n"
+printf " ---> checking if pkg-config is installed.. "
+if ! which pkg-config >/dev/null 2>&1; then
+ printf "not found\n"
+ out=1
+else
+ printf "found\n"
+fi
+
+printf " ---> checking if ncurses is installed.. "
+curses=""
+for curse in ncursesw ncurses curses; do
+ pkg-config --exists $curse || continue
+ curses=$curse
+ printf "found $curse\n"
+ CURSES_LIBS=$(pkg-config --libs $curse)
+ CURSES_CFLAGS=$(pkg-config --cflags $curse)
+ break
+done
+if [ -z "$curses" ]; then
+ printf "not found\n"
+ out=1
+fi
# creating prereq.mk
echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" >
$topdir/prereq.mk
@@ -327,6 +349,8 @@ echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
-e 's/mipsel-.*/mipsel/' \
-e 's/i[3-9]86/x86/' \
)" >>prereq.mk
+echo "CURSES_LIBS:=${CURSES_LIBS}" >> $topdir/prereq.mk
+echo "CURSES_CFLAGS:=${CURSES_CFLAGS}" >> $topdir/prereq.mk
if [ "$CC" = "clang" ]; then
echo "HOST_CC:=${CC} -fbracket-depth=1024" >> $topdir/prereq.mk
@@ -423,17 +447,6 @@ fi
rm test.c test 2>/dev/null
rm Makefile.tmp 2>/dev/null
-# for make kernelconfig pkg-config is required to find ncurses
-if [ $os = "Darwin" ]; then
- printf " ---> checking if pkg-config is installed.. "
- if ! which pkg-config >/dev/null 2>&1; then
- printf "not found\n"
- out=1
- else
- printf "found\n"
- fi
-fi
-
# error out on any required prerequisite
if [ $out -ne 0 ]; then
exit
--
2.30.0
Show replies by date
Curses detection in adk/config/Makefile is a mess - pkg-config was
designed to avoid exactly that, so make it a required tool on all host
OSs and call check-lxdialog.sh from mconf sources which uses it to
define the required curses LIBS and CFLAGS from prereq.sh.
Since pkg-config output also contains the right arguments for libtinfo
(which depends on the chosen curses variant), no mismatches between the
two may happen anymore.
While being at it, sync check-lxdialog.sh with current linux sources so
it covers installations with widechar support as well.
Signed-off-by: Phil Sutter <phil(a)nwl.cc>
---
Changes since v1:
- Original Implementation in prereq.sh was broken, CURSES_LOC define was
not added to CFLAGS.
- Make use of check-lxdialog.sh just like linux sources do to complete
the same task.
---
adk/config/Makefile | 51 ++-------------------------
adk/config/lxdialog/check-lxdialog.sh | 17 ++++++---
scripts/prereq.sh | 31 ++++++++++------
3 files changed, 35 insertions(+), 64 deletions(-)
diff --git a/adk/config/Makefile b/adk/config/Makefile
index 480c314474036..a328fbf59a5d9 100644
--- a/adk/config/Makefile
+++ b/adk/config/Makefile
@@ -8,58 +8,11 @@ include ${ADK_TOPDIR}/rules.mk
endif
CP=cp -fpR
-HOST_CFLAGS+=-DKBUILD_NO_NLS -w
+HOST_CFLAGS+= -DKBUILD_NO_NLS -w ${CURSES_CFLAGS}
+LIBS= ${CURSES_LIBS}
all: ncurses conf mconf
-LIBS=
-ifeq (/usr/lib/libtinfo.so, $(wildcard /usr/lib/libtinfo.so))
-LIBS= -ltinfo
-endif
-
-ifeq (/usr/include/ncursesw/curses.h, $(wildcard /usr/include/ncursesw/curses.h))
-HOST_CFLAGS+= -I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"
-LIBS+= -lncursesw
-else
-ifeq (/usr/include/ncurses/ncurses.h, $(wildcard /usr/include/ncurses/ncurses.h))
-HOST_CFLAGS+= -I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/include/ncurses/curses.h, $(wildcard /usr/include/ncurses/curses.h))
-HOST_CFLAGS+= -I/usr/include/ncurses -DCURSES_LOC="<ncurses/curses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/include/ncurses.h, $(wildcard /usr/include/ncurses.h))
-HOST_CFLAGS+= -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/include/ncurses/ncurses.h, $(wildcard
/usr/local/include/ncurses/ncurses.h))
-HOST_CFLAGS+= -I/usr/local/include/ncurses -DCURSES_LOC="<ncurses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/include/ncurses/curses.h, $(wildcard
/usr/local/include/ncurses/curses.h))
-HOST_CFLAGS+= -I/usr/local/include/ncurses
-DCURSES_LOC="<ncurses/curses.h>"
-LIBS+= -lncurses
-else
-ifeq (/usr/local/opt/ncurses/include/ncursesw/ncurses.h, $(wildcard
/usr/local/opt/ncurses/include/ncursesw/ncurses.h))
-HOST_CFLAGS+= -I/usr/local/opt/ncurses/include
-DCURSES_LOC="<ncursesw/ncurses.h>"
-LIBS+= -L/usr/local/opt/ncurses/lib -Wl,-rpath -Wl,/usr/local/opt/ncurses/lib
-lncursesw
-else
-ifeq (/usr/pkg/include/ncurses.h, $(wildcard /usr/pkg/include/ncurses.h))
-HOST_CFLAGS+= -I/usr/pkg/include -DCURSES_LOC="<ncurses.h>"
-LIBS+= -L/usr/pkg/lib -Wl,-rpath -Wl,/usr/pkg/lib -lncurses
-else
-HOST_CFLAGS+= -DCURSES_LOC="<curses.h>"
-LIBS= -lcurses
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
CONF_SRC =conf.c
MCONF_SRC =mconf.c $(wildcard lxdialog/*.c)
SHARED_SRC=zconf.tab.c
diff --git a/adk/config/lxdialog/check-lxdialog.sh
b/adk/config/lxdialog/check-lxdialog.sh
index fcef0f59d5539..5075ebf2d3b99 100644
--- a/adk/config/lxdialog/check-lxdialog.sh
+++ b/adk/config/lxdialog/check-lxdialog.sh
@@ -4,7 +4,9 @@
# What library to link
ldflags()
{
- for ext in so a dylib ; do
+ pkg-config --libs ncursesw 2>/dev/null && exit
+ pkg-config --libs ncurses 2>/dev/null && exit
+ for ext in so a dll.a dylib ; do
for lib in ncursesw ncurses curses ; do
$cc -print-file-name=lib${lib}.${ext} | grep -q /
if [ $? -eq 0 ]; then
@@ -19,10 +21,17 @@ ldflags()
# Where is ncurses.h?
ccflags()
{
- if [ -f /usr/include/ncurses/ncurses.h ]; then
+ if pkg-config --cflags ncursesw 2>/dev/null; then
+ echo '-DCURSES_LOC="<ncurses.h>" -DNCURSES_WIDECHAR=1'
+ elif pkg-config --cflags ncurses 2>/dev/null; then
+ echo '-DCURSES_LOC="<ncurses.h>"'
+ elif [ -f /usr/include/ncursesw/curses.h ]; then
+ echo '-I/usr/include/ncursesw -DCURSES_LOC="<curses.h>"'
+ echo ' -DNCURSES_WIDECHAR=1'
+ elif [ -f /usr/include/ncurses/ncurses.h ]; then
echo '-I/usr/include/ncurses -DCURSES_LOC="<ncurses.h>"'
elif [ -f /usr/include/ncurses/curses.h ]; then
- echo '-I/usr/include/ncurses
-DCURSES_LOC="<ncurses/curses.h>"'
+ echo '-I/usr/include/ncurses -DCURSES_LOC="<curses.h>"'
elif [ -f /usr/include/ncurses.h ]; then
echo '-DCURSES_LOC="<ncurses.h>"'
else
@@ -36,7 +45,7 @@ trap "rm -f $tmp" 0 1 2 3 15
# Check if we can link to ncurses
check() {
- $cc -xc - -o $tmp 2>/dev/null <<'EOF'
+ $cc -x c - -o $tmp 2>/dev/null <<'EOF'
#include CURSES_LOC
main() {}
EOF
diff --git a/scripts/prereq.sh b/scripts/prereq.sh
index 8f42a7c604a12..bd0b525d89c27 100755
--- a/scripts/prereq.sh
+++ b/scripts/prereq.sh
@@ -304,6 +304,24 @@ if ! which git >/dev/null 2>&1; then
fi
printf "found\n"
+printf " ---> checking if pkg-config is installed.. "
+if ! which pkg-config >/dev/null 2>&1; then
+ printf "not found\n"
+ out=1
+else
+ printf "found\n"
+fi
+
+printf " ---> checking if ncurses is installed.. "
+check_lxdialog=${topdir}/adk/config/lxdialog/check-lxdialog.sh
+CURSES_CFLAGS=$(/bin/sh ${check_lxdialog} -ccflags | tr '\n' ' ')
+CURSES_LIBS=$(/bin/sh ${check_lxdialog} -ldflags ${CC})
+if [ $? -eq 0 ]; then
+ printf "found\n"
+else
+ printf "not found\n"
+ out=1
+fi
# creating prereq.mk
echo "ADK_TOPDIR:=$(readlink -nf . 2>/dev/null || pwd -P)" >
$topdir/prereq.mk
@@ -327,6 +345,8 @@ echo "ARCH_FOR_BUILD:=$(${CC} -dumpmachine | sed \
-e 's/mipsel-.*/mipsel/' \
-e 's/i[3-9]86/x86/' \
)" >>prereq.mk
+echo "CURSES_LIBS:=${CURSES_LIBS}" >> $topdir/prereq.mk
+echo "CURSES_CFLAGS:=${CURSES_CFLAGS}" >> $topdir/prereq.mk
if [ "$CC" = "clang" ]; then
echo "HOST_CC:=${CC} -fbracket-depth=1024" >> $topdir/prereq.mk
@@ -423,17 +443,6 @@ fi
rm test.c test 2>/dev/null
rm Makefile.tmp 2>/dev/null
-# for make kernelconfig pkg-config is required to find ncurses
-if [ $os = "Darwin" ]; then
- printf " ---> checking if pkg-config is installed.. "
- if ! which pkg-config >/dev/null 2>&1; then
- printf "not found\n"
- out=1
- else
- printf "found\n"
- fi
-fi
-
# error out on any required prerequisite
if [ $out -ne 0 ]; then
exit
--
2.30.1