From 6dceece0e4b44ce810e28015b7aae3ad00853987 Mon Sep 17 00:00:00 2001 From: sandyx Date: Mon, 3 Feb 2025 17:05:17 -0600 Subject: [PATCH] init --- build.rb | 11 +++++------ install | 2 -- install.rb | 10 ++++++++++ rub | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 70 insertions(+), 9 deletions(-) delete mode 100644 install create mode 100644 install.rb diff --git a/build.rb b/build.rb index 9844b5a..506fef1 100755 --- a/build.rb +++ b/build.rb @@ -20,11 +20,6 @@ BUILDDIR="build" INCLUDE="" LIB="-lraylib" -def error(msg) - puts "error: #{msg}" - exit(1) -end - #handle argument parsing yourself def parse(arg) case arg @@ -60,12 +55,16 @@ end #main build function def main + if Dir.children(SRCDIR).count == 0 + error("src directory empty") + end + threads = [] Dir.each_child(SRCDIR) {|x| threads << Thread.new { system("#{$CC} #{INCLUDE} #{CFLAGS} #{$EFLAGS} -c #{SRCDIR}/#{x} -o #{BUILDDIR}/#{File.basename(x, ".*") + ".o"}") if x.end_with?(".c") - print "compiled: #{x}\n" if x.end_with?(".c") + message "compiled: #{x}\n" if x.end_with?(".c") } } diff --git a/install b/install deleted file mode 100644 index 1f903a0..0000000 --- a/install +++ /dev/null @@ -1,2 +0,0 @@ -chmod +x rub -cp rub /usr/local/bin/rub diff --git a/install.rb b/install.rb new file mode 100644 index 0000000..2530d89 --- /dev/null +++ b/install.rb @@ -0,0 +1,10 @@ +#!/usr/bin/ruby + +require 'fileutils' + +RUBDIR = "#{Dir.home}/.rub" + +File.mkdir RUBDIR unless File.exist? RUBDIR +FileUtils.cp("build.rb", RUBDIR) +FileUtils.chmod("+x", "rub") +FileUtils.cp("rub", "/usr/local/bin") diff --git a/rub b/rub index 9b2aeb7..8151aad 100755 --- a/rub +++ b/rub @@ -1,3 +1,57 @@ #!/usr/bin/ruby -require "#{Dir.pwd}/build.rb" +require 'fileutils' + +ANSI_RED = "\e[31m" +ANSI_CLEAR = "\e[0m" +RUB = "#{ANSI_RED}RUB#{ANSI_CLEAR}" + +RUBDIR = "#{Dir.home}/.rub/" + +def error(msg) + puts "#{RUB}: error: #{msg}" + exit 1 +end + +def message(msg) + puts "#{RUB}: #{msg}" +end + +def rub_init(name) + 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" + + File.mkdir "src" + File.mkdir "build" + FileUtils.cp(RUBDIR + "build.rb", Dir.pwd) + + `git init` + `git branch -m main` +end + +def parse_arg(arg) + case arg + when "init" + error("no project name provided") + + when "meow" + puts "#{RUB}: meow :3" + end +end + +def parse_args(argv) + case argv[0] + when "init" + rub_init(argv[1]) + end +end + +case ARGV.count +when 0 + require "#{Dir.pwd}/build.rb" +when 1 + parse_arg(ARGV[0]) +when 2 + parse_args(ARGV) +end