summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--mrbgems/Makefile4gem14
-rw-r--r--mrbgems/generator.c43
2 files changed, 46 insertions, 11 deletions
diff --git a/mrbgems/Makefile4gem b/mrbgems/Makefile4gem
index 358716fdf..3a2e74096 100644
--- a/mrbgems/Makefile4gem
+++ b/mrbgems/Makefile4gem
@@ -24,6 +24,8 @@ ifeq ($(strip $(LIBR)),)
LIBR := $(MRUBY_ROOT)lib/libmruby.a
endif
+GEM_PACKAGE := mrb-$(GEM)-gem.a
+
# Default rules which are calling the
# gem specific gem-all and gem-clean
# implementations of a gem
@@ -36,7 +38,7 @@ gem-info:
# Building target for C and Ruby files
gem-c-and-rb-files : gem_mixlib.o
- $(AR) rs gem.a $(GEM_OBJECTS) $^
+ $(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $^
gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp
cat $^ > $@
@@ -46,14 +48,14 @@ gem_mixlib_init.ctmp :
# Building target for C files
gem-c-files : gem_srclib.o
- $(AR) rs gem.a $(GEM_OBJECTS) $<
+ $(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $<
gem_srclib.c :
$(MRUBY_ROOT)mrbgems/generator gem_srclib $(GEM) > $@
# Building target for Ruby Files
gem-rb-files : gem_mrblib.o
- $(AR) rs gem.a $<
+ $(AR) rs $(GEM_PACKAGE) $<
gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp
cat $^ > $@
@@ -71,13 +73,13 @@ gem_mrblib.rbtmp :
cat $(GEM_RB_FILES) > $@
gem-clean-c-and-rb-files :
- -$(RM) gem.a gem_mixlib.o gem_mixlib.c gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp gem_mrblib.rbtmp
+ -$(RM) $(GEM_PACKAGE) gem_mixlib.o gem_mixlib.c gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp gem_mrblib.rbtmp
gem-clean-c-files :
- -$(RM) gem.a gem_srclib.c gem_srclib.o $(GEM_OBJECTS)
+ -$(RM) $(GEM_PACKAGE) gem_srclib.c gem_srclib.o $(GEM_OBJECTS)
gem-clean-rb-files :
- -$(RM) gem.a gem_mrblib.o gem_mrblib.c gem_mrblib_header.ctmp gem_mrblib_init.ctmp gem_mrblib_irep.ctmp gem_mrblib.rbtmp
+ -$(RM) $(GEM_PACKAGE) gem_mrblib.o gem_mrblib.c gem_mrblib_header.ctmp gem_mrblib_init.ctmp gem_mrblib_irep.ctmp gem_mrblib.rbtmp
.PHONY : clean
clean : gem-clean
diff --git a/mrbgems/generator.c b/mrbgems/generator.c
index 12bc2a63a..a167b848b 100644
--- a/mrbgems/generator.c
+++ b/mrbgems/generator.c
@@ -13,6 +13,39 @@ char *get_file_name(char *path)
return base ? base+1 : path;
}
+char *replace(const char *s, const char *old, const char *new)
+{
+ char *ret;
+ int i, count = 0;
+ size_t newlen = strlen(new);
+ size_t oldlen = strlen(old);
+
+ for (i = 0; s[i] != '\0'; i++) {
+ if (strstr(&s[i], old) == &s[i]) {
+ count++;
+ i += oldlen - 1;
+ }
+ }
+
+ ret = malloc(i + count * (newlen - oldlen));
+ if (ret == NULL)
+ exit(EXIT_FAILURE);
+
+ i = 0;
+ while (*s) {
+ if (strstr(s, old) == s) {
+ strcpy(&ret[i], new);
+ i += newlen;
+ s += oldlen;
+ }
+ else
+ ret[i++] = *s++;
+ }
+ ret[i] = '\0';
+
+ return ret;
+}
+
/*
* Template generator for each active GEM
*
@@ -25,8 +58,8 @@ char *get_file_name(char *path)
* String at the start of the template
* end:
* String at the end of the template
- * dir_to_skip:
- * Name of a directory which will be skipped
+ * full_path
+ * Should the full path of the GEM be used?
*
*/
static char*
@@ -76,7 +109,7 @@ for_each_gem (char before[1024], char after[1024],
strcat(complete_line, gem_list[i]);
else
strcat(complete_line, get_file_name(gem_list[i]));
- strcat(complete_line, after);
+ strcat(complete_line, replace(after, "#GEMNAME#", get_file_name(gem_list[i])));
}
strcat(complete_line, end);
@@ -161,10 +194,10 @@ void
make_gem_makefile_list()
{
printf("%s",
- for_each_gem(" ", "", "GEM_LIST := ", "\n", TRUE)
+ for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE)
);
- printf("GEM_ARCHIVE_FILES := $(addsuffix /gem.a, $(GEM_LIST))\n"
+ printf("GEM_ARCHIVE_FILES := $(GEM_LIST)\n"
"GEM_ARCHIVE_FILES += $(MRUBY_ROOT)/mrbgems/gem_init.a\n\n");
}