public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download: 
* [gentoo-dev] [RFC] toolchain-funcs.eclass: functions to call compiler
@ 2010-05-31 19:12 99% Michał Górny
  0 siblings, 0 replies; 1+ results
From: Michał Górny @ 2010-05-31 19:12 UTC (permalink / raw
  To: gentoo-dev


[-- Attachment #1.1: Type: text/plain, Size: 5774 bytes --]

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 sophisticated
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 manually,
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 maintain.

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 ${CXXFLAGS},
* 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 implementation
(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 there,
and I'm open to hear better ideas. I've decided to pass all additional
arguments (flags) through environmental variables to allow user to intuitively
supply long input file lists.

-- 
Best regards,
Michał Górny

<http://mgorny.alt.pl>
<xmpp:mgorny@jabber.ru>

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.2: toolchain-funcs.eclass.diff --]
[-- Type: text/x-patch, Size: 2321 bytes --]

--- /usr/portage/eclass/toolchain-funcs.eclass	2010-05-23 04:08:44.000000000 +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 ${lib}"
 	done
 }
+
+# @FUNCTION: tc-cc
+# @USAGE: <output-file> <input-files> [...]
+# @DESCRIPTION:
+# Compiled passed C source files into specified binary, respecting CC, CFLAGS,
+# 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_libs',
+# 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"
+	
+	local output=$1
+	shift
+	[[ -z ${CC} ]] && local CC=$(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: <output-file> <input-files> [...]
+# @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 might 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_cxxflags'
+# 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"
+	
+	local output=$1
+	shift
+	[[ -z ${CXX} ]] && local CXX=$(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}
+}

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1.3: zpaq-1.10.ebuild.diff --]
[-- Type: text/x-patch, Size: 1066 bytes --]

Index: zpaq-1.10.ebuild
===================================================================
--- zpaq-1.10.ebuild	(revision 10619)
+++ zpaq-1.10.ebuild	(working copy)
@@ -42,20 +42,20 @@
 		local stripflag=' -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=
+		my_ldflags=${stripflag} tc-cxx striptest striptest.c \
+			|| stripflag=
 
 		sed -i -e "s:%LDFLAGS%:${LDFLAGS}${stripflag}:" zpaqmake || die
 	fi
 }
 
 src_compile() {
-	"${CXX}" ${CXXFLAGS} -DNDEBUG ${LDFLAGS} zpaq.cpp -o zpaq || die
-	"${CXX}" ${CXXFLAGS} ${LDFLAGS} lzppre.cpp -o lzppre || die
+	my_cppflags=-DNDEBUG tc-cxx zpaq zpaq.cpp || die
+	tc-cxx lzppre lzppre.cpp || die
 
 	if use optimization; then
 		# provide precompiled stub
-		"${CXX}" -c ${CXXFLAGS} -DNDEBUG -DOPT zpaq.cpp -o zpaq.o || die
+		my_cxxflags='-c' my_cppflags='-DNDEBUG -DOPT' tc-cxx zpaq.o zpaq.cpp || die
 	fi
 }
 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[relevance 99%]

Results 1-1 of 1 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2010-05-31 19:12 99% [gentoo-dev] [RFC] toolchain-funcs.eclass: functions to call compiler Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox