You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

60 lines
1.6 KiB
Ruby

require 'fileutils'
module TMPL
C_MAIN = "#include <stdio.h>\n" \
"\nint main(int argc, char *argv[]) {\n" \
" printf(\"%s\\n\", \"Hello, World!\");\n" \
" return 0;\n" \
"}\n"
CPP_MAIN = "#include <cstdio>\n" \
"\nint main(int argc, char *argv[]) {\n" \
" std::printf(\"%s\\n\", \"Hello, World!\");\n" \
" return 0;\n" \
"}\n"
C = lambda { |name, tmpl|
error("template for \"#{tmpl}\" not found") unless File.exist? "#{TMPLDIR}/#{tmpl}.rb"
error("src directory already exists") if File.exist? "src"
error("build directory already exists") if File.exist? "build"
error(".git already exists") if File.exist? ".git"
FileUtils.mkdir "src"
FileUtils.mkdir "build"
buildfile = File.readlines(RUBDIR + "templates/#{tmpl}.rb")
buildfile.insert(17, "APPNAME=\"#{name}\"\n")
File.write("build.rb", buildfile.join)
c_main = File.open("src/main.c", "w")
c_main.write C_MAIN
c_main.close
`git init`
`git branch -m main`
message("set git branch to main")
}
CPP = lambda { |name, tmpl|
error("template for \"#{tmpl}\" not found") unless File.exist? "#{TMPLDIR}/#{tmpl}.rb"
error("src directory already exists") if File.exist? "src"
error("build directory already exists") if File.exist? "build"
error(".git already exists") if File.exist? ".git"
FileUtils.mkdir "src"
FileUtils.mkdir "build"
buildfile = File.readlines(RUBDIR + "templates/#{tmpl}.rb")
buildfile.insert(17, "APPNAME=\"#{name}\"\n")
File.write("build.rb", buildfile.join)
c_main = File.open("src/main.cpp", "w")
c_main.write CPP_MAIN
c_main.close
`git init`
`git branch -m main`
message("set git branch to main")
}
end