feat: 🔥 oh god
This commit is contained in:
parent
cdb5492bfe
commit
3c7f48016d
30 changed files with 708 additions and 280 deletions
70
bin/cpp_engine.rb
Normal file
70
bin/cpp_engine.rb
Normal file
|
@ -0,0 +1,70 @@
|
|||
|
||||
|
||||
$core.add_artefact_engine Comfpile::ParserEngine,
|
||||
file_regex: /^(.+)\.(h|c|cpp)$/,
|
||||
search_regexes: [
|
||||
{
|
||||
regex: /^#include\s*[<"](?<value>.+)[>"]/,
|
||||
key: 'include'
|
||||
},
|
||||
{
|
||||
regex: /\/\/\s*comf\.(?<key>\w+)[=:]?\s*(?<value>.+)/
|
||||
}
|
||||
]
|
||||
|
||||
$core.add_artefact_engine do |engine|
|
||||
engine.add_recipe(:object, /^(.*)\.(h|c|cpp)$/) do |match, a|
|
||||
a.parent_artefact :sourcefile, match[0]
|
||||
|
||||
a.add_step do
|
||||
`g++ -I #{@build_dir} -c #{@target} -o #{@target}.o`
|
||||
end
|
||||
end
|
||||
|
||||
engine.add_recipe(:main_object, /^(.*)\.(h|c|cpp)$/) do |match, a|
|
||||
a.parent_artefact :sourcefile, match[0]
|
||||
|
||||
a.add_step do
|
||||
`g++ -DCOMF_MAIN -I #{@build_dir} -c #{@target} -o #{@target}.main.o`
|
||||
end
|
||||
end
|
||||
|
||||
engine.add_recipe(:executable) do |match, a|
|
||||
a.parent_artefact :dependency_analysis, match
|
||||
|
||||
a.add_step do
|
||||
@object_files = []
|
||||
|
||||
@parent_artefact.dependencies.each do |dep|
|
||||
next unless ['.c', '.cpp'].include? File.extname(dep.target)
|
||||
next if dep.target == @target
|
||||
|
||||
@object_files << require_artefact(:object, dep.target)
|
||||
end
|
||||
|
||||
@main_object_file = require_artefact(:main_object, @target)
|
||||
end
|
||||
|
||||
a.add_step do
|
||||
link_objects = []
|
||||
@object_files.each do |obj|
|
||||
link_objects << obj.target + '.o'
|
||||
end
|
||||
link_objects << @main_object_file.target + '.main.o'
|
||||
|
||||
cmd = "g++ #{link_objects.join(' ')} -o #{@target.sub(/\.[^.\/]*\Z/, '')}"
|
||||
log cmd
|
||||
|
||||
`#{cmd}`
|
||||
end
|
||||
end
|
||||
|
||||
engine.add_recipe(:execute) do |match, a|
|
||||
|
||||
a.parent_artefact :executable, match
|
||||
|
||||
a.add_step do
|
||||
print `./#{@target.sub(/\.[^.\/]*\Z/, '')}`
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue