Opened 7 years ago

Closed 7 years ago

Last modified 7 years ago

#18301 closed defect (fixed)

ncurses fails to build with GCC 5.x

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

Status badges

Description (last modified by Frédéric 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/

    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.)
    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
    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"

Change History (16)

comment:1 Changed 7 years ago by Leif Leonhardy

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 7 years ago by Leif Leonhardy

Branch: u/leif/ncurses_GCC_5.x
Commit: 2201c9cedee5a935dae2c24fdc54a5aa09201bda
Status: newneeds_review

New commits:

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

comment:3 Changed 7 years ago by Leif Leonhardy

Cc: Volker Braun added

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

  • ncurses/base/

    old new  
    33# -- generate sources from curses.h macro definitions
    5 # ($Id:,v 1.46 2011/06/04 19:14:08 tom Exp $)
     5# ($Id:,v 1.47 2014/12/06 18:56:25 tom Exp $)
    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
     477cat >$ED1 <<EOF
     478s/  / /g
     479s/^ //
     480s/ $//
     484# A patch discussed here:
     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
    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 7 years ago by Leif Leonhardy

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 Changed 7 years ago by François Bissey

Well the corresponding gentoo bug is 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 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 7 years ago by François Bissey

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 7 years ago by Leif Leonhardy

Replying to fbissey:

Current version of ncurses in sage is a dev version from upstream (available at 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 7 years ago by Leif Leonhardy

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 7 years ago by Jean-Pierre Flori

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 7 years ago by Jean-Pierre Flori

Reviewers: Jean-Pierre Flori
Status: needs_reviewpositive_review

comment:11 Changed 7 years ago by Jean-Pierre Flori

And yes we should upgrade asap as well if possible.

comment:12 Changed 7 years ago by Leif Leonhardy


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 7 years ago by Jean-Pierre Flori

The XOPEN_SOURCE problem was on Solaris... See and #15796 for some info.

Note sure what is in latest upstream right now... See and and 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 7 years ago by Volker Braun

Branch: u/leif/ncurses_GCC_5.x2201c9cedee5a935dae2c24fdc54a5aa09201bda
Resolution: fixed
Status: positive_reviewclosed

comment:15 Changed 7 years ago by Julian Rüth

Commit: 2201c9cedee5a935dae2c24fdc54a5aa09201bda

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

comment:16 Changed 7 years ago by Frédéric Chapoton

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