Bug 54866

Summary: libgnugetopt incompatibility breaks mjpegtools build
Product: Ports & Packages Reporter: Nate Eldredge <neldredge>
Component: Individual Port(s)Assignee: Michael Johnson <ahze>
Status: Closed FIXED    
Severity: Affects Only Me    
Priority: Normal    
Version: Latest   
Hardware: Any   
OS: Any   

Description Nate Eldredge 2003-07-25 21:30:17 UTC
Seems that libgnugetopt's getopt.h and FreeBSD's unistd.h define
`getopt' slightly differently.  (As far as I can tell, one has
the second arg as `char * const *' while the other has `char * const []'.)

So a C++ program that tries to include both will fail to compile.
This prevents the multimedia/mjpegtools port from building.

This also apparently affected licq; see
http://www.freebsd.org/cgi/query-pr.cgi?pr=54037

It was fixed there by patching the licq makefile; see
http://www.freebsd.org/cgi/cvsweb.cgi/ports/net/licq/Makefile.diff?r1=1.47&r2=1.48

In that pr, dinoex claims that it only happens with gcc33, but I am using
the gcc 3.2.2 that comes with 5.1-RELEASE.

$ gcc -v
Using built-in specs.
Configured with: FreeBSD/i386 system compiler
Thread model: posix
gcc version 3.2.2 [FreeBSD] 20030205 (release)

Fix: 

Don't know.  I'm not sure whether this should be fixed in libmjpegtools,
libgnugetopt or unistd.h.


-- 

Nate Eldredge
neldredge@hmc.edu
How-To-Repeat: Install the libgnugetopt port, then

$ cat > foo.cc
#include <unistd.h>
#include <getopt.h>
^D
$ gcc -c -I /usr/local/include foo.cc
In file included from foo.cc:2:
/usr/local/include/getopt.h:115: declaration of C function `int getopt()'
   conflicts with
/usr/include/unistd.h:377: previous declaration `int getopt(int, char* const*,
   const char*)' here

Or try to build multimedia/libmjpegtools.

===>  Building for mjpegtools-1.6.1
gmake  all-recursive
gmake[1]: Entering directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1'
Making all in utils
gmake[2]: Entering directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/utils'
gmake[3]: Entering directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/utils'
gmake[3]: Nothing to be done for `all-am'.
gmake[3]: Leaving directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/utils'
gmake[2]: Leaving directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/utils'
Making all in lavtools
gmake[2]: Entering directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/lavtools'
source='lav2divx.cpp' object='lav2divx.o' libtool=no \
depfile='.deps/lav2divx.Po' tmpdepfile='.deps/lav2divx.TPo' \
depmode=gcc3 /bin/sh ../depcomp \
c++ -DHAVE_CONFIG_H -I. -I. -I.. -I.. -I/usr/local/include -DG_LOG_DOMAIN=\"lavtools\" -DLAVPLAY_VERSION=\"1.6.1\"    -I/usr/X11R6/include -I /usr/X11R6/include -I../utils -I/usr/local/include/avifile -I/usr/X11R6/include/gtk12 -I/usr/local/include/glib12 -I/usr/local/include -I/usr/X11R6/include   -D_THREAD_SAFE  -O -pipe -mcpu=pentiumpro -c -o lav2divx.o `test -f 'lav2divx.cpp' || echo './'`lav2divx.cpp
In file included from lav2divx.cpp:80:
/usr/local/include/getopt.h:115: declaration of C function `int getopt()'
   conflicts with
