Opened 5 years ago

Closed 5 years ago

Last modified 4 years ago

#18301 closed defect (fixed)

ncurses fails to build with GCC 5.x

Reported by: leif Owned by: leif
Priority: critical Milestone: sage-6.7
Component: packages: standard Keywords: syntax error, cpp
Cc: jpflori, vbraun Merged in:
Authors: Leif Leonhardy Reviewers: Jean-Pierre Flori
Report Upstream: N/A Work issues:
Branch: 2201c9c (Commits) Commit:
Dependencies: Stopgaps:

Description (last modified by chapoton)

...
gcc-5.1 -DHAVE_CONFIG_H -I../ncurses -I../../ncurses -I. -I../include -I../../ncurses/../include -I/foo/sage-6.6-gcc-5.1.0/local/include  -D_GNU_SOURCE -DNDEBUG -O2 --param max-inline-insns-single=1200 -fPIC -c ../ncurses/lib_gen.c -o ../obj_s/lib_gen.o
In file included from ../../ncurses/curses.priv.h:321:0,
                 from ../ncurses/lib_gen.c:19:
_3081.c:837:15: error: expected ')' before 'int'
../include/curses.h:1622:56: note: in definition of macro 'mouse_trafo'
 #define mouse_trafo(y,x,to_screen) wmouse_trafo(stdscr,y,x,to_screen)
                                                        ^
Makefile:1323: recipe for target '../obj_s/lib_gen.o' failed
make[1]: *** [../obj_s/lib_gen.o] Error 1
make[1]: Leaving directory '/tmp/sage-build-tmp/ncurses-5.9.20131221/src/narrow/ncurses'
Makefile:111: recipe for target 'all' failed
make: *** [all] Error 2
Error building ncurses (narrow).

(build/pkgs/ncurses/patches/ncurses-5.9.20131221_work_around_broken_GNU_cpp_5.x.patch, self-explanatory:)

  • ncurses-5.9.20131221/ncurses/base/MKlib_gen.sh

    Building ncurses with GCC 5.1 (or more precisely, with its 'cpp') fails with
    a syntax error, caused by earlier preprocessing.
    
    (I'm not entirely sure whether it's a GCC bug or rather caused by a new
    feature which breaks further processing with 'awk' and 'sed';  I *think*
    at least the 'awk' inline script "AW2" simply isn't prepared for the changed
    output of 'cpp' w.r.t. line directives [1].  Anyway, the patch fixes the issue.)
    
    [1] https://gcc.gnu.org/gcc-5/porting_to.html
    
    
     
    6262if test "${LC_CTYPE+set}"    = set; then LC_CTYPE=C;    export LC_CTYPE;    fi
    6363if test "${LC_COLLATE+set}"  = set; then LC_COLLATE=C;  export LC_COLLATE;  fi
    6464
    65 preprocessor="$1 -DNCURSES_INTERNALS -I../include"
     65# Work around "unexpected" output of GCC 5.1.0's cpp w.r.t. #line directives
     66# by simply suppressing them:
     67case `$1 -dumpversion 2>/dev/null` in
     68    5.[01].*)  # assume a "broken" one
     69        preprocessor="$1 -P -DNCURSES_INTERNALS -I../include"
     70        ;;
     71    *)
     72        preprocessor="$1 -DNCURSES_INTERNALS -I../include"
     73esac
    6674AWK="$2"
    6775USE="$3"
    6876

Change History (16)

comment:1 Changed 5 years ago by leif

Haven't checked whether or how upstream already deals with this (probably even by adding -P unconditionally).

Perhaps J-P wants to... :P

comment:2 Changed 5 years ago by leif

  • Branch set to u/leif/ncurses_GCC_5.x
  • Commit set to 2201c9cedee5a935dae2c24fdc54a5aa09201bda
  • Status changed from new to needs_review

New commits:

2201c9cAdd patch to let ncurses build with GCC 5.x (changed output of 'cpp')

comment:3 Changed 5 years ago by leif

  • Cc vbraun added

