summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authorYuichiro MASUI <[email protected]>2012-12-16 01:56:03 +0900
committerYuichiro MASUI <[email protected]>2012-12-16 01:56:03 +0900
commit06d242ae430ad37fd88fe6490980121ee26a1283 (patch)
treeb9326ec83c57de85381b73705f5cd55deaecc4f3 /mrbgems
parentf2d3c4d2f7361cbd5e246f78630cca919e342673 (diff)
downloadmruby-06d242ae430ad37fd88fe6490980121ee26a1283.tar.gz
mruby-06d242ae430ad37fd88fe6490980121ee26a1283.zip
Moved some building script from GNU make to Ruby script
Added minirake what's Rake subset
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/Makefile76
-rw-r--r--mrbgems/build_tasks.rb78
2 files changed, 78 insertions, 76 deletions
diff --git a/mrbgems/Makefile b/mrbgems/Makefile
deleted file mode 100644
index 2c0a0962c..000000000
--- a/mrbgems/Makefile
+++ /dev/null
@@ -1,76 +0,0 @@
-# makefile description.
-# add gems to the ruby library
-
-ifeq ($(strip $(MRUBY_ROOT)),)
- MRUBY_ROOT := $(realpath ..)
-endif
-
-LIBR := ../lib/libmruby.a
-RM_F := rm -f
-CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include
-
-export CC = gcc
-export LL = gcc
-export AR = ar
-
-GENERATOR := $(MRUBY_ROOT)/mrbgems/generator
-ifeq ($(OS),Windows_NT)
- GENERATOR_BIN := $(GENERATOR).exe
-else
- GENERATOR_BIN := $(GENERATOR)
-endif
-GEM_INIT := gem_init
-GEM_MAKEFILE := g/Makefile
-GEM_MAKEFILE_LIST := g/MakefileGemList
-GEMDLIB := g/mrbgemtest.ctmp
-
-ifeq ($(strip $(ACTIVE_GEMS)),)
- # the default file which contains the active GEMs
- ACTIVE_GEMS = GEMS.active
-endif
-
-##############################
-# generic build targets, rules
-
-.PHONY : all
-all : all_gems $(GEM_INIT).a
-
-$(GEM_INIT).a : $(GEM_INIT).o
- $(AR) rs gem_init.a $(GEM_INIT).o
-
-all_gems : $(GENERATOR_BIN)
- @echo "Generate Gem List Makefile"
- $(GENERATOR_BIN) makefile_list $(ACTIVE_GEMS) > $(GEM_MAKEFILE_LIST)
- @echo "Generate Gem Makefile"
- $(GENERATOR_BIN) makefile $(ACTIVE_GEMS) "$(MRUBY_ROOT)" > $(GEM_MAKEFILE)
- @echo "Build all gems"
- $(MAKE) -C g MRUBY_ROOT='$(MRUBY_ROOT)' ACTIVE_GEMS="$(ACTIVE_GEMS)"
-
-$(GEM_INIT).c : $(GENERATOR_BIN)
- @echo "Generate Gem driver"
- $(GENERATOR_BIN) $(GEM_INIT) $(ACTIVE_GEMS) > $@
-
-$(GEM_INIT).o : $(GEM_INIT).c
- @echo "Build the driver which initializes all gems"
- $(CC) $(CC_FLAGS) -MMD -c $< -o $@
-
-# Generator
-
-$(GENERATOR_BIN) : $(GENERATOR).o
- @echo "Build the generator which creates the driver and Gem Makefile"
- $(LL) -o $@ $(CC_FLAGS) $<
-
-$(GENERATOR).o : $(GENERATOR).c
- $(CC) $(CC_FLAGS) -MMD -c $< -o $@
-
-.PHONY : prepare-test
-prepare-test :
- @$(MAKE) prepare-test -C g ACTIVE_GEMS="$(ACTIVE_GEMS)" MRUBY_ROOT='$(MRUBY_ROOT)'
-
-# clean driver and all gems
-.PHONY : clean
-clean : $(GENERATOR_BIN)
- @echo "Cleanup Gems"
- $(GENERATOR_BIN) makefile $(ACTIVE_GEMS) "$(MRUBY_ROOT)" > $(GEM_MAKEFILE)
- $(MAKE) clean -C g ACTIVE_GEMS="$(ACTIVE_GEMS)" MRUBY_ROOT='$(MRUBY_ROOT)'
- -$(RM_F) $(GEM_INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) $(GEM_MAKEFILE_LIST) gem_init.a
diff --git a/mrbgems/build_tasks.rb b/mrbgems/build_tasks.rb
new file mode 100644
index 000000000..f7accdffa
--- /dev/null
+++ b/mrbgems/build_tasks.rb
@@ -0,0 +1,78 @@
+MRBGEMS_PATH = File.dirname(__FILE__)
+
+GEM_INIT = "#{MRBGEMS_PATH}/gem_init"
+GEM_MAKEFILE = "#{MRBGEMS_PATH}/g/Makefile"
+GEM_MAKEFILE_LIST = "#{MRBGEMS_PATH}/g/MakefileGemList"
+MAKEFILE_4_GEM = "#{MRUBY_ROOT}/mrbgems/Makefile4gem"
+
+GEM_MAKE_FLAGS = "#{MAKE_FLAGS} MAKEFILE_4_GEM='#{MAKEFILE_4_GEM}'"
+
+task :mrbgems_all => ["#{GEM_INIT}.a"] do
+ for_each_gem do |f|
+ sh "#{MAKE} -C #{f} #{GEM_MAKE_FLAGS}"
+ end
+end
+
+task :mrbgems_clean do
+ sh "cd #{MRUBY_ROOT}/mrbgems/g && #{RM_F} *.c *.d *.rbtmp *.ctmp *.o mrbtest"
+ for_each_gem do |f|
+ sh "#{MAKE} clean -C #{f} #{GEM_MAKE_FLAGS}"
+ end
+end
+
+task :mrbgems_prepare_test do
+ sh "#{CAT} #{for_each_gem{|f| "#{f}/test/*.rb "}} > #{MRUBY_ROOT}/mrbgems/g/mrbgemtest.rbtmp"
+ sh "#{MRUBY_ROOT}/bin/mrbc -Bmrbgemtest_irep -o#{MRUBY_ROOT}/mrbgems/g/mrbgemtest.ctmp #{MRUBY_ROOT}/mrbgems/g/mrbgemtest.rbtmp"
+end
+
+file "#{GEM_INIT}.a" => ["#{GEM_INIT}.c", "#{GEM_INIT}.o"] do |t|
+ sh "#{AR} rs #{t.name} #{t.prerequisites.join(' ')}"
+end
+
+rule ".o" => [".c"] do |t|
+ puts "Build the driver which initializes all gems"
+ sh "#{CC} #{CFLAGS.join(' ')} -I #{MRUBY_ROOT}/include -MMD -c #{t.source} -o #{t.name}"
+end
+
+file "#{GEM_INIT}.c" do |t|
+ puts "Generate Gem driver: #{t.name}"
+ open(t.name, 'w') do |f|
+ f.puts <<__EOF__
+/*
+ * This file contains a list of all
+ * initializing methods which are
+ * necessary to bootstrap all gems.
+ *
+ * IMPORTANT:
+ * This file was generated!
+ * All manual changes will get lost.
+ */
+
+#include "mruby.h"
+
+#{for_each_gem{|f| "void GENERATED_TMP_mrb_%s_gem_init(mrb_state*);\n" % [File.basename(f)]}}
+
+void
+mrb_init_mrbgems(mrb_state *mrb) {
+#{for_each_gem{|f| " GENERATED_TMP_mrb_%s_gem_init(mrb);\n" % [File.basename(f)]}}
+}
+__EOF__
+ end
+end
+
+def for_each_gem(&block)
+ IO.readlines(ACTIVE_GEMS).map { |line|
+ block.call(line.chomp)
+ }.join('')
+end
+
+task :mrbgems_generate_gem_makefile_list do
+ open(GEM_MAKEFILE_LIST, 'w') do |f|
+ f.puts <<__EOF__
+GEM_LIST := #{for_each_gem{|f| "#{f}/mrb-#{File.basename(f)}-gem.a"}}
+
+GEM_ARCHIVE_FILES := #{MRUBY_ROOT}/mrbgems/gem_init.a
+GEM_ARCHIVE_FILES += $(GEM_LIST)
+__EOF__
+ end
+end