From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1OJAQl-0000CI-U5 for garchives@archives.gentoo.org; Mon, 31 May 2010 19:13:48 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 58FDFE07E0; Mon, 31 May 2010 19:13:41 +0000 (UTC) Received: from mail-fx0-f53.google.com (mail-fx0-f53.google.com [209.85.161.53]) by pigeon.gentoo.org (Postfix) with ESMTP id 98053E0790 for ; Mon, 31 May 2010 19:13:13 +0000 (UTC) Received: by fxm14 with SMTP id 14so2873495fxm.40 for ; Mon, 31 May 2010 12:13:13 -0700 (PDT) Received: by 10.223.5.89 with SMTP id 25mr5921390fau.87.1275333192425; Mon, 31 May 2010 12:13:12 -0700 (PDT) Received: from pomiocik.lan ([81.219.195.100]) by mx.google.com with ESMTPS id j23sm42713629faa.2.2010.05.31.12.13.09 (version=SSLv3 cipher=RC4-MD5); Mon, 31 May 2010 12:13:11 -0700 (PDT) Sender: Spam Box Date: Mon, 31 May 2010 21:12:46 +0200 From: =?UTF-8?B?TWljaGHFgiBHw7Nybnk=?= To: gentoo-dev@lists.gentoo.org Subject: [gentoo-dev] [RFC] toolchain-funcs.eclass: functions to call compiler Message-ID: <20100531211246.64181dab@pomiocik.lan> X-Mailer: Claws Mail 3.7.5 (GTK+ 2.18.9; x86_64-pc-linux-gnu) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org Mime-Version: 1.0 Content-Type: multipart/signed; micalg=PGP-SHA1; boundary="Sig_/6fALw9.rkwm2t7Fo4_97gyR"; protocol="application/pgp-signature" X-Archives-Salt: 74df7775-a09c-4eda-ad68-acb67b91cff7 X-Archives-Hash: 3d5d6138926c7611c59c77c8a10d0d26 --Sig_/6fALw9.rkwm2t7Fo4_97gyR Content-Type: multipart/mixed; boundary="MP_/zFmB6t7RL5LvlHlri/NmnH." --MP_/zFmB6t7RL5LvlHlri/NmnH. Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hello, As suggested by jer@g.o in bug #321165, I would like to raise a proposal on extending toolchain-funcs.eclass with helper functions to compile applications directly. There are many simple applications which come without neither a sophisticat= ed build system or even a tiny Makefile. In some cases, such applications aren= 't even packages as tarball -- a single, compressed source file is published instead. In case of these applications, ebuilds inherit toolchain-funcs.eclass to retrieve compiler information (tc-getCC/tc-getCXX) and call compiler manual= ly, passing appropriate flags. This way, we get certain amount of code being repeated in many ebuilds, slightly differing in the way of calling the compiler and order of arguments being passed to it (see examples below). Although I haven't heard of any problems related to that, it is certainly not fool-proof and hard to mainta= in. As jer suggested, I'm providing below a listing of example ebuilds calling the compiler directly and notes on differences between the way they call it. Similar list could be obtained through calling: $ grep tc-getCXX.*CXXFLAGS.*-o /usr/portage/*/*/*.ebuild $ grep tc-getCC.*CFLAGS.*-o /usr/portage/*/*/*.ebuild C++ examples include: * app-misc/clockywock - single C++ file, ${LDFLAGS} before ${CXXFLAGS}, * app-pda/iripdb - two C++ files, with echoing the commands, ${LDFLAGS} ignored, * app-text/duconv - single C++ file with separate compilation and linking, ${LDFLAGS} after ${CXXFLAGS}, * dev-cpp/tree - single C++ file, ${LDFLAGS} ignored, * games-arcade/gunocide2ex - multiple C++ files, ${LDFLAGS} after ${CXXFLAG= S}, * mail-filter/normalizemime, * media-sound/hearnet/hearnet, * net-misc/l7-protocols, * x11-apps/amlc. C examples include: * app-admin/hwreport - single C file, ${LDFLAGS} after ${CFLAGS}, * app-admin/sysrqd - single C file, ${LDFLAGS} ignored, * app-arch/unlzx - single C file, ${LDFLAGS} after ${CFLAGS}, * app-arch/unmakeself - single C file, '-o' after libraries, * app-cdr/bchunk - ${LDFLAGS} ignored, * app-cdr/{cddetect,nrg2iso,uif2iso} * app-crypt/scsign - '-pthread' at the beginning, '-o' after sources, * app-emacs/mpg123-el - ${LDFLAGS} ignored, * app-forensics/{cmospwd,galleta,pasco,rifiuti} - ${LDFLAGS} ignored, '-o' after sources, * app-misc/hilite - ${LDFLAGS} before ${CFLAGS}, * app-misc/irtrans-irclient - ${LDFLAGS} ignored, * app-misc/sl - '-o' after libs, command echoed, * app-text/unpaper - ${LDFLAGS} before ${CFLAGS}, '-o' after sources, * dev-games/paklib - ${LDFLAGS} ignored, '-o' after sources, * dev-java/rxtx - ${LDFLAGS} before ${CFLAGS}, '-o' after sources, * dev-lang/bff, * dev-libs/libhash - ${LDFLAGS} ignored, * dev-libs/libmemcache - ${LDFLAGS} ignored, * dev-libs/nss - (pseudo-configure check), seems ugly anyway, * dev-tcltk/tclperl - ${LDFLAGS} ignored, '-o' in the middle of flags, * dev-tex/tex4ht - ${CPPFLAGS} used (not many ebuilds care about them), * dev-tinyos/{channelgen,listen,serial-forwarder} - ${LDFLAGS} ignored, * dev-util/bsdiff, * dev-util/lockrun - ${LDFLAGS} ignored, '-o' after sources, * games-puzzle/trimines - creating pseudo-Makefile, ${LDFLAGS} ignored, 'sdl-config --cflags' after '-o', '-o' after sources, * games-server/tetrix - ${LDFLAGS} ignored, * games-util/biounzip, * mail-filter/qmail-scanner - ${LDFLAGS} ignored, * media-gfx/pngrewrite - ${LDFLAGS} before ${CFLAGS}, '-o' after libs, * media-sound/cd-discid - echoing commands, * media-sound/modplugplay, * media-sound/mserv - '-o' after sources, * media-sound/mup, * media-sound/wavegain - ${LDFLAGS} before ${CFLAGS}, '-o' after sources, defines after '-o', * media-tv/mythtv - ${LDFLAGS} after sources, * media-video/cpvts - echoing commands, * net-analyzer/bigeye - ${LDFLAGS} ignored, * net-analyzer/nagios-nrpe - ${LDFLAGS} ignored, * net-analyzer/nipper - ${LDFLAGS} ignored, '-o' after sources, * net-analyzer/ttcp - ${LDFLAGS} ignored, * net-dns/bind-dns-keygen - ${LDFLAGS} ignored, * net-dns/tinystats - ${LDFLAGS} after '-o', * net-fs/mount-cifs - ${LDFLAGS} ignored, * net-fs/samba-client, * net-im/bitlbee - ${LDFLAGS} ignored, * net-irc/ircd-hybrid - ${LDFLAGS} ignored, * net-mail/qmailanalog - ${LDFLAGS} ignored, '-o' after sources, * net-misc/connect, * net-misc/{datapipe,getdate} - ${LDFLAGS} ignored, * net-misc/ifenslave, * net-print/cups-pdf - ${LDFLAGS} ignored, * net-print/poster - ${LDFLAGS} ignored, '-o' after libs, * sci-biology/consed - ${LDFLAGS} ignored, '-o' after sources, * sci-chemistry/imosflm - separate compiling and linking, einfo printing, * sci-libs/ufconfig - separate compiling and linking, * sys-apps/netboot-base - ${LDFLAGS} ignored, * sys-apps/usb_modeswitch, * sys-apps/util-linux - (configure-like check), * sys-block/lsiutil, * sys-devel/gcc-config, * x11-libs/gl2ps - separate compiling and linking, * x11-misc/blockdpy, * x11-misc/xidle - echoing, using eval. And that's all for gentoo-x86 -- that's over 80 packages, with over 30 ignoring ${LDFLAGS}, not counting lesser issues. There's also 5 similar packages in Sunrise. I think that number is large enough to seriously consider adding such functions into toolchain-funcs.eclass. I'm attaching an example implementat= ion (as a diff to toolchain-funcs.eclass) and a diff to a sample ebuild (zpaq-1.10.ebuild from Sunrise, in particular). Please notice that I'm not really attached to the calling syntax I used the= re, and I'm open to hear better ideas. I've decided to pass all additional arguments (flags) through environmental variables to allow user to intuitiv= ely supply long input file lists. --=20 Best regards, Micha=C5=82 G=C3=B3rny --MP_/zFmB6t7RL5LvlHlri/NmnH. Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=toolchain-funcs.eclass.diff --- /usr/portage/eclass/toolchain-funcs.eclass 2010-05-23 04:08:44.00000000= 0 +0200 +++ toolchain-funcs.eclass 2010-05-31 20:55:34.000000000 +0200 @@ -653,3 +653,55 @@ gen_usr_ldscript() { fperms a+x "/usr/${libdir}/${lib}" || die "could not change perms on ${l= ib}" done } + +# @FUNCTION: tc-cc +# @USAGE: [...] +# @DESCRIPTION: +# Compiled passed C source files into specified binary, respecting CC, CFL= AGS, +# CPPFLAGS and LDFLAGS. +# +# If CC is not set, the compiler is obtained using $(tc-getCC) (you might = want +# to call 'tc-export CC' if you want to call tc-cc() multiple times). +# +# Additional flags to cpp/cc/ld might be set as 'my_cppflags', 'my_cflags'= and +# 'my_ldflags' respectively. Libraries to link against may be set as 'my_l= ibs', +# in the '-lfoo -lbar' form. +tc-cc() { + [[ -z $1 ]] && die "tc-cc: output file not specified" + [[ -z $2 ]] && die "tc-cc: no input files specified" +=09 + local output=3D$1 + shift + [[ -z ${CC} ]] && local CC=3D$(tc-getCC) + + einfo ${CC} ${CPPFLAGS} ${my_cppflags} ${CFLAGS} ${my_cflags} \ + ${LDFLAGS} ${my_ldflags} -o "${output}" "$@" ${my_libs} + ${CC} ${CPPFLAGS} ${my_cppflags} ${CFLAGS} ${my_cflags} \ + ${LDFLAGS} ${my_ldflags} -o "${output}" "$@" ${my_libs} +} + +# @FUNCTION: tc-cxx +# @USAGE: [...] +# @DESCRIPTION: +# Compiled passed C++ source files into specified binary, respecting CXX, +# CXXFLAGS, CPPFLAGS and LDFLAGS. +# +# If CXX is not set, the compiler is obtained using $(tc-getCXX) (you migh= t want +# to call 'tc-export CXX' if you want to call tc-cxx() multiple times). +# +# Additional flags to cpp/c++/ld might be set as 'my_cppflags', 'my_cxxfla= gs' +# and 'my_ldflags' respectively. Libraries to link against may be set as +# 'my_libs', in the '-lfoo -lbar' form. +tc-cxx() { + [[ -z $1 ]] && die "tc-cxx: output file not specified" + [[ -z $2 ]] && die "tc-cxx: no input files specified" +=09 + local output=3D$1 + shift + [[ -z ${CXX} ]] && local CXX=3D$(tc-getCXX) + + einfo ${CXX} ${CPPFLAGS} ${my_cppflags} ${CXXFLAGS} ${my_cxxflags} \ + ${LDFLAGS} ${my_ldflags} -o "${output}" "$@" ${my_libs} + ${CXX} ${CPPFLAGS} ${my_cppflags} ${CXXFLAGS} ${my_cxxflags} \ + ${LDFLAGS} ${my_ldflags} -o "${output}" "$@" ${my_libs} +} --MP_/zFmB6t7RL5LvlHlri/NmnH. Content-Type: text/x-patch Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename=zpaq-1.10.ebuild.diff Index: zpaq-1.10.ebuild =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- zpaq-1.10.ebuild (revision 10619) +++ zpaq-1.10.ebuild (working copy) @@ -42,20 +42,20 @@ local stripflag=3D' -Wl,--strip-all' # check whether the default compiler supports -Wl,--strip-all echo 'int main(void) {return 0;}' > striptest.c - "${CXX}" ${CXXFLAGS} ${LDFLAGS} ${stripflag} \ - striptest.c -o striptest || stripflag=3D + my_ldflags=3D${stripflag} tc-cxx striptest striptest.c \ + || stripflag=3D =20 sed -i -e "s:%LDFLAGS%:${LDFLAGS}${stripflag}:" zpaqmake || die fi } =20 src_compile() { - "${CXX}" ${CXXFLAGS} -DNDEBUG ${LDFLAGS} zpaq.cpp -o zpaq || die - "${CXX}" ${CXXFLAGS} ${LDFLAGS} lzppre.cpp -o lzppre || die + my_cppflags=3D-DNDEBUG tc-cxx zpaq zpaq.cpp || die + tc-cxx lzppre lzppre.cpp || die =20 if use optimization; then # provide precompiled stub - "${CXX}" -c ${CXXFLAGS} -DNDEBUG -DOPT zpaq.cpp -o zpaq.o || die + my_cxxflags=3D'-c' my_cppflags=3D'-DNDEBUG -DOPT' tc-cxx zpaq.o zpaq.cpp= || die fi } =20 --MP_/zFmB6t7RL5LvlHlri/NmnH.-- --Sig_/6fALw9.rkwm2t7Fo4_97gyR Content-Type: application/pgp-signature; name=signature.asc Content-Disposition: attachment; filename=signature.asc -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.15 (GNU/Linux) iEYEARECAAYFAkwECjMACgkQnGSe5QXeB7tEkgCggTZ0e1fOxAF69zKEda0TQoOR wg8Anjq1MdPJ00+qGswgZFkVh4v5liqK =lmU1 -----END PGP SIGNATURE----- --Sig_/6fALw9.rkwm2t7Fo4_97gyR--