tags:

views:

18

answers:

1

I have been looking into Rake for build script in our CI system (Projects built with C++). I have been playing about with a simple 'hello world' application to see what rake is capable of doing. All was well until i decided to put the .h files into a include folder and the .cpp files into src folder. Rake was able to find the .cpp files but not the include header files. File structure like this:

src/main.cpp
src/greet.cpp
include/greet.h

rake script was as follows:


require 'rake/clean'
require 'rake/loaders/makefile'

APPLICATION = 'hello.exe'
C_FILES = FileList['src/*.cpp']
HDR_FILES = FileList['include/*.h']
ALL_FILES = [C_FILES] + HDR_FILES
O_FILES = C_FILES.sub(/\.cpp$/, '.o')

file '.depend.mf' do
  sh "makedepend -f- --  -- #{ALL_FILES} > .depend.mf"
end

import ".depend.mf"

file APPLICATION => O_FILES do |t|
  sh "gcc #{O_FILES} -o #{t.name}"
end

rule ".o" => [".cpp"] do |t|
  sh "gcc -c -o #{t.name} #{t.source}"
end

C_FILES.each do |src|
  file src.ext(".o") => src
end

CLEAN.include("**/*.o")
CLEAN.include(APPLICATION)
CLEAN.include(".depend.mf")

task :default => APPLICATION

Any help would be much appreciated.

A: 

this line: ALL_FILES = [C_FILES] + HDR_FILES should be ALL_FILES = C_FILES << HDR_FILES

a FileList is just a fancy array that rake provides for us, but it's just an array underneath the hood, so we can use all of the standard array operators on it.

the << operator will append all of the items in the HDR_FILES array onto the end of the C_FILES array.

using the + operator will add the HDR_FILES array as a single element to the end of the C_FILES array, creating an array of arrays

Derick Bailey