Subject: C++ program handling in bsd.prog.mk
To: None <tech-toolchain@netbsd.org>
From: Jason R Thorpe <thorpej@wasabisystems.com>
List: tech-toolchain
Date: 12/31/2001 16:19:45
--ibTvN161/egqYuK8
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
C++ programs, especially if compiled with GCC 3.x, require different
handling from C programs in <bsd.prog.mk>. Specifically, the ${CC}
command used to link the program really should be ${CXX}, as this may
pull in additional support libraries provided by the compiler that make
C++ programs function properly.
For DESTDIR builds, these support programs also must be specified
explicitly, much like -lgcc is specified explicitly. For GCC 3.x,
the support libraries pull in implicitly if !-nostdlib are "-lstdc++ -lm"
(-lstdc++ includes routines that make C++ exception handling work, and
programs won't link without it (or -lsupc++, but since "c++" by itself
would use -lstdc++, that is also what I used)).
The patch below adds support for C++ programs to <bsd.prog.mk> by checking
to see if the program's Makefile has set PROG_CXX, adds support for pulling
in the additional support libraries for GCC 3.x (by testing to see that
HAVE_GCC3 is defined), and includes all the necessary changes to make our
in-tree groff build with GCC 3.1 (gcc-current).
--
-- Jason R. Thorpe <thorpej@wasabisystems.com>
--ibTvN161/egqYuK8
Content-Type: text/plain; charset=us-ascii
Content-Description: bsd.prog.mk-c++
Content-Disposition: attachment; filename=foo
Index: share/mk/bsd.prog.mk
===================================================================
RCS file: /cvsroot/sharesrc/share/mk/bsd.prog.mk,v
retrieving revision 1.144
diff -c -r1.144 bsd.prog.mk
*** share/mk/bsd.prog.mk 2001/12/28 01:32:41 1.144
--- share/mk/bsd.prog.mk 2002/01/01 00:15:47
***************
*** 126,143 ****
-L${DESTDIR}${SHLIBDIR}
.endif
.if defined(DESTDIR)
${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
.if !commands(${PROG})
! ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib -lgcc -lc -lgcc ${LIBCRTEND}
.endif
.else
${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
.if !commands(${PROG})
! ${CC} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
.endif
.endif # defined(DESTDIR)
--- 126,152 ----
-L${DESTDIR}${SHLIBDIR}
.endif
+ .if defined(PROG_CXX)
+ _CCLINK= ${CXX}
+ .if defined(HAVE_GCC3)
+ _SUPCXX= -lstdc++ -lm
+ .endif
+ .else
+ _CCLINK= ${CC}
+ .endif
+
.if defined(DESTDIR)
${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
.if !commands(${PROG})
! ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} -nostdlib ${_PROGLDOPTS} ${LIBCRT0} ${LIBCRTBEGIN} ${OBJS} ${LDADD} -L${DESTDIR}/usr/lib ${_SUPCXX} -lgcc -lc -lgcc ${LIBCRTEND}
.endif
.else
${PROG}: ${LIBCRT0} ${DPSRCS} ${OBJS} ${LIBC} ${LIBCRTBEGIN} ${LIBCRTEND} ${DPADD}
.if !commands(${PROG})
! ${_CCLINK} ${LDFLAGS} ${LDSTATIC} -o ${.TARGET} ${_PROGLDOPTS} ${OBJS} ${LDADD}
.endif
.endif # defined(DESTDIR)
Index: gnu/usr.bin/groff/addftinfo/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/addftinfo/Makefile,v
retrieving revision 1.6
diff -c -r1.6 Makefile
*** gnu/usr.bin/groff/addftinfo/Makefile 2001/04/19 14:40:41 1.6
--- gnu/usr.bin/groff/addftinfo/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= addftinfo
+ PROG_CXX=
SRCS= addftinfo.cc guess.cc
LDADD+= $(LIBGROFF)
DPADD+= $(LIBGROFF)
Index: gnu/usr.bin/groff/eqn/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/eqn/Makefile,v
retrieving revision 1.16
diff -c -r1.16 Makefile
*** gnu/usr.bin/groff/eqn/Makefile 2001/11/13 17:01:23 1.16
--- gnu/usr.bin/groff/eqn/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= eqn
+ PROG_CXX=
SRCS= main.cc lex.cc box.cc limit.cc list.cc over.cc text.cc\
script.cc mark.cc other.cc delim.cc sqrt.cc pile.cc special.cc\
eqn.cc
Index: gnu/usr.bin/groff/grn/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grn/Makefile,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 Makefile
*** gnu/usr.bin/groff/grn/Makefile 2001/04/19 14:33:14 1.1.1.1
--- gnu/usr.bin/groff/grn/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grn
+ PROG_CXX=
SRCS= hdb.cc hgraph.cc hpoint.cc main.cc
CPPFLAGS+= -I${DIST}
LDADD+= $(LIBGROFF) -lm
Index: gnu/usr.bin/groff/grodvi/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grodvi/Makefile,v
retrieving revision 1.7
diff -c -r1.7 Makefile
*** gnu/usr.bin/groff/grodvi/Makefile 2001/04/19 14:41:17 1.7
--- gnu/usr.bin/groff/grodvi/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grodvi
+ PROG_CXX=
SRCS= dvi.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/groff/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/groff/Makefile,v
retrieving revision 1.9
diff -c -r1.9 Makefile
*** gnu/usr.bin/groff/groff/Makefile 2001/04/19 14:41:17 1.9
--- gnu/usr.bin/groff/groff/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= groff
+ PROG_CXX=
SRCS= groff.cc pipeline.c
LDADD+= $(LIBGROFF) -lm
DPADD+= $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/grohtml/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grohtml/Makefile,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 Makefile
*** gnu/usr.bin/groff/grohtml/Makefile 2001/04/19 14:33:14 1.1.1.1
--- gnu/usr.bin/groff/grohtml/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grohtml
+ PROG_CXX=
SRCS= html.cc output.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/grolbp/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grolbp/Makefile,v
retrieving revision 1.1.1.1
diff -c -r1.1.1.1 Makefile
*** gnu/usr.bin/groff/grolbp/Makefile 2001/04/19 14:33:14 1.1.1.1
--- gnu/usr.bin/groff/grolbp/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grolbp
+ PROG_CXX=
SRCS= lbp.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/grolj4/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grolj4/Makefile,v
retrieving revision 1.4
diff -c -r1.4 Makefile
*** gnu/usr.bin/groff/grolj4/Makefile 2001/04/19 14:41:19 1.4
--- gnu/usr.bin/groff/grolj4/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grolj4
+ PROG_CXX=
SRCS= lj4.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/grops/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grops/Makefile,v
retrieving revision 1.10
diff -c -r1.10 Makefile
*** gnu/usr.bin/groff/grops/Makefile 2001/04/19 14:41:19 1.10
--- gnu/usr.bin/groff/grops/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grops
+ PROG_CXX=
SRCS= ps.cc psrm.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/grotty/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/grotty/Makefile,v
retrieving revision 1.10
diff -c -r1.10 Makefile
*** gnu/usr.bin/groff/grotty/Makefile 2001/04/19 14:41:20 1.10
--- gnu/usr.bin/groff/grotty/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= grotty
+ PROG_CXX=
SRCS= tty.cc
LDADD+= $(LIBDRIVER) $(LIBGROFF) -lm
DPADD+= $(LIBDRIVER) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/hpftodit/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/hpftodit/Makefile,v
retrieving revision 1.4
diff -c -r1.4 Makefile
*** gnu/usr.bin/groff/hpftodit/Makefile 2001/04/19 14:41:21 1.4
--- gnu/usr.bin/groff/hpftodit/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= hpftodit
+ PROG_CXX=
SRCS= hpftodit.cc
LDADD+= $(LIBGROFF) -lm
DPADD+= $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/indxbib/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/indxbib/Makefile,v
retrieving revision 1.12
diff -c -r1.12 Makefile
*** gnu/usr.bin/groff/indxbib/Makefile 2001/04/19 14:41:23 1.12
--- gnu/usr.bin/groff/indxbib/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= indxbib
+ PROG_CXX=
SRCS= indxbib.cc dirnamemax.c signal.c
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
DPADD+= $(LIBBIB) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/lkbib/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/lkbib/Makefile,v
retrieving revision 1.7
diff -c -r1.7 Makefile
*** gnu/usr.bin/groff/lkbib/Makefile 2001/04/19 14:41:29 1.7
--- gnu/usr.bin/groff/lkbib/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= lkbib
+ PROG_CXX=
SRCS= lkbib.cc
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
DPADD+= $(LIBBIB) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/lookbib/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/lookbib/Makefile,v
retrieving revision 1.7
diff -c -r1.7 Makefile
*** gnu/usr.bin/groff/lookbib/Makefile 2001/04/19 14:41:30 1.7
--- gnu/usr.bin/groff/lookbib/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= lookbib
+ PROG_CXX=
SRCS= lookbib.cc
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
DPADD+= $(LIBBIB) $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/pfbtops/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/pfbtops/Makefile,v
retrieving revision 1.5
diff -c -r1.5 Makefile
*** gnu/usr.bin/groff/pfbtops/Makefile 2001/04/19 14:41:33 1.5
--- gnu/usr.bin/groff/pfbtops/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= pfbtops
+ PROG_CXX=
LDADD+= $(LIBGROFF)
DPADD+= $(LIBGROFF)
Index: gnu/usr.bin/groff/pic/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/pic/Makefile,v
retrieving revision 1.14
diff -c -r1.14 Makefile
*** gnu/usr.bin/groff/pic/Makefile 2001/11/13 17:01:24 1.14
--- gnu/usr.bin/groff/pic/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= pic
+ PROG_CXX=
SRCS= lex.cc main.cc object.cc common.cc troff.cc tex.cc pic.cc
CPPFLAGS+= -I. -I${DIST}
LDADD+= $(LIBGROFF) -lm
Index: gnu/usr.bin/groff/refer/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/refer/Makefile,v
retrieving revision 1.10
diff -c -r1.10 Makefile
*** gnu/usr.bin/groff/refer/Makefile 2001/11/13 17:01:25 1.10
--- gnu/usr.bin/groff/refer/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= refer
+ PROG_CXX=
SRCS= command.cc ref.cc refer.cc token.cc label.cc
CPPFLAGS+= -I. -I${DIST}
LDADD+= $(LIBBIB) $(LIBGROFF) -lm
Index: gnu/usr.bin/groff/soelim/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/soelim/Makefile,v
retrieving revision 1.6
diff -c -r1.6 Makefile
*** gnu/usr.bin/groff/soelim/Makefile 2001/04/19 14:41:41 1.6
--- gnu/usr.bin/groff/soelim/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= soelim
+ PROG_CXX=
SRCS= soelim.cc
LDADD+= $(LIBGROFF)
DPADD+= $(LIBGROFF)
Index: gnu/usr.bin/groff/tbl/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/tbl/Makefile,v
retrieving revision 1.9
diff -c -r1.9 Makefile
*** gnu/usr.bin/groff/tbl/Makefile 2001/04/19 14:41:42 1.9
--- gnu/usr.bin/groff/tbl/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= tbl
+ PROG_CXX=
SRCS= main.cc table.cc
LDADD+= $(LIBGROFF) -lm
DPADD+= $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/tfmtodit/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/tfmtodit/Makefile,v
retrieving revision 1.7
diff -c -r1.7 Makefile
*** gnu/usr.bin/groff/tfmtodit/Makefile 2001/04/19 14:41:42 1.7
--- gnu/usr.bin/groff/tfmtodit/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= tfmtodit
+ PROG_CXX=
SRCS= tfmtodit.cc
LDADD+= $(LIBGROFF) -lm
DPADD+= $(LIBGROFF) $(LIBM)
Index: gnu/usr.bin/groff/troff/Makefile
===================================================================
RCS file: /cvsroot/gnusrc/gnu/usr.bin/groff/troff/Makefile,v
retrieving revision 1.17
diff -c -r1.17 Makefile
*** gnu/usr.bin/groff/troff/Makefile 2001/04/19 14:41:47 1.17
--- gnu/usr.bin/groff/troff/Makefile 2002/01/01 00:15:47
***************
*** 6,11 ****
--- 6,12 ----
.PATH: ${DIST}
PROG= troff
+ PROG_CXX=
SRCS= column.cc dictionary.cc div.cc env.cc input.cc node.cc \
number.cc reg.cc symbol.cc majorminor.cc
LDADD+= $(LIBGROFF) -lm
--ibTvN161/egqYuK8--