From zajatz at gmail.com Wed Apr 23 12:09:24 2008 From: zajatz at gmail.com (=?UTF-8?B?0KHQtdGA0LPQtdC5INCc0L7Qu9C+0LTRhtC+0LI=?=) Date: Wed, 23 Apr 2008 20:09:24 +0400 Subject: [Rant-cafe] Build C/C++ code Message-ID: <9bd4be950804230909m2daf2753o7c8c9e36814199b1@mail.gmail.com> Hello, all. Can't anyone give me an example of rant recepie to compile hog.S into hog.o with gcc? I know command: "gcc -I. -o hog.o hog.S", but Rant syntax with all generators is confusing while examples from documentation does not work. Thanks, Sergey Molodtsoff. From pal at foss.dk Wed Apr 23 15:56:32 2008 From: pal at foss.dk (Peter Allin) Date: Wed, 23 Apr 2008 21:56:32 +0200 Subject: [Rant-cafe] Build C/C++ code References: <9bd4be950804230909m2daf2753o7c8c9e36814199b1@mail.gmail.com> Message-ID: <492B48D4183ACA409A773BB2633BBB05346B8A@FOSS40.foss.net> > Can't anyone give me an example of rant recepie to compile hog.S into hog.o > with gcc? I know command: "gcc -I. -o hog.o hog.S", but Rant syntax with all > generators is confusing while examples from documentation does not work. If you just want to create a rule for translating a single .c file into a .o file, the following should do it: file "bar.o" => "bar.c" do sys "gcc -c -I. -o bar.o bar.c" end This tells rant that the file "bar.o" depends on "bar.c", and that it should run the given command line to create "bar.o". This means that the command will be run when the date of "bar.c" is newer than the date of "bar.o" or when "bar.o does not exist. But you will probably quickly tire of writing a rule for each .o file in your program. the "Rule" generator can help you out like this: gen Rule, '.o' => '.c' do |t| sys "gcc -c -I. -o #{t.name} #{t.source}" end The first line says that we want a rule for creating ".o" files from ".c" files. The 't' variable passed to the block is a an object of the FileTask class, which amongst others defines these methods: - prerequisites, which returns a list of the file names of the prerequisites for the task. - source, which returns the name of the first prerequisite for the class. - name, which returns the name of the file that should be generated by the task. The second line then use the "name" and "source" methods to generate a command line and run it with the "sys" method. If you want the ".o" files linked into an executable, add something like this to your Rantfile: file "myprog" => [ "bar.o", "foo.o", "main.o"] do |t| sys "gcc #{t.prerequisites.join ' '} -o myprog" end This will make the "myprog" file depend on the three ".o" files in the list, and execute a command line linking all the prerequisites. With a little more complexity you can make the files be rebuilt whenever the commandline use to create them changes (for example when you change compiler options). The code below will do that: import "command" gen Command, "myprog" => [ "bar.o", "foo.o", "main.o"] do |t| "gcc #{t.prerequisites.join ' '} -o myprog" end gen Rule, '.o' => '.c' do |target, sources| gen Command, target => sources do |t| "gcc -c -I. -o #{t.name} #{t.source}" end end All the examples above compiles from ".c" files, but it should be simple to add ".S" files using the same techniques. I hope this can be of some help, Peter Allin -------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/rant-cafe/attachments/20080423/d834f409/attachment.html From russel at russel.org.uk Thu Apr 24 02:19:11 2008 From: russel at russel.org.uk (Russel Winder) Date: Thu, 24 Apr 2008 07:19:11 +0100 Subject: [Rant-cafe] Build C/C++ code In-Reply-To: <492B48D4183ACA409A773BB2633BBB05346B8A@FOSS40.foss.net> References: <9bd4be950804230909m2daf2753o7c8c9e36814199b1@mail.gmail.com> <492B48D4183ACA409A773BB2633BBB05346B8A@FOSS40.foss.net> Message-ID: <1209017951.30073.65.camel@balin.russel.org.uk> Peter, On Wed, 2008-04-23 at 21:56 +0200, Peter Allin wrote: > file "bar.o" => "bar.c" do > sys "gcc -c -I. -o bar.o bar.c" > end > gen Rule, '.o' => '.c' do |t| > sys "gcc -c -I. -o #{t.name} #{t.source}" > end There is also the option of the style: Sources = [ . . . ] Source.each { |name | Target = . . . Source = . . . file Target => Source do . . . end } where you code up the rule by reflecting on the state of the build. The whole point of Rant, Rake, SCons, Gant, etc. is that you can program the build, it is not mandatory to have the rules at the top level in Make style. But I guess I am preaching to the converted on this list :-) -- Russel. ==================================================== Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: http://www.russel.org.uk/ -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: This is a digitally signed message part Url : http://rubyforge.org/pipermail/rant-cafe/attachments/20080424/3966e110/attachment.bin From langstefan at gmx.at Thu Apr 24 06:38:36 2008 From: langstefan at gmx.at (Stefan Lang) Date: Thu, 24 Apr 2008 12:38:36 +0200 Subject: [Rant-cafe] Build C/C++ code In-Reply-To: <9bd4be950804230909m2daf2753o7c8c9e36814199b1@mail.gmail.com> References: <9bd4be950804230909m2daf2753o7c8c9e36814199b1@mail.gmail.com> Message-ID: <200804241238.36873.langstefan@gmx.at> On Mittwoch, 23. April 2008, ?????? ???????? wrote: > Hello, all. Hello! > Can't anyone give me an example of rant recepie to compile hog.S > into hog.o with gcc? I know command: "gcc -I. -o hog.o hog.S", but > Rant syntax with all generators is confusing while examples from > documentation does not work. Peter and Russel's examples should work for you. If you can point us to the examples that don't work, maybe we can fix it. Please also tell us your Ruby and Rant version! Stefan