From a05e43525d5f7e9e286421a18dfbc0a90e060168 Mon Sep 17 00:00:00 2001 From: sandyx Date: Sun, 2 Feb 2025 09:44:45 -0600 Subject: [PATCH] first --- build.rb | 89 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ install | 2 ++ readme.md | 9 ++++++ rub | 3 ++ 4 files changed, 103 insertions(+) create mode 100755 build.rb create mode 100644 install create mode 100644 readme.md create mode 100755 rub diff --git a/build.rb b/build.rb new file mode 100755 index 0000000..9844b5a --- /dev/null +++ b/build.rb @@ -0,0 +1,89 @@ +#!/usr/bin/ruby + +#I'll put this in here as an example + +# make a folder called src and a folder called build +# then put some c source code in src +# then run rub and watch it build + +# of course you could make your own build.rb to build any project + +# ruby might not let you modify CONSTANTS +# so put a $ in front of the name which makes +# them global and not CONSTANT +$CC="gcc" +CFLAGS="-O1 -march=native -std=c11 -fmacro-prefix-map=src=" +$EFLAGS = "" #extra flags +APPNAME="chess" +SRCDIR="src" +BUILDDIR="build" +INCLUDE="" +LIB="-lraylib" + +def error(msg) + puts "error: #{msg}" + exit(1) +end + +#handle argument parsing yourself +def parse(arg) + case arg + when "clean" + `rm build/*` + `rm #{APPNAME}` + exit(0) + + when "debug" + $EFLAGS = "-DDEBUG" + main + + when arg.split("=")[0] = "cc" + $CC = arg.split("=")[1] + main + + else + error "unknown argument: #{arg}" + end +end + +#same as above +def args + case ARGV.count + when 0 + main + when 1 + parse(ARGV[0]) + else + puts "too many arguments" + end +end + +#main build function +def main + 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") + } + } + + threads.each{ |t| t.join } + + #wait for each thread to finish + until threads.map { |t| t.alive? }.include?(false) + end + + build = Dir.each_child(BUILDDIR) + o_files = [] + build.each { |s| + o_files.append("#{BUILDDIR}/#{s}") + } + + `#{$CC} #{CFLAGS} #{$EFLAGS} #{o_files.join(" ")} -o #{APPNAME} #{LIB}` + exit(0) +end + +#run some functions +args diff --git a/install b/install new file mode 100644 index 0000000..1f903a0 --- /dev/null +++ b/install @@ -0,0 +1,2 @@ +chmod +x rub +cp rub /usr/local/bin/rub diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..27de371 --- /dev/null +++ b/readme.md @@ -0,0 +1,9 @@ +#Rub +>to install +``` +#sh install +``` +>to run +``` +$rub +``` diff --git a/rub b/rub new file mode 100755 index 0000000..9b2aeb7 --- /dev/null +++ b/rub @@ -0,0 +1,3 @@ +#!/usr/bin/ruby + +require "#{Dir.pwd}/build.rb"