Module: Flak::Template::Cpp::Tasks

Defined in:
lib/flak/rake/templates/cpp.rb

Class Method Summary collapse

Class Method Details

.extended(target) ⇒ Object



102
103
104
# File 'lib/flak/rake/templates/cpp.rb', line 102

def self.extended target
  task_factory target
end

.task_factory(target) ⇒ Object



107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/flak/rake/templates/cpp.rb', line 107

def self.task_factory target
  settings = target.settings


  files = settings[:source_files]
  unless files.nil?




    # file tasks to compile objects from sources
    # make sure the object file depends on the 
    # source and header if it exists
    ######################################################    
    files.each do |f|
      object = target.object_file(f)  
      file object => f  do |t|
        target.make_directory_for(object)
        sh target.c_compile_cmd(f)
      end
      header = f.ext('h')
      file object => header if File.exists?(header) 
    end
    ######################################################     





    # file tasks to link targets
    ######################################################
    objects = target.object_files
    build_file = target.build_filename
    file build_file => objects do 
      target.make_directory_for(build_file)
      sh target.c_link_cmd
    end

    namespace settings[:name].to_sym do             
      desc "build the #{settings[:name].to_sym} binary"
      task :build => build_file # add named target
    end
    task :build => "#{settings[:name].to_sym}:build"
    ######################################################







    # tasks to clean the build
    ######################################################
    namespace settings[:name].to_sym do     
      desc "clean the #{settings[:name].to_sym} build files"
      task :clean do
        sh target.c_clean_cmd
      end
    end
    task :clean => "#{settings[:name].to_sym}:clean"
    ######################################################







    # plugins and executables release tasks
    ######################################################
    release_binary = target.release_filename
    build_file = target.build_filename  
    file release_binary => build_file do
      target.make_directory_for(release_binary)
      rm_r release_binary  if File.exists?(release_binary)
      cp build_file, release_binary 
      File.chmod 0755, release_binary 
    end
    ######################################################





    # add the release_binary file task to the tool's release task
    # and add the tool's release task to the release task
    # in the global namespace
    ######################################################
    namespace settings[:name].to_sym do             
      task :release => release_binary
    end

    task :release => "#{settings[:name].to_sym}:release"
    ######################################################

  end



end