summaryrefslogtreecommitdiffhomepage
path: root/mrbgems
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2012-12-08 02:22:33 -0800
committerYukihiro "Matz" Matsumoto <[email protected]>2012-12-08 02:22:33 -0800
commit453980d76ae0ac22dc490612fefcab9cd756950f (patch)
tree71e928cb321291d6679451e6b390208ff36a007b /mrbgems
parentba38dd539822e4f514ea6fadd30f706b395926f6 (diff)
parent54ef99d8dfc18952fd647eb3012b21f54e9d0416 (diff)
downloadmruby-453980d76ae0ac22dc490612fefcab9cd756950f.tar.gz
mruby-453980d76ae0ac22dc490612fefcab9cd756950f.zip
Merge pull request #598 from bovi/mrbgems-improve-for-masuidrive
mrbgems - Improvements for masuidrive's mobiruby
Diffstat (limited to 'mrbgems')
-rw-r--r--mrbgems/Makefile4
-rw-r--r--mrbgems/Makefile4gem3
-rw-r--r--mrbgems/generator.c107
3 files changed, 91 insertions, 23 deletions
diff --git a/mrbgems/Makefile b/mrbgems/Makefile
index c7d1f577d..c9cd7add2 100644
--- a/mrbgems/Makefile
+++ b/mrbgems/Makefile
@@ -42,7 +42,7 @@ 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)" > $(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)"
@@ -71,6 +71,6 @@ prepare-test :
.PHONY : clean
clean : $(GENERATOR_BIN)
@echo "Cleanup Gems"
- $(GENERATOR_BIN) makefile "$(ACTIVE_GEMS)" > $(GEM_MAKEFILE)
+ $(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/Makefile4gem b/mrbgems/Makefile4gem
index 1725c5f15..df972ddbb 100644
--- a/mrbgems/Makefile4gem
+++ b/mrbgems/Makefile4gem
@@ -15,9 +15,6 @@ AR := ar
SRC_DIR := src
MRB_DIR := mrblib
-INCLUDES := -I$(SRC_DIR) -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I.
-CFLAGS := $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration
-
# LIBR can be manipulated with command line arguments
ifeq ($(strip $(LIBR)),)
# default mruby library
diff --git a/mrbgems/generator.c b/mrbgems/generator.c
index 8ac2746bf..cbad09747 100644
--- a/mrbgems/generator.c
+++ b/mrbgems/generator.c
@@ -7,6 +7,7 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
+#include <errno.h>
#include <mrbconf.h>
/*
@@ -24,6 +25,29 @@ static char
return base ? base+1 : path;
}
+static char
+*get_full_path(char *path, char *mruby_root)
+{
+ char full_path[1024] = { 0 };
+ if (path[0] == '/') {
+ /* An absolute UNIX path starts with a slash */
+ strcpy(full_path, path);
+ }
+ else if (path[1] == ':') {
+ /* An absolute path on WIN32 starts
+ * with a drive like "c://path/to/somewhere"
+ */
+ strcpy(full_path, path);
+ }
+ else {
+ strcpy(full_path, mruby_root);
+ strcat(full_path, "/mrbgems/g/");
+ strcat(full_path, path);
+ }
+
+ return full_path;
+}
+
/*
* Search in *s* for *old* and replace with *new*.
*
@@ -103,13 +127,20 @@ static char
* GEMS.active file location
* escape:
* Should the gem name be escaped?
+ * check_suffix:
+ * If not empty it will be added to the GEM
+ * path and a check will be performed if this
+ * full path is a directory. Every GEM which
+ * doesn't contain this path will be skipped
+ * in the iteration.
*
*/
static char*
for_each_gem (char before[1024], char after[1024],
char start[1024], char end[1024],
int full_path, char active_gems[1024],
- int escape)
+ int escape, char check_suffix[1024],
+ char mruby_root[1024])
{
/* active GEM check */
FILE *active_gem_file;
@@ -119,6 +150,9 @@ for_each_gem (char before[1024], char after[1024],
char gem_list[1024][1024] = { { 0 }, { 0 } };
int gem_index;
int i;
+ int skip;
+ FILE *check;
+ char check_name[1024] = { 0 };
/* return value */
char* complete_line = malloc(4096 + sizeof(char));
@@ -130,6 +164,7 @@ for_each_gem (char before[1024], char after[1024],
if (active_gem_file != NULL) {
char_index = 0;
gem_index = 0;
+ skip = FALSE;
while((gem_char = fgetc(active_gem_file)) != EOF) {
if (gem_char == '\n') {
/* Every line contains one active GEM */
@@ -138,7 +173,21 @@ for_each_gem (char before[1024], char after[1024],
if (escape == TRUE)
strcpy(gem_name, escape_gem_name(gem_name));
- strcpy(gem_list[gem_index++], gem_name);
+ if (strcmp(check_suffix, "") == 0) { /* No suffix passed */ }
+ else {
+ /* Check the path with suffix if it is a directory */
+
+ strcpy(check_name, get_full_path(gem_name, mruby_root));
+ strcat(check_name, check_suffix);
+ check = fopen(check_name, "r+");
+ if (errno == EISDIR)
+ skip = FALSE;
+ else
+ skip = TRUE;
+ }
+
+ if (skip == FALSE)
+ strcpy(gem_list[gem_index++], gem_name);
gem_name[0] = '\0';
char_index = 0;
@@ -153,8 +202,12 @@ for_each_gem (char before[1024], char after[1024],
for(i = 0; i < gem_index; i++) {
strcat(complete_line, before);
- if (full_path == TRUE)
- strcat(complete_line, gem_list[i]);
+ if (full_path == TRUE) {
+ if (strcmp(mruby_root, "") == 0)
+ strcat(complete_line, get_full_path(gem_list[i], "$(MRUBY_ROOT)"));
+ else
+ strcat(complete_line, get_full_path(gem_list[i], mruby_root));
+ }
else
strcat(complete_line, get_file_name(gem_list[i]));
strcat(complete_line, replace(after, "#GEMNAME#", get_file_name(gem_list[i])));
@@ -172,7 +225,7 @@ for_each_gem (char before[1024], char after[1024],
*
*/
static void
-make_gem_makefile(char active_gems[1024])
+make_gem_makefile(char active_gems[1024], char mruby_root[1024])
{
char *gem_check = { 0 };
int gem_empty;
@@ -180,16 +233,26 @@ make_gem_makefile(char active_gems[1024])
printf("ifeq ($(strip $(MRUBY_ROOT)),)\n"
" MRUBY_ROOT := $(realpath ../../..)\n"
"endif\n\n"
+
"MAKEFILE_4_GEM := $(MRUBY_ROOT)/mrbgems/Makefile4gem\n\n"
- "CFLAGS := -I. -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src\n\n"
+
+ "INCLUDE := ");
+
+ /* collect all GEM include directories if they exist */
+ printf("%s\n",
+ for_each_gem("-I", "/include ", "", "", TRUE, active_gems, FALSE, "/include", mruby_root)
+ );
+
+ printf("CFLAGS := -I. -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src $(INCLUDE)\n\n"
+
"ifeq ($(OS),Windows_NT)\n"
- " MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' MRUBY_ROOT='$(MRUBY_ROOT)' MAKEFILE_4_GEM='$(MAKEFILE_4_GEM)'\n"
+ " MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) CFLAGS='$(CFLAGS)' MRUBY_ROOT='$(MRUBY_ROOT)' MAKEFILE_4_GEM='$(MAKEFILE_4_GEM)'\n"
"else\n"
- " MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' MRUBY_ROOT='$(MRUBY_ROOT)' MAKEFILE_4_GEM='$(MAKEFILE_4_GEM)'\n"
+ " MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' CFLAGS='$(CFLAGS)' MRUBY_ROOT='$(MRUBY_ROOT)' MAKEFILE_4_GEM='$(MAKEFILE_4_GEM)'\n"
"endif\n\n");
/* is there any GEM available? */
- gem_check = for_each_gem("", "", "", "", TRUE, active_gems, FALSE);
+ gem_check = for_each_gem("", "", "", "", TRUE, active_gems, FALSE, "", "");
if (strcmp(gem_check, "") == 0)
gem_empty = TRUE;
else
@@ -205,7 +268,7 @@ make_gem_makefile(char active_gems[1024])
/* Call make for every GEM */
printf("all_gems :\n%s\n",
- for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems, FALSE)
+ for_each_gem("\t$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems, FALSE, "", "")
);
printf("\n");
}
@@ -217,7 +280,7 @@ make_gem_makefile(char active_gems[1024])
);
if (!gem_empty)
printf("%s",
- for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE, active_gems, FALSE)
+ for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE, active_gems, FALSE, "", "")
);
else
printf("\t$(MRUBY_ROOT)/mrbgems/generator rbtmp> mrbgemtest.rbtmp");
@@ -231,7 +294,7 @@ make_gem_makefile(char active_gems[1024])
"\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n");
if (!gem_empty)
printf("%s",
- for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems, FALSE)
+ for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems, FALSE, "", "")
);
}
@@ -246,7 +309,7 @@ static void
make_gem_makefile_list(char active_gems[1024])
{
printf("%s",
- for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE, active_gems, FALSE)
+ for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE, active_gems, FALSE, "", "")
);
printf("GEM_ARCHIVE_FILES := $(MRUBY_ROOT)/mrbgems/gem_init.a\n"
@@ -273,7 +336,7 @@ make_gem_init(char active_gems[1024])
/* Protoype definition of all initialization methods */
printf("\n%s",
- for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", FALSE, active_gems, TRUE)
+ for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", FALSE, active_gems, TRUE, "", "")
);
printf("\n");
@@ -281,7 +344,7 @@ make_gem_init(char active_gems[1024])
printf("void\n"
"mrb_init_mrbgems(mrb_state *mrb) {\n");
printf( "%s",
- for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", FALSE, active_gems, TRUE)
+ for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", FALSE, active_gems, TRUE, "", "")
);
printf("}");
}
@@ -363,6 +426,7 @@ make_gem_srclib(char gem_name[1024])
" */\n\n"
"#include \"mruby.h\"\n");
+ /* Prototype method for GEM initialization */
printf("\n"
"void mrb_%s_gem_init(mrb_state*);\n", gem_name);
@@ -384,6 +448,7 @@ make_gem_srclib(char gem_name[1024])
static void
make_gem_mixlib(char gem_name[1024])
{
+ /* Prototype method for GEM initialization */
printf("\n"
"void mrb_%s_gem_init(mrb_state*);\n", gem_name);
@@ -419,9 +484,7 @@ main (int argc, char *argv[])
}
}
else if (argc == 3) {
- if (strcmp(argv[1], "makefile") == 0)
- make_gem_makefile(argv[2]);
- else if (strcmp(argv[1], "makefile_list") == 0)
+ if (strcmp(argv[1], "makefile_list") == 0)
make_gem_makefile_list(argv[2]);
else if (strcmp(argv[1], "gem_init") == 0)
make_gem_init(argv[2]);
@@ -436,6 +499,14 @@ main (int argc, char *argv[])
return 1;
}
}
+ else if (argc == 4) {
+ if (strcmp(argv[1], "makefile") == 0)
+ make_gem_makefile(argv[2], argv[3]);
+ else {
+ printf("%s", argument_info);
+ return 1;
+ }
+ }
else {
printf("%s", argument_info);
return 1;