Meanwhile found an upstream patch for the issue (not yet part of a "stable" release):

  • ncurses/base/MKlib_gen.sh

    old new  
    22#
    33# MKlib_gen.sh -- generate sources from curses.h macro definitions
    44#
    5 # ($Id: MKlib_gen.sh,v 1.46 2011/06/04 19:14:08 tom Exp $)
     5# ($Id: MKlib_gen.sh,v 1.47 2014/12/06 18:56:25 tom Exp $)
    66#
    77##############################################################################
    8 # Copyright (c) 1998-2010,2011 Free Software Foundation, Inc.                #
     8# Copyright (c) 1998-2011,2014 Free Software Foundation, Inc.                #
    99#                                                                            #
    1010# Permission is hereby granted, free of charge, to any person obtaining a    #
    1111# copy of this software and associated documentation files (the "Software"), #
     
    474474        -e 's/gen_$//' \
    475475        -e 's/  / /g' >>$TMP
    476476
     477cat >$ED1 <<EOF
     478s/  / /g
     479s/^ //
     480s/ $//
     481s/P_NCURSES_BOOL/NCURSES_BOOL/g
     482EOF
     483
     484# A patch discussed here:
     485#       https://gcc.gnu.org/ml/gcc-patches/2014-06/msg02185.html
     486# introduces spurious #line markers.  Work around that by ignoring the system's
     487# attempt to define "bool" and using our own symbol here.
     488sed -e 's/bool/P_NCURSES_BOOL/g' $TMP > $ED2
     489cat $ED2 >$TMP
     490
    477491$preprocessor $TMP 2>/dev/null \
    478 | sed \
    479         -e 's/  / /g' \
    480         -e 's/^ //' \
    481         -e 's/_Bool/NCURSES_BOOL/g' \
     492| sed -f $ED1 \
    482493| $AWK -f $AW2 \
    483494| sed -f $ED3 \
    484495| sed \

Still think my solution is a bit more robust (and easier to follow ;-) ). (Haven't actually tried upstream's fix.)


Cc'ing the spkg maintainer...

comment:4 Changed 5 years ago by leif

P.S.: Doesn't look like that single upstream patch alone would suffice, we'd presumably have to include more (but our package is already patched).

I'm not really keen to figure out which other parts we may need, and whether those may in turn break other things.

comment:5 follow-up: Changed 5 years ago by fbissey

Well the corresponding gentoo bug is https://bugs.gentoo.org/show_bug.cgi?id=545114 since the same dev opened and closed it, I would say they very much have tested upstream patch.

I'll have to say I like yours better, it feels more comprehensible. But upstream will probably stick to its own fix.

Current version of ncurses in sage is a dev version from upstream (available at ftp://invisible-island.net/ncurses/current/ the one we have is old enough to be off the list) may be we should just upgrade to one of the latest dev version? Jean-Pierre Flori did the last upgrade may be he has an opinion on the process?

comment:6 Changed 5 years ago by fbissey

Well using ncurses-5.9-20150425 got me through. I had to remove the patch for ncurses included in sage. The first part about aclocal.m4 applied with fuzz, but the second part about configure was rejected as appearing to be a reverse patch. I take that as a news that the patch in question is no longer necessary.

I'll report back about whether or not that upgrade breaks any parts of sage.

comment:7 in reply to: ↑ 5 Changed 5 years ago by leif

Replying to fbissey:

Current version of ncurses in sage is a dev version from upstream (available at ftp://invisible-island.net/ncurses/current/ the one we have is old enough to be off the list) may be we should just upgrade to one of the latest dev version?

Well, that's the problem. Last time J-P had to add a patch again because something got borked again which was fixed in the previous version, and I cannot (and don't want to) test on various platforms, with various compilers or setups.

(The diff above is btw. from the latest devel version, but only for that file, which got fixed in an earlier version.)

comment:8 Changed 5 years ago by leif

I'd rather upgrade on another (less important) ticket, i.e., get some working fix into Sage quickly, without risking other issues or endless review.

comment:9 Changed 5 years ago by jpflori

I agree, let's update in a follow up ticket.

And I fear the XOPEN_SOURCE thing if still present is still broken on some archs. The patch surely does not apply anymore because configure was regenerated...

comment:10 Changed 5 years ago by jpflori

  • Reviewers set to Jean-Pierre Flori
  • Status changed from needs_review to positive_review

comment:11 Changed 5 years ago by jpflori

And yes we should upgrade asap as well if possible.

comment:12 Changed 5 years ago by leif

Thanks.

Where did you have the XOPEN_SOURCE problems?

I currently cannot test on anything but Linux x86/x86_64 (skynet and bsd.math, RIP), so I didn't even try to upgrade.

comment:13 Changed 5 years ago by jpflori

The XOPEN_SOURCE problem was on Solaris... See http://trac.sagemath.org/ticket/15268#comment:10 and #15796 for some info.

Note sure what is in latest upstream right now... See http://invisible-island.net/ncurses/NEWS.html#index-t20131116 and http://invisible-island.net/ncurses/NEWS.html#index-t20140209 and http://invisible-island.net/ncurses/NEWS.html#index-t20150221 for some recent changes, especially the second one. I'd say the patch is not needed anymore, but we'll have to check the source or test on Solaris.

comment:14 Changed 5 years ago by vbraun

  • Branch changed from u/leif/ncurses_GCC_5.x to 2201c9cedee5a935dae2c24fdc54a5aa09201bda
  • Resolution set to fixed
  • Status changed from positive_review to closed

comment:15 Changed 4 years ago by saraedum

  • Commit 2201c9cedee5a935dae2c24fdc54a5aa09201bda deleted

This is still an issue with GCC 5.2.0. See #18977.

comment:16 Changed 4 years ago by chapoton

  • Description modified (diff)
Note: See TracTickets for help on using tickets.