/usr/include/unistd.h:377: previous declaration `int getopt(int, char* const*,
   const char*)' here
In file included from libavifile.h:51,
                 from lav2divx.cpp:92:
/usr/local/include/avifile/fourcc.h:4:2: warning: #warning Use #include "avm_fourcc.h" instead
gmake[2]: *** [lav2divx.o] Error 1
gmake[2]: Leaving directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1/lavtools'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/big/ports/multimedia/mjpegtools/work/mjpegtools-1.6.1'
gmake: *** [all] Error 2
*** Error code 2

Stop in /big/ports/multimedia/mjpegtools.
Comment 1 tkato 2003-07-26 06:07:18 UTC
Here is a patch to fix build on -current.


diff -urN /usr/ports/multimedia/mjpegtools/Makefile multimedia/mjpegtools/Makefile
--- /usr/ports/multimedia/mjpegtools/Makefile	Sun Jun 29 08:19:25 2003
+++ multimedia/mjpegtools/Makefile	Sat Jul 26 13:58:32 2003
@@ -18,13 +18,14 @@
 LIB_DEPENDS=	aviplay.0:${PORTSDIR}/multimedia/avifile \
 		jpeg.9:${PORTSDIR}/graphics/jpeg
 
-USE_GNOME=	glib12
+USE_GETOPT_LONG=	yes
+USE_GNOME=	glib12 gnometarget
 USE_GMAKE=	yes
 USE_LIBTOOL=	yes
 USE_REINPLACE=	yes
 USE_XLIB=	yes
 GNU_CONFIGURE=	yes
-CONFIGURE_ENV=  CPPFLAGS="${CPPFLAGS} ${PTHREAD_CFLAGS}" \
+CONFIGURE_ENV=  CPPFLAGS="${CPPFLAGS} -DHAVE_DECL_GETOPT ${PTHREAD_CFLAGS}" \
 		LDFLAGS="${LDFLAGS} ${PTHREAD_LIBS:S/"//g}" \
 		PTHREAD_LIBS="${PTHREAD_LIBS:S/"//g}"
 WANT_GNOME=	yes
@@ -63,11 +64,6 @@
 .if exists(${LOCALBASE}/lib/libdv.so.3)
 WITH_LIBDV=	yes
 .endif
-# LIBGNUGETOPT
-# -CURRENT after 500041 has getopt_long
-.if ${OSVERSION} < 500041
-WITH_LIBGNUGETOPT=	yes
-.endif
 # LIBMOVTAR
 .if exists(${LOCALBASE}/lib/libmovtar.a)
 WITH_LIBMOVTAR=	yes
@@ -95,10 +91,6 @@
 CONFIGURE_ARGS+=	--with-dv=${LOCALBASE}
 .endif
 #
-.ifdef(WITH_LIBGNUGETOPT)
-USE_GETOPT_LONG=	yes
-.endif
-#
 .ifdef(WITH_LIBMOVTAR)
 BUILD_DEPENDS+=	${LOCALBASE}/lib/libmovtar.a:${PORTSDIR}/multimedia/libmovtar
 
@@ -154,6 +146,8 @@
 	@${REINPLACE_CMD} -e 's|SDL/|SDL11/|' \
 		${WRKSRC}/lavtools/liblavplay.c \
 		${WRKSRC}/lavtools/yuvplay.c
+	@${REINPLACE_CMD} -e 's|-Werror||' \
+		${WRKSRC}/yuvdenoise/Makefile.in
 .ifdef(WITH_QUICKTIME)
 	@${REINPLACE_CMD} -E -e 's|^(have_openquicktime=).+$$|\1true|' \
 		${CONFIGURE_WRKSRC}/${CONFIGURE_SCRIPT}
@@ -169,10 +163,6 @@
 .if ${OPSYS:L} == "freebsd"
 	@${REINPLACE_CMD} -E -e 's|^(have_pthread=).+$$|\1true|' \
 		${CONFIGURE_WRKSRC}/${CONFIGURE_SCRIPT}
-.endif
-.ifdef(WITH_LIBGNUGETOPT)
-	@${REINPLACE_CMD} -E -e 's|(AVIPLAY_LIBS \=.*)|\1 -lgnugetopt|' \
-		${WRKSRC}/lavtools/Makefile.in
 .endif
 # link to pthreads
 	@${REINPLACE_CMD} -E -e 's|(AVIPLAY_LIBS \=.*)|\1 ${PTHREAD_LIBS}|' \
diff -urN /usr/ports/multimedia/mjpegtools/files/patch-mplex::multplex.cc multimedia/mjpegtools/files/patch-mplex::multplex.cc
--- /usr/ports/multimedia/mjpegtools/files/patch-mplex::multplex.cc	Thu Jan  1 09:00:00 1970
+++ multimedia/mjpegtools/files/patch-mplex::multplex.cc	Sat Jul 26 13:49:38 2003
@@ -0,0 +1,10 @@
+--- mplex/multplex.cc.orig	Mon Apr 29 23:36:00 2002
++++ mplex/multplex.cc	Sat Jul 26 13:49:13 2003
+@@ -3,6 +3,7 @@
+ #include <math.h>
+ #include <stdlib.h>
+ #include <unistd.h>
++#include <assert.h>
+ 
+ #include <mjpeg_types.h>
+ #include <mjpeg_logging.h>
diff -urN /usr/ports/multimedia/mjpegtools/files/patch-mplex::stillsstream.cc multimedia/mjpegtools/files/patch-mplex::stillsstream.cc
--- /usr/ports/multimedia/mjpegtools/files/patch-mplex::stillsstream.cc	Thu Jan  1 09:00:00 1970
+++ multimedia/mjpegtools/files/patch-mplex::stillsstream.cc	Sat Jul 26 13:53:03 2003
@@ -0,0 +1,10 @@
+--- mplex/stillsstream.cc.orig	Thu Apr 18 13:32:02 2002
++++ mplex/stillsstream.cc	Sat Jul 26 13:52:37 2003
+@@ -21,6 +21,7 @@
+  */
+ 
+ 
++#include <assert.h>
+ #include <format_codes.h>
+ 
+ #include "stillsstream.hh"
diff -urN /usr/ports/multimedia/mjpegtools/files/patch-mplex::systems.cc multimedia/mjpegtools/files/patch-mplex::systems.cc
--- /usr/ports/multimedia/mjpegtools/files/patch-mplex::systems.cc	Thu Jan  1 09:00:00 1970
+++ multimedia/mjpegtools/files/patch-mplex::systems.cc	Sat Jul 26 13:51:38 2003
@@ -0,0 +1,10 @@
+--- mplex/systems.cc.orig	Mon Apr 29 23:36:01 2002
++++ mplex/systems.cc	Sat Jul 26 13:51:19 2003
+@@ -2,6 +2,7 @@
+ #include <stdio.h>
+ #include <stdlib.h>
+ #include <string.h>
++#include <assert.h>
+ #include <sys/param.h>
+ #include <sys/stat.h>
+ #include "systems.hh"
Comment 2 Tilman Keskinoz freebsd_committer freebsd_triage 2003-07-28 09:58:33 UTC
Responsible Changed
From-To: freebsd-ports-bugs->lioux

over to maintainer
Comment 3 Jonathan Lennox 2004-03-30 23:53:38 UTC
This is, indeed, a bug with libgnugetopt.  The version of getopt.h that it
installs in /usr/local/include is incompatible with C++.

Specifically, if HAVE_DECL_GETOPT is not defined, libgnugetopt's
/usr/local/include/getopt.h declares getopt as

   extern int getopt ();

which is fine for C ("function with unknown parameters"), but is broken for
C++ ("function taking zero parameters").

Compare /usr/local/include/getopt.h with /usr/src/contrib/gcc/getopt.h,
which is a more recent version of the same file.  In that version, the
ifdefs are rearranged so that the trivial getopt prototype isn't defined if
__cplusplus.

The solution to this problem, therefore, is to update libgnugetopt (or at
least its include file) to match the latest version of the files from
libiberty.
Comment 4 Volker Stolz freebsd_committer freebsd_triage 2004-08-30 20:51:13 UTC
Responsible Changed
From-To: lioux->freebsd-port-bugs

lioux no longer maintains this one.
Comment 5 Volker Stolz freebsd_committer freebsd_triage 2004-08-30 21:26:02 UTC
Responsible Changed
From-To: freebsd-port-bugs->freebsd-ports-bugs

Fix typo
Comment 6 Florent Thoumie freebsd_committer freebsd_triage 2005-03-09 09:28:37 UTC
State Changed
From-To: open->feedback

I'm not sure devel/libgnugetopt is going to be updated. 

This PR is quite old now and Kato Tsuguru sent a patch to correct this 
behavior. 

Could you try it and say if it works for you? 


Comment 7 Florent Thoumie freebsd_committer freebsd_triage 2005-03-09 09:28:37 UTC
Responsible Changed
From-To: freebsd-ports-bugs->flz

Take replies.
Comment 8 Florent Thoumie freebsd_committer freebsd_triage 2005-04-04 13:46:38 UTC
Responsible Changed
From-To: flz->ahze

I'm not sure why i took this one, over to maintainer.
Comment 9 Michael Johnson freebsd_committer freebsd_triage 2005-04-08 05:24:40 UTC
State Changed
From-To: feedback->closed

This should not be a problem with 5.3+