From 738a8775e91a883db2a5764b2597d24f99bb0ce3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:22:32 +0900 Subject: change global Makefile by adding mrbgems to it --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 2df86c949..21cd57685 100644 --- a/Makefile +++ b/Makefile @@ -43,6 +43,7 @@ export CAT := cat .PHONY : all all : @$(MAKE) -C src $(MAKE_FLAGS) + @$(MAKE) -C mrbgems $(MAKE_FLAGS) @$(MAKE) -C mrblib $(MAKE_FLAGS) @$(MAKE) -C tools/mruby $(MAKE_FLAGS) @$(MAKE) -C tools/mirb $(MAKE_FLAGS) @@ -56,6 +57,7 @@ test : all .PHONY : clean clean : @$(MAKE) clean -C src $(MAKE_FLAGS) + @$(MAKE) clean -C mrbgems $(MAKE_FLAGS) @$(MAKE) clean -C tools/mruby $(MAKE_FLAGS) @$(MAKE) clean -C tools/mirb $(MAKE_FLAGS) @$(MAKE) clean -C test $(MAKE_FLAGS) -- cgit v1.2.3 From 50c21a9350b418fb1b44840f5ae80b6a52dc105a Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:22:56 +0900 Subject: Change mrblib Makefile to include gems --- mrblib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrblib/Makefile b/mrblib/Makefile index 6d7ac65f9..9b6badd09 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -55,7 +55,7 @@ all : $(LIBR) # update libmruby.a $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) - $(AR) r $(LIBR) $(MLIB) + $(AR) rs $(LIBR) ../mrbgems/md5/md5.o ../mrbgems/md5/mrb_md5.o ../mrbgems/init_gems.o $(MLIB) # Compile mrblib source $(MLIB) : $(CLIB) -- cgit v1.2.3 From d3d21cbdfeb656f028e9ab3096119e3c06d7c827 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:23:25 +0900 Subject: Add init function for gems to init of core --- src/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/init.c b/src/init.c index 52fd9e118..1a7e72686 100644 --- a/src/init.c +++ b/src/init.c @@ -27,6 +27,7 @@ void mrb_init_print(mrb_state*); void mrb_init_time(mrb_state*); void mrb_init_math(mrb_state*); void mrb_init_mrblib(mrb_state*); +void mrb_init_mrbgems(mrb_state*); void @@ -66,6 +67,7 @@ mrb_init_core(mrb_state *mrb) #endif mrb_init_mrblib(mrb); + mrb_init_mrbgems(mrb); mrb_gc_arena_restore(mrb, 0); } -- cgit v1.2.3 From cd72971adc76143c7b652ecdafe0c4acaf50904b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:23:51 +0900 Subject: make mrbc aware of the gem init --- tools/mrbc/mrbc.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 5382b90a8..62bc34700 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -212,3 +212,8 @@ void mrb_init_mrblib(mrb_state *mrb) { } + +void +mrb_init_mrbgems(mrb_state *mrb) +{ +} -- cgit v1.2.3 From f89e722ef09211d3e5b39344c6df66217966f8df Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:24:16 +0900 Subject: Add a first implementation of mrbgems with one fixed MD5 gem --- mrbgems/Makefile | 22 +++ mrbgems/init_gems.c | 16 +++ mrbgems/md5/Makefile | 20 +++ mrbgems/md5/README.md | 4 + mrbgems/md5/md5.c | 381 ++++++++++++++++++++++++++++++++++++++++++++++++++ mrbgems/md5/md5.h | 91 ++++++++++++ mrbgems/md5/mrb_md5.c | 56 ++++++++ mrbgems/md5/mrb_md5.h | 6 + 8 files changed, 596 insertions(+) create mode 100644 mrbgems/Makefile create mode 100644 mrbgems/init_gems.c create mode 100644 mrbgems/md5/Makefile create mode 100644 mrbgems/md5/README.md create mode 100644 mrbgems/md5/md5.c create mode 100644 mrbgems/md5/md5.h create mode 100644 mrbgems/md5/mrb_md5.c create mode 100644 mrbgems/md5/mrb_md5.h diff --git a/mrbgems/Makefile b/mrbgems/Makefile new file mode 100644 index 000000000..7f2157032 --- /dev/null +++ b/mrbgems/Makefile @@ -0,0 +1,22 @@ +# makefile description. +# add gems to the ruby library + +LIBRGEMS := ../lib/libmruby_gems.a +INIT := init_gems +RM_F := rm -f +CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include + +############################## +# generic build targets, rules + +.PHONY : all +all : $(INIT).o + +$(INIT).o : $(INIT).c + gcc $(CC_FLAGS) -c $(INIT).c -o $(INIT).o + @$(MAKE) -C md5 + +.PHONY : clean +clean : + $(RM_F) $(INIT).o $(INIT).d $(LIBRGEMS) + @$(MAKE) clean -C md5 diff --git a/mrbgems/init_gems.c b/mrbgems/init_gems.c new file mode 100644 index 000000000..302720da4 --- /dev/null +++ b/mrbgems/init_gems.c @@ -0,0 +1,16 @@ +/* + * This file will contain a list of all + * initializing methods necessary to + * bootstrap every gem. + * + */ + +#include "mruby.h" + +void mrb_md5_gem_init(mrb_state*); + +void +mrb_init_mrbgems(mrb_state *mrb) +{ + mrb_md5_gem_init(mrb); +} diff --git a/mrbgems/md5/Makefile b/mrbgems/md5/Makefile new file mode 100644 index 000000000..0605d66a4 --- /dev/null +++ b/mrbgems/md5/Makefile @@ -0,0 +1,20 @@ +MRUBY_ROOT = ../.. + +INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. +CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration + +CC = gcc +LL = gcc +AR = ar + +all : md5.o mrb_md5.o + @echo done + +md5.o : md5.c md5.h + gcc -c -I. md5.c + +mrb_md5.o : mrb_md5.c mrb_md5.h + gcc -c $(CFLAGS) mrb_md5.c + +clean : + rm -f *.o diff --git a/mrbgems/md5/README.md b/mrbgems/md5/README.md new file mode 100644 index 000000000..c96475aa1 --- /dev/null +++ b/mrbgems/md5/README.md @@ -0,0 +1,4 @@ +mruby-md5 +========= + +MD5 digest function diff --git a/mrbgems/md5/md5.c b/mrbgems/md5/md5.c new file mode 100644 index 000000000..c35d96c5e --- /dev/null +++ b/mrbgems/md5/md5.c @@ -0,0 +1,381 @@ +/* + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.c is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order + either statically or dynamically; added missing #include + in library. + 2002-03-11 lpd Corrected argument list for main(), and added int return + type, in test program and T value program. + 2002-02-21 lpd Added missing #include in test program. + 2000-07-03 lpd Patched to eliminate warnings about "constant is + unsigned in ANSI C, signed in traditional"; made test program + self-checking. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). + 1999-05-03 lpd Original version. + */ + +#include "md5.h" +#include + +#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ +#ifdef ARCH_IS_BIG_ENDIAN +# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) +#else +# define BYTE_ORDER 0 +#endif + +#define T_MASK ((md5_word_t)~0) +#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) +#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) +#define T3 0x242070db +#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) +#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) +#define T6 0x4787c62a +#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) +#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) +#define T9 0x698098d8 +#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) +#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) +#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) +#define T13 0x6b901122 +#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) +#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) +#define T16 0x49b40821 +#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) +#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) +#define T19 0x265e5a51 +#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) +#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) +#define T22 0x02441453 +#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) +#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) +#define T25 0x21e1cde6 +#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) +#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) +#define T28 0x455a14ed +#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) +#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) +#define T31 0x676f02d9 +#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) +#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) +#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) +#define T35 0x6d9d6122 +#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) +#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) +#define T38 0x4bdecfa9 +#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) +#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) +#define T41 0x289b7ec6 +#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) +#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) +#define T44 0x04881d05 +#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) +#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) +#define T47 0x1fa27cf8 +#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) +#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) +#define T50 0x432aff97 +#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) +#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) +#define T53 0x655b59c3 +#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) +#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) +#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) +#define T57 0x6fa87e4f +#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) +#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) +#define T60 0x4e0811a1 +#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) +#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) +#define T63 0x2ad7d2bb +#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) + + +static void +md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) +{ + md5_word_t + a = pms->abcd[0], b = pms->abcd[1], + c = pms->abcd[2], d = pms->abcd[3]; + md5_word_t t; +#if BYTE_ORDER > 0 + /* Define storage only for big-endian CPUs. */ + md5_word_t X[16]; +#else + /* Define storage for little-endian or both types of CPUs. */ + md5_word_t xbuf[16]; + const md5_word_t *X; +#endif + + { +#if BYTE_ORDER == 0 + /* + * Determine dynamically whether this is a big-endian or + * little-endian machine, since we can use a more efficient + * algorithm on the latter. + */ + static const int w = 1; + + if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ +#endif +#if BYTE_ORDER <= 0 /* little-endian */ + { + /* + * On little-endian machines, we can process properly aligned + * data without copying it. + */ + if (!((data - (const md5_byte_t *)0) & 3)) { + /* data are properly aligned */ + X = (const md5_word_t *)data; + } else { + /* not aligned */ + memcpy(xbuf, data, 64); + X = xbuf; + } + } +#endif +#if BYTE_ORDER == 0 + else /* dynamic big-endian */ +#endif +#if BYTE_ORDER >= 0 /* big-endian */ + { + /* + * On big-endian machines, we must arrange the bytes in the + * right order. + */ + const md5_byte_t *xp = data; + int i; + +# if BYTE_ORDER == 0 + X = xbuf; /* (dynamic only) */ +# else +# define xbuf X /* (static only) */ +# endif + for (i = 0; i < 16; ++i, xp += 4) + xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); + } +#endif + } + +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + + /* Round 1. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ +#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + F(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 7, T1); + SET(d, a, b, c, 1, 12, T2); + SET(c, d, a, b, 2, 17, T3); + SET(b, c, d, a, 3, 22, T4); + SET(a, b, c, d, 4, 7, T5); + SET(d, a, b, c, 5, 12, T6); + SET(c, d, a, b, 6, 17, T7); + SET(b, c, d, a, 7, 22, T8); + SET(a, b, c, d, 8, 7, T9); + SET(d, a, b, c, 9, 12, T10); + SET(c, d, a, b, 10, 17, T11); + SET(b, c, d, a, 11, 22, T12); + SET(a, b, c, d, 12, 7, T13); + SET(d, a, b, c, 13, 12, T14); + SET(c, d, a, b, 14, 17, T15); + SET(b, c, d, a, 15, 22, T16); +#undef SET + + /* Round 2. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ +#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + G(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 1, 5, T17); + SET(d, a, b, c, 6, 9, T18); + SET(c, d, a, b, 11, 14, T19); + SET(b, c, d, a, 0, 20, T20); + SET(a, b, c, d, 5, 5, T21); + SET(d, a, b, c, 10, 9, T22); + SET(c, d, a, b, 15, 14, T23); + SET(b, c, d, a, 4, 20, T24); + SET(a, b, c, d, 9, 5, T25); + SET(d, a, b, c, 14, 9, T26); + SET(c, d, a, b, 3, 14, T27); + SET(b, c, d, a, 8, 20, T28); + SET(a, b, c, d, 13, 5, T29); + SET(d, a, b, c, 2, 9, T30); + SET(c, d, a, b, 7, 14, T31); + SET(b, c, d, a, 12, 20, T32); +#undef SET + + /* Round 3. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + H(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 5, 4, T33); + SET(d, a, b, c, 8, 11, T34); + SET(c, d, a, b, 11, 16, T35); + SET(b, c, d, a, 14, 23, T36); + SET(a, b, c, d, 1, 4, T37); + SET(d, a, b, c, 4, 11, T38); + SET(c, d, a, b, 7, 16, T39); + SET(b, c, d, a, 10, 23, T40); + SET(a, b, c, d, 13, 4, T41); + SET(d, a, b, c, 0, 11, T42); + SET(c, d, a, b, 3, 16, T43); + SET(b, c, d, a, 6, 23, T44); + SET(a, b, c, d, 9, 4, T45); + SET(d, a, b, c, 12, 11, T46); + SET(c, d, a, b, 15, 16, T47); + SET(b, c, d, a, 2, 23, T48); +#undef SET + + /* Round 4. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ +#define I(x, y, z) ((y) ^ ((x) | ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + I(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 6, T49); + SET(d, a, b, c, 7, 10, T50); + SET(c, d, a, b, 14, 15, T51); + SET(b, c, d, a, 5, 21, T52); + SET(a, b, c, d, 12, 6, T53); + SET(d, a, b, c, 3, 10, T54); + SET(c, d, a, b, 10, 15, T55); + SET(b, c, d, a, 1, 21, T56); + SET(a, b, c, d, 8, 6, T57); + SET(d, a, b, c, 15, 10, T58); + SET(c, d, a, b, 6, 15, T59); + SET(b, c, d, a, 13, 21, T60); + SET(a, b, c, d, 4, 6, T61); + SET(d, a, b, c, 11, 10, T62); + SET(c, d, a, b, 2, 15, T63); + SET(b, c, d, a, 9, 21, T64); +#undef SET + + /* Then perform the following additions. (That is increment each + of the four registers by the value it had before this block + was started.) */ + pms->abcd[0] += a; + pms->abcd[1] += b; + pms->abcd[2] += c; + pms->abcd[3] += d; +} + +void +md5_init(md5_state_t *pms) +{ + pms->count[0] = pms->count[1] = 0; + pms->abcd[0] = 0x67452301; + pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; + pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; + pms->abcd[3] = 0x10325476; +} + +void +md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) +{ + const md5_byte_t *p = data; + int left = nbytes; + int offset = (pms->count[0] >> 3) & 63; + md5_word_t nbits = (md5_word_t)(nbytes << 3); + + if (nbytes <= 0) + return; + + /* Update the message length. */ + pms->count[1] += nbytes >> 29; + pms->count[0] += nbits; + if (pms->count[0] < nbits) + pms->count[1]++; + + /* Process an initial partial block. */ + if (offset) { + int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); + + memcpy(pms->buf + offset, p, copy); + if (offset + copy < 64) + return; + p += copy; + left -= copy; + md5_process(pms, pms->buf); + } + + /* Process full blocks. */ + for (; left >= 64; p += 64, left -= 64) + md5_process(pms, p); + + /* Process a final partial block. */ + if (left) + memcpy(pms->buf, p, left); +} + +void +md5_finish(md5_state_t *pms, md5_byte_t digest[16]) +{ + static const md5_byte_t pad[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + md5_byte_t data[8]; + int i; + + /* Save the length before padding. */ + for (i = 0; i < 8; ++i) + data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + /* Pad to 56 bytes mod 64. */ + md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); + /* Append the length. */ + md5_append(pms, data, 8); + for (i = 0; i < 16; ++i) + digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); +} diff --git a/mrbgems/md5/md5.h b/mrbgems/md5/md5.h new file mode 100644 index 000000000..698c995d8 --- /dev/null +++ b/mrbgems/md5/md5.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.h is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Removed support for non-ANSI compilers; removed + references to Ghostscript; clarified derivation from RFC 1321; + now handles byte order either statically or dynamically. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); + added conditionalization for C++ compilation from Martin + Purschke . + 1999-05-03 lpd Original version. + */ + +#ifndef md5_INCLUDED +# define md5_INCLUDED + +/* + * This package supports both compile-time and run-time determination of CPU + * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be + * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is + * defined as non-zero, the code will be compiled to run only on big-endian + * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to + * run on either big- or little-endian CPUs, but will run slightly less + * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. + */ + +typedef unsigned char md5_byte_t; /* 8-bit byte */ +typedef unsigned int md5_word_t; /* 32-bit word */ + +/* Define the state of the MD5 Algorithm. */ +typedef struct md5_state_s { + md5_word_t count[2]; /* message length in bits, lsw first */ + md5_word_t abcd[4]; /* digest buffer */ + md5_byte_t buf[64]; /* accumulate block */ +} md5_state_t; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Initialize the algorithm. */ +void md5_init(md5_state_t *pms); + +/* Append a string to the message. */ +void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); + +/* Finish the message and return the digest. */ +void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* md5_INCLUDED */ diff --git a/mrbgems/md5/mrb_md5.c b/mrbgems/md5/mrb_md5.c new file mode 100644 index 000000000..6df453b0e --- /dev/null +++ b/mrbgems/md5/mrb_md5.c @@ -0,0 +1,56 @@ +#include +#include +#include "md5.h" + +static struct RClass *_class_md5; + +/********************************************************* + * main + *********************************************************/ + +static char +nr2char(int n) { + if (0 <= n && n <= 9) { + return '0' + n; + } else { + return 'a' + n - 10; + } +} + +static mrb_value +mrb_md5_hex(mrb_state *mrb, mrb_value self) +{ + md5_state_t pms; + md5_byte_t digest[16]; + md5_byte_t digest_hex[33]; + mrb_value arg; + int i; + + mrb_get_args(mrb, "o", &arg); + if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); + } + + md5_init(&pms); + md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); + md5_finish(&pms, digest); + + + for (i = 0; i < 16; i++) { + digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); + digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); + } + digest_hex[32] = 0; + + return mrb_str_new(mrb, (char*) digest_hex, 32); +} + +/********************************************************* + * register + *********************************************************/ + +void +mrb_md5_gem_init(mrb_state* mrb) { + _class_md5 = mrb_define_module(mrb, "MD5"); + mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); +} diff --git a/mrbgems/md5/mrb_md5.h b/mrbgems/md5/mrb_md5.h new file mode 100644 index 000000000..2f5934017 --- /dev/null +++ b/mrbgems/md5/mrb_md5.h @@ -0,0 +1,6 @@ +#ifndef MRB_MD5_H +#define MRB_MD5_H + +void mrb_md5_gem_init(mrb_state*); + +#endif /* MRB_MD5_H */ -- cgit v1.2.3 From a941934045e9c63eb9a620e3e516b377a42e0943 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 13 Sep 2012 22:31:23 +0900 Subject: Add TODOs to finalize gems --- mrbgems/Makefile | 4 ++++ mrbgems/init_gems.c | 2 ++ mrbgems/md5/README.md | 4 +++- mrblib/Makefile | 5 ++++- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 7f2157032..368488926 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -12,10 +12,14 @@ CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../i .PHONY : all all : $(INIT).o +# @TODO: +# all available GEMS have to be built $(INIT).o : $(INIT).c gcc $(CC_FLAGS) -c $(INIT).c -o $(INIT).o @$(MAKE) -C md5 +# @TODO: +# all available GEMS have to be cleaned .PHONY : clean clean : $(RM_F) $(INIT).o $(INIT).d $(LIBRGEMS) diff --git a/mrbgems/init_gems.c b/mrbgems/init_gems.c index 302720da4..02024d5a2 100644 --- a/mrbgems/init_gems.c +++ b/mrbgems/init_gems.c @@ -3,6 +3,8 @@ * initializing methods necessary to * bootstrap every gem. * + * @TODO: + * this file has to be generated based on the active gems */ #include "mruby.h" diff --git a/mrbgems/md5/README.md b/mrbgems/md5/README.md index c96475aa1..d84bb9941 100644 --- a/mrbgems/md5/README.md +++ b/mrbgems/md5/README.md @@ -1,4 +1,6 @@ mruby-md5 ========= -MD5 digest function +MD5 digest function. + +This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrblib/Makefile b/mrblib/Makefile index 9b6badd09..c3817e334 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -14,6 +14,7 @@ MRB1 := $(BASEDIR)/*.rb MRBS := $(MRB1) LIBR0 := ../lib/libmruby_core.a LIBR := ../lib/libmruby.a +GEM0 := ../mrbgems/md5/ # libraries, includes INCLUDES = -I../src -I../include @@ -52,10 +53,12 @@ endif .PHONY : all all : $(LIBR) +# TODO: +# all available GEMS have to be added to the main library # update libmruby.a $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) - $(AR) rs $(LIBR) ../mrbgems/md5/md5.o ../mrbgems/md5/mrb_md5.o ../mrbgems/init_gems.o $(MLIB) + $(AR) rs $(LIBR) $(GEM0)md5.o $(GEM0)mrb_md5.o ../mrbgems/init_gems.o $(MLIB) # Compile mrblib source $(MLIB) : $(CLIB) -- cgit v1.2.3 From 85bc533f90f6fac78bdf74b2f5b2e69a715d4049 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 15 Sep 2012 15:40:20 +0900 Subject: Small modifications for location --- mrbgems/md5/Makefile | 16 ++++++---------- mrblib/Makefile | 2 +- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/mrbgems/md5/Makefile b/mrbgems/md5/Makefile index 0605d66a4..5ea2597c6 100644 --- a/mrbgems/md5/Makefile +++ b/mrbgems/md5/Makefile @@ -3,18 +3,14 @@ MRUBY_ROOT = ../.. INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration -CC = gcc -LL = gcc -AR = ar - -all : md5.o mrb_md5.o +all : src/md5.o src/mrb_md5.o @echo done -md5.o : md5.c md5.h - gcc -c -I. md5.c +md5.o : src/md5.c + gcc -c -I. src/md5.c -mrb_md5.o : mrb_md5.c mrb_md5.h - gcc -c $(CFLAGS) mrb_md5.c +mrb_md5.o : src/mrb_md5.c + gcc -c $(CFLAGS) src/mrb_md5.c clean : - rm -f *.o + rm -f src/*.o diff --git a/mrblib/Makefile b/mrblib/Makefile index c3817e334..fe0b816fb 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -14,7 +14,7 @@ MRB1 := $(BASEDIR)/*.rb MRBS := $(MRB1) LIBR0 := ../lib/libmruby_core.a LIBR := ../lib/libmruby.a -GEM0 := ../mrbgems/md5/ +GEM0 := ../mrbgems/md5/src/ # libraries, includes INCLUDES = -I../src -I../include -- cgit v1.2.3 From 0101e47a27a084724de35db58a6b182c941aacc3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 15 Sep 2012 15:47:43 +0900 Subject: Relocated md5 source --- mrbgems/md5/src/md5.c | 381 ++++++++++++++++++++++++++++++++++++++++++++++ mrbgems/md5/src/md5.h | 91 +++++++++++ mrbgems/md5/src/mrb_md5.c | 56 +++++++ mrbgems/md5/src/mrb_md5.h | 6 + 4 files changed, 534 insertions(+) create mode 100644 mrbgems/md5/src/md5.c create mode 100644 mrbgems/md5/src/md5.h create mode 100644 mrbgems/md5/src/mrb_md5.c create mode 100644 mrbgems/md5/src/mrb_md5.h diff --git a/mrbgems/md5/src/md5.c b/mrbgems/md5/src/md5.c new file mode 100644 index 000000000..c35d96c5e --- /dev/null +++ b/mrbgems/md5/src/md5.c @@ -0,0 +1,381 @@ +/* + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.c is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order + either statically or dynamically; added missing #include + in library. + 2002-03-11 lpd Corrected argument list for main(), and added int return + type, in test program and T value program. + 2002-02-21 lpd Added missing #include in test program. + 2000-07-03 lpd Patched to eliminate warnings about "constant is + unsigned in ANSI C, signed in traditional"; made test program + self-checking. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). + 1999-05-03 lpd Original version. + */ + +#include "md5.h" +#include + +#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ +#ifdef ARCH_IS_BIG_ENDIAN +# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) +#else +# define BYTE_ORDER 0 +#endif + +#define T_MASK ((md5_word_t)~0) +#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) +#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) +#define T3 0x242070db +#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) +#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) +#define T6 0x4787c62a +#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) +#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) +#define T9 0x698098d8 +#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) +#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) +#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) +#define T13 0x6b901122 +#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) +#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) +#define T16 0x49b40821 +#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) +#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) +#define T19 0x265e5a51 +#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) +#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) +#define T22 0x02441453 +#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) +#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) +#define T25 0x21e1cde6 +#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) +#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) +#define T28 0x455a14ed +#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) +#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) +#define T31 0x676f02d9 +#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) +#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) +#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) +#define T35 0x6d9d6122 +#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) +#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) +#define T38 0x4bdecfa9 +#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) +#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) +#define T41 0x289b7ec6 +#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) +#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) +#define T44 0x04881d05 +#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) +#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) +#define T47 0x1fa27cf8 +#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) +#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) +#define T50 0x432aff97 +#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) +#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) +#define T53 0x655b59c3 +#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) +#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) +#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) +#define T57 0x6fa87e4f +#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) +#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) +#define T60 0x4e0811a1 +#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) +#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) +#define T63 0x2ad7d2bb +#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) + + +static void +md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) +{ + md5_word_t + a = pms->abcd[0], b = pms->abcd[1], + c = pms->abcd[2], d = pms->abcd[3]; + md5_word_t t; +#if BYTE_ORDER > 0 + /* Define storage only for big-endian CPUs. */ + md5_word_t X[16]; +#else + /* Define storage for little-endian or both types of CPUs. */ + md5_word_t xbuf[16]; + const md5_word_t *X; +#endif + + { +#if BYTE_ORDER == 0 + /* + * Determine dynamically whether this is a big-endian or + * little-endian machine, since we can use a more efficient + * algorithm on the latter. + */ + static const int w = 1; + + if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ +#endif +#if BYTE_ORDER <= 0 /* little-endian */ + { + /* + * On little-endian machines, we can process properly aligned + * data without copying it. + */ + if (!((data - (const md5_byte_t *)0) & 3)) { + /* data are properly aligned */ + X = (const md5_word_t *)data; + } else { + /* not aligned */ + memcpy(xbuf, data, 64); + X = xbuf; + } + } +#endif +#if BYTE_ORDER == 0 + else /* dynamic big-endian */ +#endif +#if BYTE_ORDER >= 0 /* big-endian */ + { + /* + * On big-endian machines, we must arrange the bytes in the + * right order. + */ + const md5_byte_t *xp = data; + int i; + +# if BYTE_ORDER == 0 + X = xbuf; /* (dynamic only) */ +# else +# define xbuf X /* (static only) */ +# endif + for (i = 0; i < 16; ++i, xp += 4) + xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); + } +#endif + } + +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + + /* Round 1. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ +#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + F(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 7, T1); + SET(d, a, b, c, 1, 12, T2); + SET(c, d, a, b, 2, 17, T3); + SET(b, c, d, a, 3, 22, T4); + SET(a, b, c, d, 4, 7, T5); + SET(d, a, b, c, 5, 12, T6); + SET(c, d, a, b, 6, 17, T7); + SET(b, c, d, a, 7, 22, T8); + SET(a, b, c, d, 8, 7, T9); + SET(d, a, b, c, 9, 12, T10); + SET(c, d, a, b, 10, 17, T11); + SET(b, c, d, a, 11, 22, T12); + SET(a, b, c, d, 12, 7, T13); + SET(d, a, b, c, 13, 12, T14); + SET(c, d, a, b, 14, 17, T15); + SET(b, c, d, a, 15, 22, T16); +#undef SET + + /* Round 2. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ +#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + G(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 1, 5, T17); + SET(d, a, b, c, 6, 9, T18); + SET(c, d, a, b, 11, 14, T19); + SET(b, c, d, a, 0, 20, T20); + SET(a, b, c, d, 5, 5, T21); + SET(d, a, b, c, 10, 9, T22); + SET(c, d, a, b, 15, 14, T23); + SET(b, c, d, a, 4, 20, T24); + SET(a, b, c, d, 9, 5, T25); + SET(d, a, b, c, 14, 9, T26); + SET(c, d, a, b, 3, 14, T27); + SET(b, c, d, a, 8, 20, T28); + SET(a, b, c, d, 13, 5, T29); + SET(d, a, b, c, 2, 9, T30); + SET(c, d, a, b, 7, 14, T31); + SET(b, c, d, a, 12, 20, T32); +#undef SET + + /* Round 3. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + H(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 5, 4, T33); + SET(d, a, b, c, 8, 11, T34); + SET(c, d, a, b, 11, 16, T35); + SET(b, c, d, a, 14, 23, T36); + SET(a, b, c, d, 1, 4, T37); + SET(d, a, b, c, 4, 11, T38); + SET(c, d, a, b, 7, 16, T39); + SET(b, c, d, a, 10, 23, T40); + SET(a, b, c, d, 13, 4, T41); + SET(d, a, b, c, 0, 11, T42); + SET(c, d, a, b, 3, 16, T43); + SET(b, c, d, a, 6, 23, T44); + SET(a, b, c, d, 9, 4, T45); + SET(d, a, b, c, 12, 11, T46); + SET(c, d, a, b, 15, 16, T47); + SET(b, c, d, a, 2, 23, T48); +#undef SET + + /* Round 4. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ +#define I(x, y, z) ((y) ^ ((x) | ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + I(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 6, T49); + SET(d, a, b, c, 7, 10, T50); + SET(c, d, a, b, 14, 15, T51); + SET(b, c, d, a, 5, 21, T52); + SET(a, b, c, d, 12, 6, T53); + SET(d, a, b, c, 3, 10, T54); + SET(c, d, a, b, 10, 15, T55); + SET(b, c, d, a, 1, 21, T56); + SET(a, b, c, d, 8, 6, T57); + SET(d, a, b, c, 15, 10, T58); + SET(c, d, a, b, 6, 15, T59); + SET(b, c, d, a, 13, 21, T60); + SET(a, b, c, d, 4, 6, T61); + SET(d, a, b, c, 11, 10, T62); + SET(c, d, a, b, 2, 15, T63); + SET(b, c, d, a, 9, 21, T64); +#undef SET + + /* Then perform the following additions. (That is increment each + of the four registers by the value it had before this block + was started.) */ + pms->abcd[0] += a; + pms->abcd[1] += b; + pms->abcd[2] += c; + pms->abcd[3] += d; +} + +void +md5_init(md5_state_t *pms) +{ + pms->count[0] = pms->count[1] = 0; + pms->abcd[0] = 0x67452301; + pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; + pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; + pms->abcd[3] = 0x10325476; +} + +void +md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) +{ + const md5_byte_t *p = data; + int left = nbytes; + int offset = (pms->count[0] >> 3) & 63; + md5_word_t nbits = (md5_word_t)(nbytes << 3); + + if (nbytes <= 0) + return; + + /* Update the message length. */ + pms->count[1] += nbytes >> 29; + pms->count[0] += nbits; + if (pms->count[0] < nbits) + pms->count[1]++; + + /* Process an initial partial block. */ + if (offset) { + int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); + + memcpy(pms->buf + offset, p, copy); + if (offset + copy < 64) + return; + p += copy; + left -= copy; + md5_process(pms, pms->buf); + } + + /* Process full blocks. */ + for (; left >= 64; p += 64, left -= 64) + md5_process(pms, p); + + /* Process a final partial block. */ + if (left) + memcpy(pms->buf, p, left); +} + +void +md5_finish(md5_state_t *pms, md5_byte_t digest[16]) +{ + static const md5_byte_t pad[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + md5_byte_t data[8]; + int i; + + /* Save the length before padding. */ + for (i = 0; i < 8; ++i) + data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + /* Pad to 56 bytes mod 64. */ + md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); + /* Append the length. */ + md5_append(pms, data, 8); + for (i = 0; i < 16; ++i) + digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); +} diff --git a/mrbgems/md5/src/md5.h b/mrbgems/md5/src/md5.h new file mode 100644 index 000000000..698c995d8 --- /dev/null +++ b/mrbgems/md5/src/md5.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.h is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Removed support for non-ANSI compilers; removed + references to Ghostscript; clarified derivation from RFC 1321; + now handles byte order either statically or dynamically. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); + added conditionalization for C++ compilation from Martin + Purschke . + 1999-05-03 lpd Original version. + */ + +#ifndef md5_INCLUDED +# define md5_INCLUDED + +/* + * This package supports both compile-time and run-time determination of CPU + * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be + * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is + * defined as non-zero, the code will be compiled to run only on big-endian + * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to + * run on either big- or little-endian CPUs, but will run slightly less + * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. + */ + +typedef unsigned char md5_byte_t; /* 8-bit byte */ +typedef unsigned int md5_word_t; /* 32-bit word */ + +/* Define the state of the MD5 Algorithm. */ +typedef struct md5_state_s { + md5_word_t count[2]; /* message length in bits, lsw first */ + md5_word_t abcd[4]; /* digest buffer */ + md5_byte_t buf[64]; /* accumulate block */ +} md5_state_t; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Initialize the algorithm. */ +void md5_init(md5_state_t *pms); + +/* Append a string to the message. */ +void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); + +/* Finish the message and return the digest. */ +void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* md5_INCLUDED */ diff --git a/mrbgems/md5/src/mrb_md5.c b/mrbgems/md5/src/mrb_md5.c new file mode 100644 index 000000000..6df453b0e --- /dev/null +++ b/mrbgems/md5/src/mrb_md5.c @@ -0,0 +1,56 @@ +#include +#include +#include "md5.h" + +static struct RClass *_class_md5; + +/********************************************************* + * main + *********************************************************/ + +static char +nr2char(int n) { + if (0 <= n && n <= 9) { + return '0' + n; + } else { + return 'a' + n - 10; + } +} + +static mrb_value +mrb_md5_hex(mrb_state *mrb, mrb_value self) +{ + md5_state_t pms; + md5_byte_t digest[16]; + md5_byte_t digest_hex[33]; + mrb_value arg; + int i; + + mrb_get_args(mrb, "o", &arg); + if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); + } + + md5_init(&pms); + md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); + md5_finish(&pms, digest); + + + for (i = 0; i < 16; i++) { + digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); + digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); + } + digest_hex[32] = 0; + + return mrb_str_new(mrb, (char*) digest_hex, 32); +} + +/********************************************************* + * register + *********************************************************/ + +void +mrb_md5_gem_init(mrb_state* mrb) { + _class_md5 = mrb_define_module(mrb, "MD5"); + mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); +} diff --git a/mrbgems/md5/src/mrb_md5.h b/mrbgems/md5/src/mrb_md5.h new file mode 100644 index 000000000..2f5934017 --- /dev/null +++ b/mrbgems/md5/src/mrb_md5.h @@ -0,0 +1,6 @@ +#ifndef MRB_MD5_H +#define MRB_MD5_H + +void mrb_md5_gem_init(mrb_state*); + +#endif /* MRB_MD5_H */ -- cgit v1.2.3 From 3ee1565c7ba24f0ff6894288ce487265dbe56cdf Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 15 Sep 2012 15:50:34 +0900 Subject: Remove old location of md5 source --- mrbgems/md5/md5.c | 381 -------------------------------------------------- mrbgems/md5/md5.h | 91 ------------ mrbgems/md5/mrb_md5.c | 56 -------- mrbgems/md5/mrb_md5.h | 6 - 4 files changed, 534 deletions(-) delete mode 100644 mrbgems/md5/md5.c delete mode 100644 mrbgems/md5/md5.h delete mode 100644 mrbgems/md5/mrb_md5.c delete mode 100644 mrbgems/md5/mrb_md5.h diff --git a/mrbgems/md5/md5.c b/mrbgems/md5/md5.c deleted file mode 100644 index c35d96c5e..000000000 --- a/mrbgems/md5/md5.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} diff --git a/mrbgems/md5/md5.h b/mrbgems/md5/md5.h deleted file mode 100644 index 698c995d8..000000000 --- a/mrbgems/md5/md5.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke . - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ diff --git a/mrbgems/md5/mrb_md5.c b/mrbgems/md5/mrb_md5.c deleted file mode 100644 index 6df453b0e..000000000 --- a/mrbgems/md5/mrb_md5.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include "md5.h" - -static struct RClass *_class_md5; - -/********************************************************* - * main - *********************************************************/ - -static char -nr2char(int n) { - if (0 <= n && n <= 9) { - return '0' + n; - } else { - return 'a' + n - 10; - } -} - -static mrb_value -mrb_md5_hex(mrb_state *mrb, mrb_value self) -{ - md5_state_t pms; - md5_byte_t digest[16]; - md5_byte_t digest_hex[33]; - mrb_value arg; - int i; - - mrb_get_args(mrb, "o", &arg); - if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); - } - - md5_init(&pms); - md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); - md5_finish(&pms, digest); - - - for (i = 0; i < 16; i++) { - digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); - digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); - } - digest_hex[32] = 0; - - return mrb_str_new(mrb, (char*) digest_hex, 32); -} - -/********************************************************* - * register - *********************************************************/ - -void -mrb_md5_gem_init(mrb_state* mrb) { - _class_md5 = mrb_define_module(mrb, "MD5"); - mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); -} diff --git a/mrbgems/md5/mrb_md5.h b/mrbgems/md5/mrb_md5.h deleted file mode 100644 index 2f5934017..000000000 --- a/mrbgems/md5/mrb_md5.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MRB_MD5_H -#define MRB_MD5_H - -void mrb_md5_gem_init(mrb_state*); - -#endif /* MRB_MD5_H */ -- cgit v1.2.3 From ac235e25e54c55784b175cf9e66b8db89a54bd44 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 17 Sep 2012 10:23:51 +0900 Subject: Relocate files --- mrbgems/Makefile | 22 +-- mrbgems/g/md5/Makefile | 16 ++ mrbgems/g/md5/README.md | 6 + mrbgems/g/md5/src/md5.c | 381 ++++++++++++++++++++++++++++++++++++++++++++ mrbgems/g/md5/src/md5.h | 91 +++++++++++ mrbgems/g/md5/src/mrb_md5.c | 56 +++++++ mrbgems/g/md5/src/mrb_md5.h | 6 + mrbgems/md5/Makefile | 16 -- mrbgems/md5/README.md | 6 - mrbgems/md5/src/md5.c | 381 -------------------------------------------- mrbgems/md5/src/md5.h | 91 ----------- mrbgems/md5/src/mrb_md5.c | 56 ------- mrbgems/md5/src/mrb_md5.h | 6 - 13 files changed, 568 insertions(+), 566 deletions(-) create mode 100644 mrbgems/g/md5/Makefile create mode 100644 mrbgems/g/md5/README.md create mode 100644 mrbgems/g/md5/src/md5.c create mode 100644 mrbgems/g/md5/src/md5.h create mode 100644 mrbgems/g/md5/src/mrb_md5.c create mode 100644 mrbgems/g/md5/src/mrb_md5.h delete mode 100644 mrbgems/md5/Makefile delete mode 100644 mrbgems/md5/README.md delete mode 100644 mrbgems/md5/src/md5.c delete mode 100644 mrbgems/md5/src/md5.h delete mode 100644 mrbgems/md5/src/mrb_md5.c delete mode 100644 mrbgems/md5/src/mrb_md5.h diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 368488926..b8f35f2a9 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -5,22 +5,24 @@ LIBRGEMS := ../lib/libmruby_gems.a INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include +GEM_DIRS := $(wildcard g/*) ############################## # generic build targets, rules .PHONY : all -all : $(INIT).o +all : $(GEM_DIRS) + echo $(GEM_DIRS) -# @TODO: -# all available GEMS have to be built -$(INIT).o : $(INIT).c - gcc $(CC_FLAGS) -c $(INIT).c -o $(INIT).o - @$(MAKE) -C md5 +# driver build rule +#$(INIT).o : $(INIT).c +# gcc $(CC_FLAGS) -c $(INIT).c -o $(INIT).o -# @TODO: -# all available GEMS have to be cleaned +$(GEM_DIRS) : + echo $@ + +# clean driver and all gems .PHONY : clean -clean : +clean : g/* $(RM_F) $(INIT).o $(INIT).d $(LIBRGEMS) - @$(MAKE) clean -C md5 + $(MAKE) clean -C $< diff --git a/mrbgems/g/md5/Makefile b/mrbgems/g/md5/Makefile new file mode 100644 index 000000000..a4457c9a6 --- /dev/null +++ b/mrbgems/g/md5/Makefile @@ -0,0 +1,16 @@ +MRUBY_ROOT = ../../.. + +INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. +CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration + +all : src/md5.o src/mrb_md5.o + @echo done + +md5.o : src/md5.c + gcc -c -I. src/md5.c + +mrb_md5.o : src/mrb_md5.c + gcc -c $(CFLAGS) src/mrb_md5.c + +clean : + rm -f src/*.o diff --git a/mrbgems/g/md5/README.md b/mrbgems/g/md5/README.md new file mode 100644 index 000000000..d84bb9941 --- /dev/null +++ b/mrbgems/g/md5/README.md @@ -0,0 +1,6 @@ +mruby-md5 +========= + +MD5 digest function. + +This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/g/md5/src/md5.c b/mrbgems/g/md5/src/md5.c new file mode 100644 index 000000000..c35d96c5e --- /dev/null +++ b/mrbgems/g/md5/src/md5.c @@ -0,0 +1,381 @@ +/* + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.c is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order + either statically or dynamically; added missing #include + in library. + 2002-03-11 lpd Corrected argument list for main(), and added int return + type, in test program and T value program. + 2002-02-21 lpd Added missing #include in test program. + 2000-07-03 lpd Patched to eliminate warnings about "constant is + unsigned in ANSI C, signed in traditional"; made test program + self-checking. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). + 1999-05-03 lpd Original version. + */ + +#include "md5.h" +#include + +#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ +#ifdef ARCH_IS_BIG_ENDIAN +# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) +#else +# define BYTE_ORDER 0 +#endif + +#define T_MASK ((md5_word_t)~0) +#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) +#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) +#define T3 0x242070db +#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) +#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) +#define T6 0x4787c62a +#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) +#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) +#define T9 0x698098d8 +#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) +#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) +#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) +#define T13 0x6b901122 +#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) +#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) +#define T16 0x49b40821 +#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) +#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) +#define T19 0x265e5a51 +#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) +#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) +#define T22 0x02441453 +#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) +#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) +#define T25 0x21e1cde6 +#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) +#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) +#define T28 0x455a14ed +#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) +#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) +#define T31 0x676f02d9 +#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) +#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) +#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) +#define T35 0x6d9d6122 +#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) +#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) +#define T38 0x4bdecfa9 +#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) +#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) +#define T41 0x289b7ec6 +#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) +#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) +#define T44 0x04881d05 +#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) +#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) +#define T47 0x1fa27cf8 +#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) +#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) +#define T50 0x432aff97 +#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) +#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) +#define T53 0x655b59c3 +#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) +#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) +#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) +#define T57 0x6fa87e4f +#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) +#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) +#define T60 0x4e0811a1 +#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) +#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) +#define T63 0x2ad7d2bb +#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) + + +static void +md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) +{ + md5_word_t + a = pms->abcd[0], b = pms->abcd[1], + c = pms->abcd[2], d = pms->abcd[3]; + md5_word_t t; +#if BYTE_ORDER > 0 + /* Define storage only for big-endian CPUs. */ + md5_word_t X[16]; +#else + /* Define storage for little-endian or both types of CPUs. */ + md5_word_t xbuf[16]; + const md5_word_t *X; +#endif + + { +#if BYTE_ORDER == 0 + /* + * Determine dynamically whether this is a big-endian or + * little-endian machine, since we can use a more efficient + * algorithm on the latter. + */ + static const int w = 1; + + if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ +#endif +#if BYTE_ORDER <= 0 /* little-endian */ + { + /* + * On little-endian machines, we can process properly aligned + * data without copying it. + */ + if (!((data - (const md5_byte_t *)0) & 3)) { + /* data are properly aligned */ + X = (const md5_word_t *)data; + } else { + /* not aligned */ + memcpy(xbuf, data, 64); + X = xbuf; + } + } +#endif +#if BYTE_ORDER == 0 + else /* dynamic big-endian */ +#endif +#if BYTE_ORDER >= 0 /* big-endian */ + { + /* + * On big-endian machines, we must arrange the bytes in the + * right order. + */ + const md5_byte_t *xp = data; + int i; + +# if BYTE_ORDER == 0 + X = xbuf; /* (dynamic only) */ +# else +# define xbuf X /* (static only) */ +# endif + for (i = 0; i < 16; ++i, xp += 4) + xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); + } +#endif + } + +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + + /* Round 1. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ +#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + F(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 7, T1); + SET(d, a, b, c, 1, 12, T2); + SET(c, d, a, b, 2, 17, T3); + SET(b, c, d, a, 3, 22, T4); + SET(a, b, c, d, 4, 7, T5); + SET(d, a, b, c, 5, 12, T6); + SET(c, d, a, b, 6, 17, T7); + SET(b, c, d, a, 7, 22, T8); + SET(a, b, c, d, 8, 7, T9); + SET(d, a, b, c, 9, 12, T10); + SET(c, d, a, b, 10, 17, T11); + SET(b, c, d, a, 11, 22, T12); + SET(a, b, c, d, 12, 7, T13); + SET(d, a, b, c, 13, 12, T14); + SET(c, d, a, b, 14, 17, T15); + SET(b, c, d, a, 15, 22, T16); +#undef SET + + /* Round 2. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ +#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + G(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 1, 5, T17); + SET(d, a, b, c, 6, 9, T18); + SET(c, d, a, b, 11, 14, T19); + SET(b, c, d, a, 0, 20, T20); + SET(a, b, c, d, 5, 5, T21); + SET(d, a, b, c, 10, 9, T22); + SET(c, d, a, b, 15, 14, T23); + SET(b, c, d, a, 4, 20, T24); + SET(a, b, c, d, 9, 5, T25); + SET(d, a, b, c, 14, 9, T26); + SET(c, d, a, b, 3, 14, T27); + SET(b, c, d, a, 8, 20, T28); + SET(a, b, c, d, 13, 5, T29); + SET(d, a, b, c, 2, 9, T30); + SET(c, d, a, b, 7, 14, T31); + SET(b, c, d, a, 12, 20, T32); +#undef SET + + /* Round 3. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + H(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 5, 4, T33); + SET(d, a, b, c, 8, 11, T34); + SET(c, d, a, b, 11, 16, T35); + SET(b, c, d, a, 14, 23, T36); + SET(a, b, c, d, 1, 4, T37); + SET(d, a, b, c, 4, 11, T38); + SET(c, d, a, b, 7, 16, T39); + SET(b, c, d, a, 10, 23, T40); + SET(a, b, c, d, 13, 4, T41); + SET(d, a, b, c, 0, 11, T42); + SET(c, d, a, b, 3, 16, T43); + SET(b, c, d, a, 6, 23, T44); + SET(a, b, c, d, 9, 4, T45); + SET(d, a, b, c, 12, 11, T46); + SET(c, d, a, b, 15, 16, T47); + SET(b, c, d, a, 2, 23, T48); +#undef SET + + /* Round 4. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ +#define I(x, y, z) ((y) ^ ((x) | ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + I(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 6, T49); + SET(d, a, b, c, 7, 10, T50); + SET(c, d, a, b, 14, 15, T51); + SET(b, c, d, a, 5, 21, T52); + SET(a, b, c, d, 12, 6, T53); + SET(d, a, b, c, 3, 10, T54); + SET(c, d, a, b, 10, 15, T55); + SET(b, c, d, a, 1, 21, T56); + SET(a, b, c, d, 8, 6, T57); + SET(d, a, b, c, 15, 10, T58); + SET(c, d, a, b, 6, 15, T59); + SET(b, c, d, a, 13, 21, T60); + SET(a, b, c, d, 4, 6, T61); + SET(d, a, b, c, 11, 10, T62); + SET(c, d, a, b, 2, 15, T63); + SET(b, c, d, a, 9, 21, T64); +#undef SET + + /* Then perform the following additions. (That is increment each + of the four registers by the value it had before this block + was started.) */ + pms->abcd[0] += a; + pms->abcd[1] += b; + pms->abcd[2] += c; + pms->abcd[3] += d; +} + +void +md5_init(md5_state_t *pms) +{ + pms->count[0] = pms->count[1] = 0; + pms->abcd[0] = 0x67452301; + pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; + pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; + pms->abcd[3] = 0x10325476; +} + +void +md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) +{ + const md5_byte_t *p = data; + int left = nbytes; + int offset = (pms->count[0] >> 3) & 63; + md5_word_t nbits = (md5_word_t)(nbytes << 3); + + if (nbytes <= 0) + return; + + /* Update the message length. */ + pms->count[1] += nbytes >> 29; + pms->count[0] += nbits; + if (pms->count[0] < nbits) + pms->count[1]++; + + /* Process an initial partial block. */ + if (offset) { + int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); + + memcpy(pms->buf + offset, p, copy); + if (offset + copy < 64) + return; + p += copy; + left -= copy; + md5_process(pms, pms->buf); + } + + /* Process full blocks. */ + for (; left >= 64; p += 64, left -= 64) + md5_process(pms, p); + + /* Process a final partial block. */ + if (left) + memcpy(pms->buf, p, left); +} + +void +md5_finish(md5_state_t *pms, md5_byte_t digest[16]) +{ + static const md5_byte_t pad[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + md5_byte_t data[8]; + int i; + + /* Save the length before padding. */ + for (i = 0; i < 8; ++i) + data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + /* Pad to 56 bytes mod 64. */ + md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); + /* Append the length. */ + md5_append(pms, data, 8); + for (i = 0; i < 16; ++i) + digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); +} diff --git a/mrbgems/g/md5/src/md5.h b/mrbgems/g/md5/src/md5.h new file mode 100644 index 000000000..698c995d8 --- /dev/null +++ b/mrbgems/g/md5/src/md5.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.h is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Removed support for non-ANSI compilers; removed + references to Ghostscript; clarified derivation from RFC 1321; + now handles byte order either statically or dynamically. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); + added conditionalization for C++ compilation from Martin + Purschke . + 1999-05-03 lpd Original version. + */ + +#ifndef md5_INCLUDED +# define md5_INCLUDED + +/* + * This package supports both compile-time and run-time determination of CPU + * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be + * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is + * defined as non-zero, the code will be compiled to run only on big-endian + * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to + * run on either big- or little-endian CPUs, but will run slightly less + * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. + */ + +typedef unsigned char md5_byte_t; /* 8-bit byte */ +typedef unsigned int md5_word_t; /* 32-bit word */ + +/* Define the state of the MD5 Algorithm. */ +typedef struct md5_state_s { + md5_word_t count[2]; /* message length in bits, lsw first */ + md5_word_t abcd[4]; /* digest buffer */ + md5_byte_t buf[64]; /* accumulate block */ +} md5_state_t; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Initialize the algorithm. */ +void md5_init(md5_state_t *pms); + +/* Append a string to the message. */ +void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); + +/* Finish the message and return the digest. */ +void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* md5_INCLUDED */ diff --git a/mrbgems/g/md5/src/mrb_md5.c b/mrbgems/g/md5/src/mrb_md5.c new file mode 100644 index 000000000..6df453b0e --- /dev/null +++ b/mrbgems/g/md5/src/mrb_md5.c @@ -0,0 +1,56 @@ +#include +#include +#include "md5.h" + +static struct RClass *_class_md5; + +/********************************************************* + * main + *********************************************************/ + +static char +nr2char(int n) { + if (0 <= n && n <= 9) { + return '0' + n; + } else { + return 'a' + n - 10; + } +} + +static mrb_value +mrb_md5_hex(mrb_state *mrb, mrb_value self) +{ + md5_state_t pms; + md5_byte_t digest[16]; + md5_byte_t digest_hex[33]; + mrb_value arg; + int i; + + mrb_get_args(mrb, "o", &arg); + if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); + } + + md5_init(&pms); + md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); + md5_finish(&pms, digest); + + + for (i = 0; i < 16; i++) { + digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); + digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); + } + digest_hex[32] = 0; + + return mrb_str_new(mrb, (char*) digest_hex, 32); +} + +/********************************************************* + * register + *********************************************************/ + +void +mrb_md5_gem_init(mrb_state* mrb) { + _class_md5 = mrb_define_module(mrb, "MD5"); + mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); +} diff --git a/mrbgems/g/md5/src/mrb_md5.h b/mrbgems/g/md5/src/mrb_md5.h new file mode 100644 index 000000000..2f5934017 --- /dev/null +++ b/mrbgems/g/md5/src/mrb_md5.h @@ -0,0 +1,6 @@ +#ifndef MRB_MD5_H +#define MRB_MD5_H + +void mrb_md5_gem_init(mrb_state*); + +#endif /* MRB_MD5_H */ diff --git a/mrbgems/md5/Makefile b/mrbgems/md5/Makefile deleted file mode 100644 index 5ea2597c6..000000000 --- a/mrbgems/md5/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -MRUBY_ROOT = ../.. - -INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. -CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration - -all : src/md5.o src/mrb_md5.o - @echo done - -md5.o : src/md5.c - gcc -c -I. src/md5.c - -mrb_md5.o : src/mrb_md5.c - gcc -c $(CFLAGS) src/mrb_md5.c - -clean : - rm -f src/*.o diff --git a/mrbgems/md5/README.md b/mrbgems/md5/README.md deleted file mode 100644 index d84bb9941..000000000 --- a/mrbgems/md5/README.md +++ /dev/null @@ -1,6 +0,0 @@ -mruby-md5 -========= - -MD5 digest function. - -This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/md5/src/md5.c b/mrbgems/md5/src/md5.c deleted file mode 100644 index c35d96c5e..000000000 --- a/mrbgems/md5/src/md5.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} diff --git a/mrbgems/md5/src/md5.h b/mrbgems/md5/src/md5.h deleted file mode 100644 index 698c995d8..000000000 --- a/mrbgems/md5/src/md5.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke . - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ diff --git a/mrbgems/md5/src/mrb_md5.c b/mrbgems/md5/src/mrb_md5.c deleted file mode 100644 index 6df453b0e..000000000 --- a/mrbgems/md5/src/mrb_md5.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include "md5.h" - -static struct RClass *_class_md5; - -/********************************************************* - * main - *********************************************************/ - -static char -nr2char(int n) { - if (0 <= n && n <= 9) { - return '0' + n; - } else { - return 'a' + n - 10; - } -} - -static mrb_value -mrb_md5_hex(mrb_state *mrb, mrb_value self) -{ - md5_state_t pms; - md5_byte_t digest[16]; - md5_byte_t digest_hex[33]; - mrb_value arg; - int i; - - mrb_get_args(mrb, "o", &arg); - if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); - } - - md5_init(&pms); - md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); - md5_finish(&pms, digest); - - - for (i = 0; i < 16; i++) { - digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); - digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); - } - digest_hex[32] = 0; - - return mrb_str_new(mrb, (char*) digest_hex, 32); -} - -/********************************************************* - * register - *********************************************************/ - -void -mrb_md5_gem_init(mrb_state* mrb) { - _class_md5 = mrb_define_module(mrb, "MD5"); - mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); -} diff --git a/mrbgems/md5/src/mrb_md5.h b/mrbgems/md5/src/mrb_md5.h deleted file mode 100644 index 2f5934017..000000000 --- a/mrbgems/md5/src/mrb_md5.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MRB_MD5_H -#define MRB_MD5_H - -void mrb_md5_gem_init(mrb_state*); - -#endif /* MRB_MD5_H */ -- cgit v1.2.3 From c6a520c6b5362e26cb9d741eed08f4fc3426b3ad Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 07:27:07 +0900 Subject: Built generator for an variable amount of gems --- mrbgems/Makefile | 41 +++-- mrbgems/g/md5/Makefile | 10 +- mrbgems/g/md5_zwo/Makefile | 16 ++ mrbgems/g/md5_zwo/README.md | 6 + mrbgems/g/md5_zwo/src/md5.c | 381 ++++++++++++++++++++++++++++++++++++++++ mrbgems/g/md5_zwo/src/md5.h | 91 ++++++++++ mrbgems/g/md5_zwo/src/mrb_md5.c | 56 ++++++ mrbgems/g/md5_zwo/src/mrb_md5.h | 6 + mrbgems/gem_helper.c | 112 ++++++++++++ mrbgems/init_gems.c | 18 -- 10 files changed, 704 insertions(+), 33 deletions(-) create mode 100644 mrbgems/g/md5_zwo/Makefile create mode 100644 mrbgems/g/md5_zwo/README.md create mode 100644 mrbgems/g/md5_zwo/src/md5.c create mode 100644 mrbgems/g/md5_zwo/src/md5.h create mode 100644 mrbgems/g/md5_zwo/src/mrb_md5.c create mode 100644 mrbgems/g/md5_zwo/src/mrb_md5.h create mode 100644 mrbgems/gem_helper.c delete mode 100644 mrbgems/init_gems.c diff --git a/mrbgems/Makefile b/mrbgems/Makefile index b8f35f2a9..970baadac 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -5,24 +5,43 @@ LIBRGEMS := ../lib/libmruby_gems.a INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -GEM_DIRS := $(wildcard g/*) +MMAKER := ./gem_helper +MMAKER_BIN := $(MMAKER) +export CC = gcc +export LL = gcc ############################## # generic build targets, rules .PHONY : all -all : $(GEM_DIRS) - echo $(GEM_DIRS) +all : $(INIT).o all_gems -# driver build rule -#$(INIT).o : $(INIT).c -# gcc $(CC_FLAGS) -c $(INIT).c -o $(INIT).o +$(INIT).o : $(INIT).c + @echo "Build the driver which initiailizes all gems" + gcc $(CC_FLAGS) -c $< -o $@ -$(GEM_DIRS) : - echo $@ +all_gems : $(MMAKER_BIN) g/Makefile + @echo "Build all gems" + $(MAKE) -C g + +$(MMAKER_BIN) : $(MMAKER).o + @echo "Build the generator which creates the driver and Gem Makefile" + $(LL) -o $@ $(CC_FLAGS) $< +$(MMAKER).o : $(MMAKER).c + $(CC) $(CC_FLAGS) -MMD -c $< -o $@ + +$(INIT).c : $(MMAKER_BIN) + @echo "Generate Gem driver" + $(MMAKER_BIN) $(INIT) > $@ + +g/Makefile : + @echo "Generate Gem Makefile" + $(MMAKER_BIN) makefile > $@ # clean driver and all gems .PHONY : clean -clean : g/* - $(RM_F) $(INIT).o $(INIT).d $(LIBRGEMS) - $(MAKE) clean -C $< +clean : $(MMAKER_BIN) + @echo "Cleanup Gems" + $(MMAKER_BIN) makefile > g/Makefile + $(MAKE) clean -C g + -$(RM_F) $(INIT).c *.o *.d $(MMAKER_BIN) g/Makefile diff --git a/mrbgems/g/md5/Makefile b/mrbgems/g/md5/Makefile index a4457c9a6..52e2b99b9 100644 --- a/mrbgems/g/md5/Makefile +++ b/mrbgems/g/md5/Makefile @@ -1,16 +1,18 @@ +GEMNAME := md5 MRUBY_ROOT = ../../.. INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration +RM_F := rm -f all : src/md5.o src/mrb_md5.o - @echo done + @echo "Gem '$(GEMNAME)' is done" md5.o : src/md5.c - gcc -c -I. src/md5.c + @gcc -c -I. src/md5.c mrb_md5.o : src/mrb_md5.c - gcc -c $(CFLAGS) src/mrb_md5.c + @gcc -c $(CFLAGS) src/mrb_md5.c clean : - rm -f src/*.o + -$(RM_F) src/*.o diff --git a/mrbgems/g/md5_zwo/Makefile b/mrbgems/g/md5_zwo/Makefile new file mode 100644 index 000000000..a4457c9a6 --- /dev/null +++ b/mrbgems/g/md5_zwo/Makefile @@ -0,0 +1,16 @@ +MRUBY_ROOT = ../../.. + +INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. +CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration + +all : src/md5.o src/mrb_md5.o + @echo done + +md5.o : src/md5.c + gcc -c -I. src/md5.c + +mrb_md5.o : src/mrb_md5.c + gcc -c $(CFLAGS) src/mrb_md5.c + +clean : + rm -f src/*.o diff --git a/mrbgems/g/md5_zwo/README.md b/mrbgems/g/md5_zwo/README.md new file mode 100644 index 000000000..d84bb9941 --- /dev/null +++ b/mrbgems/g/md5_zwo/README.md @@ -0,0 +1,6 @@ +mruby-md5 +========= + +MD5 digest function. + +This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/g/md5_zwo/src/md5.c b/mrbgems/g/md5_zwo/src/md5.c new file mode 100644 index 000000000..c35d96c5e --- /dev/null +++ b/mrbgems/g/md5_zwo/src/md5.c @@ -0,0 +1,381 @@ +/* + Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.c is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order + either statically or dynamically; added missing #include + in library. + 2002-03-11 lpd Corrected argument list for main(), and added int return + type, in test program and T value program. + 2002-02-21 lpd Added missing #include in test program. + 2000-07-03 lpd Patched to eliminate warnings about "constant is + unsigned in ANSI C, signed in traditional"; made test program + self-checking. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). + 1999-05-03 lpd Original version. + */ + +#include "md5.h" +#include + +#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ +#ifdef ARCH_IS_BIG_ENDIAN +# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) +#else +# define BYTE_ORDER 0 +#endif + +#define T_MASK ((md5_word_t)~0) +#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) +#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) +#define T3 0x242070db +#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) +#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) +#define T6 0x4787c62a +#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) +#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) +#define T9 0x698098d8 +#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) +#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) +#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) +#define T13 0x6b901122 +#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) +#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) +#define T16 0x49b40821 +#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) +#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) +#define T19 0x265e5a51 +#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) +#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) +#define T22 0x02441453 +#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) +#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) +#define T25 0x21e1cde6 +#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) +#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) +#define T28 0x455a14ed +#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) +#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) +#define T31 0x676f02d9 +#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) +#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) +#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) +#define T35 0x6d9d6122 +#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) +#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) +#define T38 0x4bdecfa9 +#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) +#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) +#define T41 0x289b7ec6 +#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) +#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) +#define T44 0x04881d05 +#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) +#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) +#define T47 0x1fa27cf8 +#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) +#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) +#define T50 0x432aff97 +#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) +#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) +#define T53 0x655b59c3 +#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) +#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) +#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) +#define T57 0x6fa87e4f +#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) +#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) +#define T60 0x4e0811a1 +#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) +#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) +#define T63 0x2ad7d2bb +#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) + + +static void +md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) +{ + md5_word_t + a = pms->abcd[0], b = pms->abcd[1], + c = pms->abcd[2], d = pms->abcd[3]; + md5_word_t t; +#if BYTE_ORDER > 0 + /* Define storage only for big-endian CPUs. */ + md5_word_t X[16]; +#else + /* Define storage for little-endian or both types of CPUs. */ + md5_word_t xbuf[16]; + const md5_word_t *X; +#endif + + { +#if BYTE_ORDER == 0 + /* + * Determine dynamically whether this is a big-endian or + * little-endian machine, since we can use a more efficient + * algorithm on the latter. + */ + static const int w = 1; + + if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ +#endif +#if BYTE_ORDER <= 0 /* little-endian */ + { + /* + * On little-endian machines, we can process properly aligned + * data without copying it. + */ + if (!((data - (const md5_byte_t *)0) & 3)) { + /* data are properly aligned */ + X = (const md5_word_t *)data; + } else { + /* not aligned */ + memcpy(xbuf, data, 64); + X = xbuf; + } + } +#endif +#if BYTE_ORDER == 0 + else /* dynamic big-endian */ +#endif +#if BYTE_ORDER >= 0 /* big-endian */ + { + /* + * On big-endian machines, we must arrange the bytes in the + * right order. + */ + const md5_byte_t *xp = data; + int i; + +# if BYTE_ORDER == 0 + X = xbuf; /* (dynamic only) */ +# else +# define xbuf X /* (static only) */ +# endif + for (i = 0; i < 16; ++i, xp += 4) + xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); + } +#endif + } + +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) + + /* Round 1. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ +#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + F(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 7, T1); + SET(d, a, b, c, 1, 12, T2); + SET(c, d, a, b, 2, 17, T3); + SET(b, c, d, a, 3, 22, T4); + SET(a, b, c, d, 4, 7, T5); + SET(d, a, b, c, 5, 12, T6); + SET(c, d, a, b, 6, 17, T7); + SET(b, c, d, a, 7, 22, T8); + SET(a, b, c, d, 8, 7, T9); + SET(d, a, b, c, 9, 12, T10); + SET(c, d, a, b, 10, 17, T11); + SET(b, c, d, a, 11, 22, T12); + SET(a, b, c, d, 12, 7, T13); + SET(d, a, b, c, 13, 12, T14); + SET(c, d, a, b, 14, 17, T15); + SET(b, c, d, a, 15, 22, T16); +#undef SET + + /* Round 2. */ + /* Let [abcd k s i] denote the operation + a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ +#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + G(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 1, 5, T17); + SET(d, a, b, c, 6, 9, T18); + SET(c, d, a, b, 11, 14, T19); + SET(b, c, d, a, 0, 20, T20); + SET(a, b, c, d, 5, 5, T21); + SET(d, a, b, c, 10, 9, T22); + SET(c, d, a, b, 15, 14, T23); + SET(b, c, d, a, 4, 20, T24); + SET(a, b, c, d, 9, 5, T25); + SET(d, a, b, c, 14, 9, T26); + SET(c, d, a, b, 3, 14, T27); + SET(b, c, d, a, 8, 20, T28); + SET(a, b, c, d, 13, 5, T29); + SET(d, a, b, c, 2, 9, T30); + SET(c, d, a, b, 7, 14, T31); + SET(b, c, d, a, 12, 20, T32); +#undef SET + + /* Round 3. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ +#define H(x, y, z) ((x) ^ (y) ^ (z)) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + H(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 5, 4, T33); + SET(d, a, b, c, 8, 11, T34); + SET(c, d, a, b, 11, 16, T35); + SET(b, c, d, a, 14, 23, T36); + SET(a, b, c, d, 1, 4, T37); + SET(d, a, b, c, 4, 11, T38); + SET(c, d, a, b, 7, 16, T39); + SET(b, c, d, a, 10, 23, T40); + SET(a, b, c, d, 13, 4, T41); + SET(d, a, b, c, 0, 11, T42); + SET(c, d, a, b, 3, 16, T43); + SET(b, c, d, a, 6, 23, T44); + SET(a, b, c, d, 9, 4, T45); + SET(d, a, b, c, 12, 11, T46); + SET(c, d, a, b, 15, 16, T47); + SET(b, c, d, a, 2, 23, T48); +#undef SET + + /* Round 4. */ + /* Let [abcd k s t] denote the operation + a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ +#define I(x, y, z) ((y) ^ ((x) | ~(z))) +#define SET(a, b, c, d, k, s, Ti)\ + t = a + I(b,c,d) + X[k] + Ti;\ + a = ROTATE_LEFT(t, s) + b + /* Do the following 16 operations. */ + SET(a, b, c, d, 0, 6, T49); + SET(d, a, b, c, 7, 10, T50); + SET(c, d, a, b, 14, 15, T51); + SET(b, c, d, a, 5, 21, T52); + SET(a, b, c, d, 12, 6, T53); + SET(d, a, b, c, 3, 10, T54); + SET(c, d, a, b, 10, 15, T55); + SET(b, c, d, a, 1, 21, T56); + SET(a, b, c, d, 8, 6, T57); + SET(d, a, b, c, 15, 10, T58); + SET(c, d, a, b, 6, 15, T59); + SET(b, c, d, a, 13, 21, T60); + SET(a, b, c, d, 4, 6, T61); + SET(d, a, b, c, 11, 10, T62); + SET(c, d, a, b, 2, 15, T63); + SET(b, c, d, a, 9, 21, T64); +#undef SET + + /* Then perform the following additions. (That is increment each + of the four registers by the value it had before this block + was started.) */ + pms->abcd[0] += a; + pms->abcd[1] += b; + pms->abcd[2] += c; + pms->abcd[3] += d; +} + +void +md5_init(md5_state_t *pms) +{ + pms->count[0] = pms->count[1] = 0; + pms->abcd[0] = 0x67452301; + pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; + pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; + pms->abcd[3] = 0x10325476; +} + +void +md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) +{ + const md5_byte_t *p = data; + int left = nbytes; + int offset = (pms->count[0] >> 3) & 63; + md5_word_t nbits = (md5_word_t)(nbytes << 3); + + if (nbytes <= 0) + return; + + /* Update the message length. */ + pms->count[1] += nbytes >> 29; + pms->count[0] += nbits; + if (pms->count[0] < nbits) + pms->count[1]++; + + /* Process an initial partial block. */ + if (offset) { + int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); + + memcpy(pms->buf + offset, p, copy); + if (offset + copy < 64) + return; + p += copy; + left -= copy; + md5_process(pms, pms->buf); + } + + /* Process full blocks. */ + for (; left >= 64; p += 64, left -= 64) + md5_process(pms, p); + + /* Process a final partial block. */ + if (left) + memcpy(pms->buf, p, left); +} + +void +md5_finish(md5_state_t *pms, md5_byte_t digest[16]) +{ + static const md5_byte_t pad[64] = { + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 + }; + md5_byte_t data[8]; + int i; + + /* Save the length before padding. */ + for (i = 0; i < 8; ++i) + data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); + /* Pad to 56 bytes mod 64. */ + md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); + /* Append the length. */ + md5_append(pms, data, 8); + for (i = 0; i < 16; ++i) + digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); +} diff --git a/mrbgems/g/md5_zwo/src/md5.h b/mrbgems/g/md5_zwo/src/md5.h new file mode 100644 index 000000000..698c995d8 --- /dev/null +++ b/mrbgems/g/md5_zwo/src/md5.h @@ -0,0 +1,91 @@ +/* + Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. + + This software is provided 'as-is', without any express or implied + warranty. In no event will the authors be held liable for any damages + arising from the use of this software. + + Permission is granted to anyone to use this software for any purpose, + including commercial applications, and to alter it and redistribute it + freely, subject to the following restrictions: + + 1. The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. + 2. Altered source versions must be plainly marked as such, and must not be + misrepresented as being the original software. + 3. This notice may not be removed or altered from any source distribution. + + L. Peter Deutsch + ghost@aladdin.com + + */ +/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ +/* + Independent implementation of MD5 (RFC 1321). + + This code implements the MD5 Algorithm defined in RFC 1321, whose + text is available at + http://www.ietf.org/rfc/rfc1321.txt + The code is derived from the text of the RFC, including the test suite + (section A.5) but excluding the rest of Appendix A. It does not include + any code or documentation that is identified in the RFC as being + copyrighted. + + The original and principal author of md5.h is L. Peter Deutsch + . Other authors are noted in the change history + that follows (in reverse chronological order): + + 2002-04-13 lpd Removed support for non-ANSI compilers; removed + references to Ghostscript; clarified derivation from RFC 1321; + now handles byte order either statically or dynamically. + 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. + 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); + added conditionalization for C++ compilation from Martin + Purschke . + 1999-05-03 lpd Original version. + */ + +#ifndef md5_INCLUDED +# define md5_INCLUDED + +/* + * This package supports both compile-time and run-time determination of CPU + * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be + * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is + * defined as non-zero, the code will be compiled to run only on big-endian + * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to + * run on either big- or little-endian CPUs, but will run slightly less + * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. + */ + +typedef unsigned char md5_byte_t; /* 8-bit byte */ +typedef unsigned int md5_word_t; /* 32-bit word */ + +/* Define the state of the MD5 Algorithm. */ +typedef struct md5_state_s { + md5_word_t count[2]; /* message length in bits, lsw first */ + md5_word_t abcd[4]; /* digest buffer */ + md5_byte_t buf[64]; /* accumulate block */ +} md5_state_t; + +#ifdef __cplusplus +extern "C" +{ +#endif + +/* Initialize the algorithm. */ +void md5_init(md5_state_t *pms); + +/* Append a string to the message. */ +void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); + +/* Finish the message and return the digest. */ +void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); + +#ifdef __cplusplus +} /* end extern "C" */ +#endif + +#endif /* md5_INCLUDED */ diff --git a/mrbgems/g/md5_zwo/src/mrb_md5.c b/mrbgems/g/md5_zwo/src/mrb_md5.c new file mode 100644 index 000000000..6df453b0e --- /dev/null +++ b/mrbgems/g/md5_zwo/src/mrb_md5.c @@ -0,0 +1,56 @@ +#include +#include +#include "md5.h" + +static struct RClass *_class_md5; + +/********************************************************* + * main + *********************************************************/ + +static char +nr2char(int n) { + if (0 <= n && n <= 9) { + return '0' + n; + } else { + return 'a' + n - 10; + } +} + +static mrb_value +mrb_md5_hex(mrb_state *mrb, mrb_value self) +{ + md5_state_t pms; + md5_byte_t digest[16]; + md5_byte_t digest_hex[33]; + mrb_value arg; + int i; + + mrb_get_args(mrb, "o", &arg); + if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { + mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); + } + + md5_init(&pms); + md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); + md5_finish(&pms, digest); + + + for (i = 0; i < 16; i++) { + digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); + digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); + } + digest_hex[32] = 0; + + return mrb_str_new(mrb, (char*) digest_hex, 32); +} + +/********************************************************* + * register + *********************************************************/ + +void +mrb_md5_gem_init(mrb_state* mrb) { + _class_md5 = mrb_define_module(mrb, "MD5"); + mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); +} diff --git a/mrbgems/g/md5_zwo/src/mrb_md5.h b/mrbgems/g/md5_zwo/src/mrb_md5.h new file mode 100644 index 000000000..2f5934017 --- /dev/null +++ b/mrbgems/g/md5_zwo/src/mrb_md5.h @@ -0,0 +1,6 @@ +#ifndef MRB_MD5_H +#define MRB_MD5_H + +void mrb_md5_gem_init(mrb_state*); + +#endif /* MRB_MD5_H */ diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c new file mode 100644 index 000000000..6b32a916e --- /dev/null +++ b/mrbgems/gem_helper.c @@ -0,0 +1,112 @@ +#include +#include +#include +#include + +static int +one (const struct dirent *unused) +{ + return 1; +} + +void +dir_list (char before[1024], char after[1024]) +{ + struct dirent **eps; + int n; + char gemname[1024] = ""; + char gemname_path[4096] = ""; + char complete_line[4096] = ""; + struct stat attribut; + + n = scandir("./g", &eps, one, alphasort); + if (n >= 0) { + int cnt; + for (cnt = 0; cnt < n; ++cnt) { + strcpy(gemname, eps[cnt]->d_name); + strcpy(gemname_path, "./g/"); + strcat(gemname_path, gemname); + + if (strcmp(gemname, ".") == 0) + continue; + if (strcmp(gemname, "..") == 0) + continue; + + stat(gemname_path, &attribut); + if (S_ISDIR(attribut.st_mode) == 0) + continue; + + strcat(complete_line, before); + strcat(complete_line, gemname); + strcat(complete_line, after); + strcat(complete_line, "\n"); + } + puts(complete_line); + } + else + perror ("Couldn't open the directory"); +} + +void +make_gem_makefile() +{ + puts("ifeq ($(OS),Windows_NT)"); + puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'"); + puts("else"); + puts("MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'"); + puts("endif"); + puts(""); + + puts(".PHONY : all"); + puts("all :"); + dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)"); + + puts(".PHONY : clean"); + puts("clean :"); + dir_list("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)"); +} + +void +make_init_gems() +{ + puts("/*"); + puts(" * This file contains a list of all"); + puts(" * initializing methods which are"); + puts(" * necessary to bootstrap all gems."); + puts(" *"); + puts(" * IMPORTANT:"); + puts(" * This file was generated!"); + puts(" * All manual changes will get lost."); + puts(" */"); + + puts(""); + puts("#include \"mruby.h\""); + puts(""); + + dir_list("void mrb_", "_gem_init(mrb_state*);"); + + puts("void"); + puts("mrb_init_mrbgems(mrb_state *mrb)"); + puts("{"); + dir_list(" mrb_", "_gem_init(mrb);"); + puts("}"); +} + +int +main (int argc, char *argv[]) +{ + if (argc == 2) { + if (strcmp(argv[1], "makefile") == 0) + make_gem_makefile(); + else if (strcmp(argv[1], "init_gems") == 0) + make_init_gems(); + else + return 1; + } + else { + puts("Argument missing! Options: 'makefile'"); + return 1; + } + + return 0; +} diff --git a/mrbgems/init_gems.c b/mrbgems/init_gems.c deleted file mode 100644 index 02024d5a2..000000000 --- a/mrbgems/init_gems.c +++ /dev/null @@ -1,18 +0,0 @@ -/* - * This file will contain a list of all - * initializing methods necessary to - * bootstrap every gem. - * - * @TODO: - * this file has to be generated based on the active gems - */ - -#include "mruby.h" - -void mrb_md5_gem_init(mrb_state*); - -void -mrb_init_mrbgems(mrb_state *mrb) -{ - mrb_md5_gem_init(mrb); -} -- cgit v1.2.3 From ea68cb1beb1c561a1d960857a830dd5b6f2e497e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 07:41:02 +0900 Subject: remove second gem --- Makefile | 2 +- mrbgems/g/md5/Makefile | 11 +- mrbgems/g/md5_zwo/Makefile | 16 -- mrbgems/g/md5_zwo/README.md | 6 - mrbgems/g/md5_zwo/src/md5.c | 381 ---------------------------------------- mrbgems/g/md5_zwo/src/md5.h | 91 ---------- mrbgems/g/md5_zwo/src/mrb_md5.c | 56 ------ mrbgems/g/md5_zwo/src/mrb_md5.h | 6 - mrblib/Makefile | 3 +- 9 files changed, 11 insertions(+), 561 deletions(-) delete mode 100644 mrbgems/g/md5_zwo/Makefile delete mode 100644 mrbgems/g/md5_zwo/README.md delete mode 100644 mrbgems/g/md5_zwo/src/md5.c delete mode 100644 mrbgems/g/md5_zwo/src/md5.h delete mode 100644 mrbgems/g/md5_zwo/src/mrb_md5.c delete mode 100644 mrbgems/g/md5_zwo/src/mrb_md5.h diff --git a/Makefile b/Makefile index 21cd57685..d18222c3c 100644 --- a/Makefile +++ b/Makefile @@ -43,8 +43,8 @@ export CAT := cat .PHONY : all all : @$(MAKE) -C src $(MAKE_FLAGS) - @$(MAKE) -C mrbgems $(MAKE_FLAGS) @$(MAKE) -C mrblib $(MAKE_FLAGS) + @$(MAKE) -C mrbgems $(MAKE_FLAGS) @$(MAKE) -C tools/mruby $(MAKE_FLAGS) @$(MAKE) -C tools/mirb $(MAKE_FLAGS) diff --git a/mrbgems/g/md5/Makefile b/mrbgems/g/md5/Makefile index 52e2b99b9..4ad7295a2 100644 --- a/mrbgems/g/md5/Makefile +++ b/mrbgems/g/md5/Makefile @@ -1,12 +1,19 @@ GEMNAME := md5 -MRUBY_ROOT = ../../.. +MRUBY_ROOT = ../../../ -INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. +INCLUDES = -I$(MRUBY_ROOT)include -I$(MRUBY_ROOT)src -I. CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration RM_F := rm -f +AR := ar + +ifeq ($(strip $(LIBR)),) + # default compile option + LIBR = $(MRUBY_ROOT)lib/libmruby.a +endif all : src/md5.o src/mrb_md5.o @echo "Gem '$(GEMNAME)' is done" + @$(AR) rs $(LIBR) src/md5.o src/mrb_md5.o md5.o : src/md5.c @gcc -c -I. src/md5.c diff --git a/mrbgems/g/md5_zwo/Makefile b/mrbgems/g/md5_zwo/Makefile deleted file mode 100644 index a4457c9a6..000000000 --- a/mrbgems/g/md5_zwo/Makefile +++ /dev/null @@ -1,16 +0,0 @@ -MRUBY_ROOT = ../../.. - -INCLUDES = -I$(MRUBY_ROOT)/include -I$(MRUBY_ROOT)/src -I. -CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration - -all : src/md5.o src/mrb_md5.o - @echo done - -md5.o : src/md5.c - gcc -c -I. src/md5.c - -mrb_md5.o : src/mrb_md5.c - gcc -c $(CFLAGS) src/mrb_md5.c - -clean : - rm -f src/*.o diff --git a/mrbgems/g/md5_zwo/README.md b/mrbgems/g/md5_zwo/README.md deleted file mode 100644 index d84bb9941..000000000 --- a/mrbgems/g/md5_zwo/README.md +++ /dev/null @@ -1,6 +0,0 @@ -mruby-md5 -========= - -MD5 digest function. - -This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/g/md5_zwo/src/md5.c b/mrbgems/g/md5_zwo/src/md5.c deleted file mode 100644 index c35d96c5e..000000000 --- a/mrbgems/g/md5_zwo/src/md5.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} diff --git a/mrbgems/g/md5_zwo/src/md5.h b/mrbgems/g/md5_zwo/src/md5.h deleted file mode 100644 index 698c995d8..000000000 --- a/mrbgems/g/md5_zwo/src/md5.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke . - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ diff --git a/mrbgems/g/md5_zwo/src/mrb_md5.c b/mrbgems/g/md5_zwo/src/mrb_md5.c deleted file mode 100644 index 6df453b0e..000000000 --- a/mrbgems/g/md5_zwo/src/mrb_md5.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include "md5.h" - -static struct RClass *_class_md5; - -/********************************************************* - * main - *********************************************************/ - -static char -nr2char(int n) { - if (0 <= n && n <= 9) { - return '0' + n; - } else { - return 'a' + n - 10; - } -} - -static mrb_value -mrb_md5_hex(mrb_state *mrb, mrb_value self) -{ - md5_state_t pms; - md5_byte_t digest[16]; - md5_byte_t digest_hex[33]; - mrb_value arg; - int i; - - mrb_get_args(mrb, "o", &arg); - if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); - } - - md5_init(&pms); - md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); - md5_finish(&pms, digest); - - - for (i = 0; i < 16; i++) { - digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); - digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); - } - digest_hex[32] = 0; - - return mrb_str_new(mrb, (char*) digest_hex, 32); -} - -/********************************************************* - * register - *********************************************************/ - -void -mrb_md5_gem_init(mrb_state* mrb) { - _class_md5 = mrb_define_module(mrb, "MD5"); - mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); -} diff --git a/mrbgems/g/md5_zwo/src/mrb_md5.h b/mrbgems/g/md5_zwo/src/mrb_md5.h deleted file mode 100644 index 2f5934017..000000000 --- a/mrbgems/g/md5_zwo/src/mrb_md5.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MRB_MD5_H -#define MRB_MD5_H - -void mrb_md5_gem_init(mrb_state*); - -#endif /* MRB_MD5_H */ diff --git a/mrblib/Makefile b/mrblib/Makefile index fe0b816fb..9ba7ed0cf 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -14,7 +14,6 @@ MRB1 := $(BASEDIR)/*.rb MRBS := $(MRB1) LIBR0 := ../lib/libmruby_core.a LIBR := ../lib/libmruby.a -GEM0 := ../mrbgems/md5/src/ # libraries, includes INCLUDES = -I../src -I../include @@ -58,7 +57,7 @@ all : $(LIBR) # update libmruby.a $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) - $(AR) rs $(LIBR) $(GEM0)md5.o $(GEM0)mrb_md5.o ../mrbgems/init_gems.o $(MLIB) + $(AR) rs $(LIBR) $(MLIB) # Compile mrblib source $(MLIB) : $(CLIB) -- cgit v1.2.3 From 17c877011d2ecaba8a904f1b5b87a4aa2f5a82bb Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 09:34:24 +0900 Subject: Some additional changes to compile properly --- mrbgems/Makefile | 21 ++++++++++++--------- mrbgems/g/md5/Makefile | 7 +++++-- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 970baadac..abd726a0e 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -1,7 +1,7 @@ # makefile description. # add gems to the ruby library -LIBRGEMS := ../lib/libmruby_gems.a +LIBR := ../lib/libmruby.a INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include @@ -9,6 +9,7 @@ MMAKER := ./gem_helper MMAKER_BIN := $(MMAKER) export CC = gcc export LL = gcc +export AR = ar ############################## # generic build targets, rules @@ -16,17 +17,10 @@ export LL = gcc .PHONY : all all : $(INIT).o all_gems -$(INIT).o : $(INIT).c - @echo "Build the driver which initiailizes all gems" - gcc $(CC_FLAGS) -c $< -o $@ - -all_gems : $(MMAKER_BIN) g/Makefile - @echo "Build all gems" - $(MAKE) -C g - $(MMAKER_BIN) : $(MMAKER).o @echo "Build the generator which creates the driver and Gem Makefile" $(LL) -o $@ $(CC_FLAGS) $< + $(MMAKER).o : $(MMAKER).c $(CC) $(CC_FLAGS) -MMD -c $< -o $@ @@ -34,10 +28,19 @@ $(INIT).c : $(MMAKER_BIN) @echo "Generate Gem driver" $(MMAKER_BIN) $(INIT) > $@ +$(INIT).o : $(INIT).c + @echo "Build the driver which initiailizes all gems" + gcc $(CC_FLAGS) -c $< -o $@ + $(AR) rs $(LIBR) $@ + g/Makefile : @echo "Generate Gem Makefile" $(MMAKER_BIN) makefile > $@ +all_gems : $(MMAKER_BIN) g/Makefile + @echo "Build all gems" + $(MAKE) -C g + # clean driver and all gems .PHONY : clean clean : $(MMAKER_BIN) diff --git a/mrbgems/g/md5/Makefile b/mrbgems/g/md5/Makefile index 4ad7295a2..839646ef4 100644 --- a/mrbgems/g/md5/Makefile +++ b/mrbgems/g/md5/Makefile @@ -7,13 +7,14 @@ RM_F := rm -f AR := ar ifeq ($(strip $(LIBR)),) - # default compile option + # default mruby library LIBR = $(MRUBY_ROOT)lib/libmruby.a endif +.PHONY : all all : src/md5.o src/mrb_md5.o - @echo "Gem '$(GEMNAME)' is done" @$(AR) rs $(LIBR) src/md5.o src/mrb_md5.o + @echo "Gem '$(GEMNAME)' is done" md5.o : src/md5.c @gcc -c -I. src/md5.c @@ -21,5 +22,7 @@ md5.o : src/md5.c mrb_md5.o : src/mrb_md5.c @gcc -c $(CFLAGS) src/mrb_md5.c +.PHONY : clean clean : -$(RM_F) src/*.o + @echo "Gem '$(GEMNAME)' is clean" -- cgit v1.2.3 From 48c84cbc2e6aa2043ec164ed5a76a6581ea348e0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 09:39:45 +0900 Subject: Ignore generated files --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 797f98917..02ffb598a 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,6 @@ cscope.out /test/*.*tmp CMakeFiles CMakeCache.txt +/mrbgems/gem_helper +/mrbgems/init_gems.c +/mrbgems/g/Makefile -- cgit v1.2.3 From e7425584e3aebc0295f1b55f7f44c2c5f5583964 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 23:01:13 +0800 Subject: Modify information messages --- mrbgems/gem_helper.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c index 6b32a916e..d1cbfb046 100644 --- a/mrbgems/gem_helper.c +++ b/mrbgems/gem_helper.c @@ -44,7 +44,7 @@ dir_list (char before[1024], char after[1024]) puts(complete_line); } else - perror ("Couldn't open the directory"); + perror("Error while scanning the directory."); } void @@ -104,7 +104,7 @@ main (int argc, char *argv[]) return 1; } else { - puts("Argument missing! Options: 'makefile'"); + puts("Argument missing! Options: 'makefile', 'init_gems'"); return 1; } -- cgit v1.2.3 From ab548b1c19a23cb6e8369a67d03f4c60a54f8a54 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 19 Sep 2012 23:18:35 +0800 Subject: add hello world test program --- mrbgems/g/hello_world/Makefile | 25 +++ mrbgems/g/hello_world/README.md | 6 + mrbgems/g/hello_world/src/hello_world.c | 17 ++ mrbgems/g/md5/Makefile | 28 --- mrbgems/g/md5/README.md | 6 - mrbgems/g/md5/src/md5.c | 381 -------------------------------- mrbgems/g/md5/src/md5.h | 91 -------- mrbgems/g/md5/src/mrb_md5.c | 56 ----- mrbgems/g/md5/src/mrb_md5.h | 6 - 9 files changed, 48 insertions(+), 568 deletions(-) create mode 100644 mrbgems/g/hello_world/Makefile create mode 100644 mrbgems/g/hello_world/README.md create mode 100644 mrbgems/g/hello_world/src/hello_world.c delete mode 100644 mrbgems/g/md5/Makefile delete mode 100644 mrbgems/g/md5/README.md delete mode 100644 mrbgems/g/md5/src/md5.c delete mode 100644 mrbgems/g/md5/src/md5.h delete mode 100644 mrbgems/g/md5/src/mrb_md5.c delete mode 100644 mrbgems/g/md5/src/mrb_md5.h diff --git a/mrbgems/g/hello_world/Makefile b/mrbgems/g/hello_world/Makefile new file mode 100644 index 000000000..50a92f03a --- /dev/null +++ b/mrbgems/g/hello_world/Makefile @@ -0,0 +1,25 @@ +GEMNAME := hello_world +MRUBY_ROOT = ../../../ + +INCLUDES = -I$(MRUBY_ROOT)include -I$(MRUBY_ROOT)src -I. +CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration +RM_F := rm -f +AR := ar + +ifeq ($(strip $(LIBR)),) + # default mruby library + LIBR = $(MRUBY_ROOT)lib/libmruby.a +endif + +.PHONY : all +all : src/hello_world.o + @$(AR) rs $(LIBR) src/hello_world.o + @echo "Gem '$(GEMNAME)' is done" + +src/hello_world.o : src/hello_world.c + @gcc -c $(CFLAGS) src/hello_world.c -o src/hello_world.o + +.PHONY : clean +clean : + -$(RM_F) src/*.o + @echo "Gem '$(GEMNAME)' is clean" diff --git a/mrbgems/g/hello_world/README.md b/mrbgems/g/hello_world/README.md new file mode 100644 index 000000000..d84bb9941 --- /dev/null +++ b/mrbgems/g/hello_world/README.md @@ -0,0 +1,6 @@ +mruby-md5 +========= + +MD5 digest function. + +This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/g/hello_world/src/hello_world.c b/mrbgems/g/hello_world/src/hello_world.c new file mode 100644 index 000000000..75d353542 --- /dev/null +++ b/mrbgems/g/hello_world/src/hello_world.c @@ -0,0 +1,17 @@ +#include +#include + +static struct RClass *_class_hw; + +static mrb_value +mrb_hello_world(mrb_state *mrb, mrb_value self) +{ + puts("Hello World"); + return self; +} + +void +mrb_hello_world_gem_init(mrb_state* mrb) { + _class_hw = mrb_define_module(mrb, "HW"); + mrb_define_class_method(mrb, _class_hw, "say", mrb_hello_world, ARGS_NONE()); +} diff --git a/mrbgems/g/md5/Makefile b/mrbgems/g/md5/Makefile deleted file mode 100644 index 839646ef4..000000000 --- a/mrbgems/g/md5/Makefile +++ /dev/null @@ -1,28 +0,0 @@ -GEMNAME := md5 -MRUBY_ROOT = ../../../ - -INCLUDES = -I$(MRUBY_ROOT)include -I$(MRUBY_ROOT)src -I. -CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration -RM_F := rm -f -AR := ar - -ifeq ($(strip $(LIBR)),) - # default mruby library - LIBR = $(MRUBY_ROOT)lib/libmruby.a -endif - -.PHONY : all -all : src/md5.o src/mrb_md5.o - @$(AR) rs $(LIBR) src/md5.o src/mrb_md5.o - @echo "Gem '$(GEMNAME)' is done" - -md5.o : src/md5.c - @gcc -c -I. src/md5.c - -mrb_md5.o : src/mrb_md5.c - @gcc -c $(CFLAGS) src/mrb_md5.c - -.PHONY : clean -clean : - -$(RM_F) src/*.o - @echo "Gem '$(GEMNAME)' is clean" diff --git a/mrbgems/g/md5/README.md b/mrbgems/g/md5/README.md deleted file mode 100644 index d84bb9941..000000000 --- a/mrbgems/g/md5/README.md +++ /dev/null @@ -1,6 +0,0 @@ -mruby-md5 -========= - -MD5 digest function. - -This library comes original from mattn (http://github.com/mattn/mruby-md5) diff --git a/mrbgems/g/md5/src/md5.c b/mrbgems/g/md5/src/md5.c deleted file mode 100644 index c35d96c5e..000000000 --- a/mrbgems/g/md5/src/md5.c +++ /dev/null @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} diff --git a/mrbgems/g/md5/src/md5.h b/mrbgems/g/md5/src/md5.h deleted file mode 100644 index 698c995d8..000000000 --- a/mrbgems/g/md5/src/md5.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - ghost@aladdin.com - - */ -/* $Id: md5.h,v 1.4 2002/04/13 19:20:28 lpd Exp $ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - . Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke . - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ diff --git a/mrbgems/g/md5/src/mrb_md5.c b/mrbgems/g/md5/src/mrb_md5.c deleted file mode 100644 index 6df453b0e..000000000 --- a/mrbgems/g/md5/src/mrb_md5.c +++ /dev/null @@ -1,56 +0,0 @@ -#include -#include -#include "md5.h" - -static struct RClass *_class_md5; - -/********************************************************* - * main - *********************************************************/ - -static char -nr2char(int n) { - if (0 <= n && n <= 9) { - return '0' + n; - } else { - return 'a' + n - 10; - } -} - -static mrb_value -mrb_md5_hex(mrb_state *mrb, mrb_value self) -{ - md5_state_t pms; - md5_byte_t digest[16]; - md5_byte_t digest_hex[33]; - mrb_value arg; - int i; - - mrb_get_args(mrb, "o", &arg); - if (mrb_nil_p(arg) || mrb_type(arg) != MRB_TT_STRING) { - mrb_raise(mrb, E_ARGUMENT_ERROR, "invalid argument"); - } - - md5_init(&pms); - md5_append(&pms, (const md5_byte_t*) RSTRING_PTR(arg), RSTRING_CAPA(arg)); - md5_finish(&pms, digest); - - - for (i = 0; i < 16; i++) { - digest_hex[i*2+0] = nr2char((digest[i] >> 4) & 0xf); - digest_hex[i*2+1] = nr2char(digest[i] & 0x0f); - } - digest_hex[32] = 0; - - return mrb_str_new(mrb, (char*) digest_hex, 32); -} - -/********************************************************* - * register - *********************************************************/ - -void -mrb_md5_gem_init(mrb_state* mrb) { - _class_md5 = mrb_define_module(mrb, "MD5"); - mrb_define_class_method(mrb, _class_md5, "md5_hex", mrb_md5_hex, ARGS_REQ(1)); -} diff --git a/mrbgems/g/md5/src/mrb_md5.h b/mrbgems/g/md5/src/mrb_md5.h deleted file mode 100644 index 2f5934017..000000000 --- a/mrbgems/g/md5/src/mrb_md5.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef MRB_MD5_H -#define MRB_MD5_H - -void mrb_md5_gem_init(mrb_state*); - -#endif /* MRB_MD5_H */ -- cgit v1.2.3 From 19fa4a0993acef802ab4250541c1df72c7e2b604 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 20 Sep 2012 00:27:56 +0800 Subject: Add default makefile for Gems --- mrbgems/Makefile4gem | 37 +++++++++++++++++++++++++++++++++++++ mrbgems/g/hello_world/Makefile | 29 ++++++++--------------------- mrbgems/g/hello_world/README.md | 6 ++---- 3 files changed, 47 insertions(+), 25 deletions(-) create mode 100644 mrbgems/Makefile4gem diff --git a/mrbgems/Makefile4gem b/mrbgems/Makefile4gem new file mode 100644 index 000000000..a4fa3f3c9 --- /dev/null +++ b/mrbgems/Makefile4gem @@ -0,0 +1,37 @@ +# This is the default Makefile integrated +# by each Gem. It integrates important constants +# for usage inside of a Gem. + +# mruby src root +MRUBY_ROOT := ../../../ + +# Tools +CC := gcc +RM := rm -f +AR := ar + +SRC_DIR := src + +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 + LIBR := $(MRUBY_ROOT)lib/libmruby.a +endif + +# Default rules which are calling the +# gem specific gem-all and gem-clean +# implementations of a gem + +.PHONY : all +all : gem-info gem-all + @echo "Gem '$(GEM)' is done" + +gem-info: + @echo "Building Gem '$(GEM)'" + +.PHONY : clean +clean : gem-clean + @echo "Gem '$(GEM)' is clean" diff --git a/mrbgems/g/hello_world/Makefile b/mrbgems/g/hello_world/Makefile index 50a92f03a..c03910bf6 100644 --- a/mrbgems/g/hello_world/Makefile +++ b/mrbgems/g/hello_world/Makefile @@ -1,25 +1,12 @@ -GEMNAME := hello_world -MRUBY_ROOT = ../../../ +include ../../Makefile4gem -INCLUDES = -I$(MRUBY_ROOT)include -I$(MRUBY_ROOT)src -I. -CFLAGS = $(INCLUDES) -O3 -g -Wall -Werror-implicit-function-declaration -RM_F := rm -f -AR := ar +GEM := hello_world -ifeq ($(strip $(LIBR)),) - # default mruby library - LIBR = $(MRUBY_ROOT)lib/libmruby.a -endif +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -.PHONY : all -all : src/hello_world.o - @$(AR) rs $(LIBR) src/hello_world.o - @echo "Gem '$(GEMNAME)' is done" +gem-all : $(GEM_OBJECTS) + $(AR) rs $(LIBR) $< -src/hello_world.o : src/hello_world.c - @gcc -c $(CFLAGS) src/hello_world.c -o src/hello_world.o - -.PHONY : clean -clean : - -$(RM_F) src/*.o - @echo "Gem '$(GEMNAME)' is clean" +gem-clean : + -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/hello_world/README.md b/mrbgems/g/hello_world/README.md index d84bb9941..42792567f 100644 --- a/mrbgems/g/hello_world/README.md +++ b/mrbgems/g/hello_world/README.md @@ -1,6 +1,4 @@ -mruby-md5 +hello world ========= -MD5 digest function. - -This library comes original from mattn (http://github.com/mattn/mruby-md5) +This is an example gem which implements just one method +HW.say+ in a C extension. -- cgit v1.2.3 From 9a11c45e64dd9010d70a3a7e63819cec78c83afb Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 20 Sep 2012 01:31:26 +0800 Subject: Integrate tests into mrbgems --- Makefile | 1 + mrbgems/Makefile | 3 +++ mrbgems/g/hello_world/test/hello_world.rb | 3 +++ mrbgems/gem_helper.c | 35 ++++++++++++++++++++++++------- 4 files changed, 34 insertions(+), 8 deletions(-) create mode 100644 mrbgems/g/hello_world/test/hello_world.rb diff --git a/Makefile b/Makefile index d18222c3c..6866ec9e3 100644 --- a/Makefile +++ b/Makefile @@ -52,6 +52,7 @@ all : .PHONY : test test : all @$(MAKE) -C test $(MAKE_FLAGS) + @$(MAKE) test -C mrbgems $(MAKE_FLAGS) # clean up .PHONY : clean diff --git a/mrbgems/Makefile b/mrbgems/Makefile index abd726a0e..6fde97128 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -41,6 +41,9 @@ all_gems : $(MMAKER_BIN) g/Makefile @echo "Build all gems" $(MAKE) -C g +test : + $(MAKE) test -C g + # clean driver and all gems .PHONY : clean clean : $(MMAKER_BIN) diff --git a/mrbgems/g/hello_world/test/hello_world.rb b/mrbgems/g/hello_world/test/hello_world.rb new file mode 100644 index 000000000..2d8c335db --- /dev/null +++ b/mrbgems/g/hello_world/test/hello_world.rb @@ -0,0 +1,3 @@ +assert('Hello World') do + HW.respond_to? :say +end diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c index d1cbfb046..01daef364 100644 --- a/mrbgems/gem_helper.c +++ b/mrbgems/gem_helper.c @@ -10,7 +10,7 @@ one (const struct dirent *unused) } void -dir_list (char before[1024], char after[1024]) +dir_list (char before[1024], char after[1024], char start[1024], char end[1024]) { struct dirent **eps; int n; @@ -19,6 +19,8 @@ dir_list (char before[1024], char after[1024]) char complete_line[4096] = ""; struct stat attribut; + strcat(complete_line, start); + n = scandir("./g", &eps, one, alphasort); if (n >= 0) { int cnt; @@ -39,17 +41,22 @@ dir_list (char before[1024], char after[1024]) strcat(complete_line, before); strcat(complete_line, gemname); strcat(complete_line, after); - strcat(complete_line, "\n"); + } - puts(complete_line); } - else + else { perror("Error while scanning the directory."); + } + + strcat(complete_line, end); + puts(complete_line); } void make_gem_makefile() { + puts("CFLAGS := -I. -I../../include -I../../src"); + puts(""); puts("ifeq ($(OS),Windows_NT)"); puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'"); puts("else"); @@ -59,11 +66,23 @@ make_gem_makefile() puts(".PHONY : all"); puts("all :"); - dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)"); + dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", ""); + + puts(".PHONY : test"); + puts("test :"); + dir_list("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp"); + puts("\t../../bin/mrbc -Bmrbtest_irep -omrbtest.ctmp mrbtest.rbtmp"); + puts("\tcat ../../test/init_mrbtest.c mrbtest.ctmp > mrbtest.c"); + puts("\t$(CC) -c ../../test/driver.c -o ./driver.o $(CFLAGS)"); + puts("\t$(CC) -c ./mrbtest.c -o ./mrbtest.o $(CFLAGS)"); + puts("\t$(CC) -o ./mrbtest ./mrbtest.o ../../lib/libmruby.a ./driver.o $(CFLAGS) -lm"); + puts("\t./mrbtest"); + puts(""); puts(".PHONY : clean"); puts("clean :"); - dir_list("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)"); + puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); + dir_list("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", ""); } void @@ -83,12 +102,12 @@ make_init_gems() puts("#include \"mruby.h\""); puts(""); - dir_list("void mrb_", "_gem_init(mrb_state*);"); + dir_list("void mrb_", "_gem_init(mrb_state*);\n", "", ""); puts("void"); puts("mrb_init_mrbgems(mrb_state *mrb)"); puts("{"); - dir_list(" mrb_", "_gem_init(mrb);"); + dir_list(" mrb_", "_gem_init(mrb);\n", "", ""); puts("}"); } -- cgit v1.2.3 From a8d418d5b128bc1f63092fafd4037029b36c1748 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 20 Sep 2012 01:35:57 +0800 Subject: Remove TODO. This point is finished --- mrblib/Makefile | 3 --- 1 file changed, 3 deletions(-) diff --git a/mrblib/Makefile b/mrblib/Makefile index 9ba7ed0cf..def24d497 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -52,9 +52,6 @@ endif .PHONY : all all : $(LIBR) -# TODO: -# all available GEMS have to be added to the main library -# update libmruby.a $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) $(AR) rs $(LIBR) $(MLIB) -- cgit v1.2.3 From f93572c531c1e69dc0c5d2c2bfd03fc83044158c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 20 Sep 2012 18:41:16 +0800 Subject: Optimize Makefile --- mrbgems/Makefile | 2 +- mrbgems/gem_helper.c | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 6fde97128..0f2908ab9 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -42,7 +42,7 @@ all_gems : $(MMAKER_BIN) g/Makefile $(MAKE) -C g test : - $(MAKE) test -C g + @$(MAKE) test -C g # clean driver and all gems .PHONY : clean diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c index 01daef364..dd19ea2d0 100644 --- a/mrbgems/gem_helper.c +++ b/mrbgems/gem_helper.c @@ -69,14 +69,31 @@ make_gem_makefile() dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", ""); puts(".PHONY : test"); - puts("test :"); - dir_list("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp"); - puts("\t../../bin/mrbc -Bmrbtest_irep -omrbtest.ctmp mrbtest.rbtmp"); + puts("test : mrbtest"); + puts("\t@./mrbtest"); + puts(""); + + puts("mrbtest : driver.o mrbtest.o"); + puts("\t$(CC) $(CFLAGS) -o ./mrbtest ./mrbtest.o ../../lib/libmruby.a ./driver.o"); + puts(""); + + puts("driver.o : ../../test/driver.c"); + puts("\t$(CC) $(CFLAGS) -o $@ -c $<"); + puts(""); + + puts("mrbtest.o : mrbtest.c"); + puts(""); + + puts("mrbtest.c : mrbtest.ctmp"); puts("\tcat ../../test/init_mrbtest.c mrbtest.ctmp > mrbtest.c"); - puts("\t$(CC) -c ../../test/driver.c -o ./driver.o $(CFLAGS)"); - puts("\t$(CC) -c ./mrbtest.c -o ./mrbtest.o $(CFLAGS)"); - puts("\t$(CC) -o ./mrbtest ./mrbtest.o ../../lib/libmruby.a ./driver.o $(CFLAGS) -lm"); - puts("\t./mrbtest"); + puts(""); + + puts("mrbtest.ctmp : mrbtest.rbtmp"); + puts("\t../../bin/mrbc -Bmrbtest_irep -omrbtest.ctmp mrbtest.rbtmp"); + puts(""); + + puts("mrbtest.rbtmp :"); + dir_list("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp"); puts(""); puts(".PHONY : clean"); -- cgit v1.2.3 From d6f2f55b46ceddd986e7ba42fb8269aef0ca8e77 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 21 Sep 2012 19:56:28 +0800 Subject: Add Support for Ruby Extensions, C Extensions and Test Integration --- mrbgems/Makefile | 28 +++--- mrbgems/g/clib_example/Makefile | 12 +++ mrbgems/g/clib_example/README.md | 4 + mrbgems/g/clib_example/src/clib_example.c | 17 ++++ mrbgems/g/clib_example/test/clib_example.rb | 3 + mrbgems/g/hello_world/Makefile | 12 --- mrbgems/g/hello_world/README.md | 4 - mrbgems/g/hello_world/src/hello_world.c | 17 ---- mrbgems/g/hello_world/test/hello_world.rb | 3 - mrbgems/g/mrblib_example/Makefile | 7 ++ mrbgems/g/mrblib_example/README.md | 4 + mrbgems/g/mrblib_example/mrblib/mrblib_example.rb | 5 + mrbgems/g/mrblib_example/test/mrblib_example.rb | 3 + mrbgems/gem_helper.c | 108 +++++++++++++++++++--- 14 files changed, 166 insertions(+), 61 deletions(-) create mode 100644 mrbgems/g/clib_example/Makefile create mode 100644 mrbgems/g/clib_example/README.md create mode 100644 mrbgems/g/clib_example/src/clib_example.c create mode 100644 mrbgems/g/clib_example/test/clib_example.rb delete mode 100644 mrbgems/g/hello_world/Makefile delete mode 100644 mrbgems/g/hello_world/README.md delete mode 100644 mrbgems/g/hello_world/src/hello_world.c delete mode 100644 mrbgems/g/hello_world/test/hello_world.rb create mode 100644 mrbgems/g/mrblib_example/Makefile create mode 100644 mrbgems/g/mrblib_example/README.md create mode 100644 mrbgems/g/mrblib_example/mrblib/mrblib_example.rb create mode 100644 mrbgems/g/mrblib_example/test/mrblib_example.rb diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 0f2908ab9..1cb5b8a83 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -17,29 +17,31 @@ export AR = ar .PHONY : all all : $(INIT).o all_gems -$(MMAKER_BIN) : $(MMAKER).o - @echo "Build the generator which creates the driver and Gem Makefile" - $(LL) -o $@ $(CC_FLAGS) $< +all_gems : g/Makefile + @echo "Build all gems" + $(MAKE) -C g -$(MMAKER).o : $(MMAKER).c - $(CC) $(CC_FLAGS) -MMD -c $< -o $@ +g/Makefile : $(MMAKER_BIN) + @echo "Generate Gem Makefile" + $(MMAKER_BIN) makefile > $@ $(INIT).c : $(MMAKER_BIN) @echo "Generate Gem driver" $(MMAKER_BIN) $(INIT) > $@ $(INIT).o : $(INIT).c - @echo "Build the driver which initiailizes all gems" - gcc $(CC_FLAGS) -c $< -o $@ + @echo "Build the driver which initializes all gems" + $(CC) $(CC_FLAGS) -MMD -c $< -o $@ $(AR) rs $(LIBR) $@ -g/Makefile : - @echo "Generate Gem Makefile" - $(MMAKER_BIN) makefile > $@ +# Generator -all_gems : $(MMAKER_BIN) g/Makefile - @echo "Build all gems" - $(MAKE) -C g +$(MMAKER_BIN) : $(MMAKER).o + @echo "Build the generator which creates the driver and Gem Makefile" + $(LL) -o $@ $(CC_FLAGS) $< + +$(MMAKER).o : $(MMAKER).c + $(CC) $(CC_FLAGS) -MMD -c $< -o $@ test : @$(MAKE) test -C g diff --git a/mrbgems/g/clib_example/Makefile b/mrbgems/g/clib_example/Makefile new file mode 100644 index 000000000..2cd523905 --- /dev/null +++ b/mrbgems/g/clib_example/Makefile @@ -0,0 +1,12 @@ +include ../../Makefile4gem + +GEM := clib_example + +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) + +gem-all : $(GEM_OBJECTS) + $(AR) rs $(LIBR) $< + +gem-clean : + -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/clib_example/README.md b/mrbgems/g/clib_example/README.md new file mode 100644 index 000000000..289f6635d --- /dev/null +++ b/mrbgems/g/clib_example/README.md @@ -0,0 +1,4 @@ +CLib Extension Example +========= + +This is an example gem which implements a C extension. diff --git a/mrbgems/g/clib_example/src/clib_example.c b/mrbgems/g/clib_example/src/clib_example.c new file mode 100644 index 000000000..2ab8682b2 --- /dev/null +++ b/mrbgems/g/clib_example/src/clib_example.c @@ -0,0 +1,17 @@ +#include +#include + +static struct RClass *_class_clib; + +static mrb_value +mrb_clib_example(mrb_state *mrb, mrb_value self) +{ + puts("A C Extension"); + return self; +} + +void +mrb_clib_example_gem_init(mrb_state* mrb) { + _class_clib = mrb_define_module(mrb, "CLib"); + mrb_define_class_method(mrb, _class_clib, "clib_method", mrb_clib_example, ARGS_NONE()); +} diff --git a/mrbgems/g/clib_example/test/clib_example.rb b/mrbgems/g/clib_example/test/clib_example.rb new file mode 100644 index 000000000..348b9271d --- /dev/null +++ b/mrbgems/g/clib_example/test/clib_example.rb @@ -0,0 +1,3 @@ +assert('CLib Extension') do + CLib.respond_to? :clib_method +end diff --git a/mrbgems/g/hello_world/Makefile b/mrbgems/g/hello_world/Makefile deleted file mode 100644 index c03910bf6..000000000 --- a/mrbgems/g/hello_world/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../../Makefile4gem - -GEM := hello_world - -GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) -GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) - -gem-all : $(GEM_OBJECTS) - $(AR) rs $(LIBR) $< - -gem-clean : - -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/hello_world/README.md b/mrbgems/g/hello_world/README.md deleted file mode 100644 index 42792567f..000000000 --- a/mrbgems/g/hello_world/README.md +++ /dev/null @@ -1,4 +0,0 @@ -hello world -========= - -This is an example gem which implements just one method +HW.say+ in a C extension. diff --git a/mrbgems/g/hello_world/src/hello_world.c b/mrbgems/g/hello_world/src/hello_world.c deleted file mode 100644 index 75d353542..000000000 --- a/mrbgems/g/hello_world/src/hello_world.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -static struct RClass *_class_hw; - -static mrb_value -mrb_hello_world(mrb_state *mrb, mrb_value self) -{ - puts("Hello World"); - return self; -} - -void -mrb_hello_world_gem_init(mrb_state* mrb) { - _class_hw = mrb_define_module(mrb, "HW"); - mrb_define_class_method(mrb, _class_hw, "say", mrb_hello_world, ARGS_NONE()); -} diff --git a/mrbgems/g/hello_world/test/hello_world.rb b/mrbgems/g/hello_world/test/hello_world.rb deleted file mode 100644 index 2d8c335db..000000000 --- a/mrbgems/g/hello_world/test/hello_world.rb +++ /dev/null @@ -1,3 +0,0 @@ -assert('Hello World') do - HW.respond_to? :say -end diff --git a/mrbgems/g/mrblib_example/Makefile b/mrbgems/g/mrblib_example/Makefile new file mode 100644 index 000000000..a43677842 --- /dev/null +++ b/mrbgems/g/mrblib_example/Makefile @@ -0,0 +1,7 @@ +include ../../Makefile4gem + +GEM := mrblib_example + +gem-all : + +gem-clean : diff --git a/mrbgems/g/mrblib_example/README.md b/mrbgems/g/mrblib_example/README.md new file mode 100644 index 000000000..42792567f --- /dev/null +++ b/mrbgems/g/mrblib_example/README.md @@ -0,0 +1,4 @@ +hello world +========= + +This is an example gem which implements just one method +HW.say+ in a C extension. diff --git a/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb b/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb new file mode 100644 index 000000000..444f32236 --- /dev/null +++ b/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb @@ -0,0 +1,5 @@ +class MRBLib + def MRBLib.mrblib_method + puts "A Ruby Extension" + end +end diff --git a/mrbgems/g/mrblib_example/test/mrblib_example.rb b/mrbgems/g/mrblib_example/test/mrblib_example.rb new file mode 100644 index 000000000..40189ffdd --- /dev/null +++ b/mrbgems/g/mrblib_example/test/mrblib_example.rb @@ -0,0 +1,3 @@ +assert('MRBLib extension') do + MRBLib.respond_to? :mrblib_method +end diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c index dd19ea2d0..24b959df9 100644 --- a/mrbgems/gem_helper.c +++ b/mrbgems/gem_helper.c @@ -1,22 +1,61 @@ #include #include #include +#include +#include #include - +#include + static int one (const struct dirent *unused) { return 1; } +/* + * Does a directory exist? + * yes => TRUE + * no => FALSE + * fs error => FALSE + * + */ +static int +directory_exists(char path[4096]) { + DIR* dir = opendir(path); + if (dir) + return TRUE; + else + return FALSE; +} + +/* + * Template generator for each GEM + * + * Arguments: + * before: + * String before each GEM template + * after: + * String after each GEM template + * start: + * String at the start of the template + * end: + * String at the end of the template + * skip_if_src_not_exist: + * TRUE => skip template for GEMs with SRC directory + * FALSE => template for all GEMs + * + */ void -dir_list (char before[1024], char after[1024], char start[1024], char end[1024]) +for_each_gem (char before[1024], char after[1024], + char start[1024], char end[1024], + char dir_to_skip[1024]) { struct dirent **eps; int n; char gemname[1024] = ""; char gemname_path[4096] = ""; char complete_line[4096] = ""; + char src_path[4096] = ""; struct stat attribut; strcat(complete_line, start); @@ -28,6 +67,8 @@ dir_list (char before[1024], char after[1024], char start[1024], char end[1024]) strcpy(gemname, eps[cnt]->d_name); strcpy(gemname_path, "./g/"); strcat(gemname_path, gemname); + strcpy(src_path, gemname_path); + strcat(src_path, "/src"); if (strcmp(gemname, ".") == 0) continue; @@ -35,13 +76,22 @@ dir_list (char before[1024], char after[1024], char start[1024], char end[1024]) continue; stat(gemname_path, &attribut); - if (S_ISDIR(attribut.st_mode) == 0) + if (S_ISDIR(attribut.st_mode) == 0) { continue; + } + + if (strcmp(dir_to_skip, "") != 0) { + strcpy(src_path, gemname_path); + strcat(src_path, "/"); + strcat(src_path, dir_to_skip); + + if (directory_exists(src_path) != TRUE) + continue; + } strcat(complete_line, before); strcat(complete_line, gemname); strcat(complete_line, after); - } } else { @@ -65,8 +115,28 @@ make_gem_makefile() puts(""); puts(".PHONY : all"); - puts("all :"); - dir_list("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", ""); + puts("all : all_gems mrblib_gem.o"); + puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + puts(""); + + puts("all_gems :"); + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", ""); + puts(""); + + puts("mrblib_gem.o : mrblib_gem.c"); + puts(""); + + puts("mrblib_gem.c : mrblib_gem.ctmp"); + puts("\tcat $< > $@"); + puts(""); + + puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); + puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); + puts(""); + + puts("mrblib_gem.rbtmp :"); + for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib"); + puts(""); puts(".PHONY : test"); puts("test : mrbtest"); @@ -93,13 +163,13 @@ make_gem_makefile() puts(""); puts("mrbtest.rbtmp :"); - dir_list("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp"); + for_each_gem("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp", ""); puts(""); puts(".PHONY : clean"); puts("clean :"); puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); - dir_list("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", ""); + for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", ""); } void @@ -117,14 +187,28 @@ make_init_gems() puts(""); puts("#include \"mruby.h\""); + puts("#include \"mruby/irep.h\""); + puts("#include \"mruby/dump.h\""); + puts("#include \"mruby/string.h\""); + puts("#include \"mruby/proc.h\""); puts(""); - dir_list("void mrb_", "_gem_init(mrb_state*);\n", "", ""); + for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src"); + + puts("extern const char mrblib_gem_irep[];"); + puts(""); puts("void"); - puts("mrb_init_mrbgems(mrb_state *mrb)"); - puts("{"); - dir_list(" mrb_", "_gem_init(mrb);\n", "", ""); + puts("mrb_init_mrbgems(mrb_state *mrb) {"); + + for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src"); + + puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); + puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); + puts(" if (mrb->exc) {"); + puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); + puts(" exit(0);"); + puts(" }"); puts("}"); } -- cgit v1.2.3 From 81225a9f0e4cf6d27e303f203833bb726b191465 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 21 Sep 2012 19:59:41 +0800 Subject: Remove symbol recreation where not necessary --- mrblib/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrblib/Makefile b/mrblib/Makefile index def24d497..942b3e1d2 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -54,7 +54,7 @@ all : $(LIBR) $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) - $(AR) rs $(LIBR) $(MLIB) + $(AR) r $(LIBR) $(MLIB) # Compile mrblib source $(MLIB) : $(CLIB) -- cgit v1.2.3 From 668b22899f5067a5eb1d86b9eab9b99f9fae85c0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 21 Sep 2012 20:10:35 +0800 Subject: Modify README for examples --- mrbgems/g/clib_example/README.md | 2 +- mrbgems/g/mrblib_example/README.md | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/mrbgems/g/clib_example/README.md b/mrbgems/g/clib_example/README.md index 289f6635d..3803c2065 100644 --- a/mrbgems/g/clib_example/README.md +++ b/mrbgems/g/clib_example/README.md @@ -1,4 +1,4 @@ -CLib Extension Example +C Extension Example ========= This is an example gem which implements a C extension. diff --git a/mrbgems/g/mrblib_example/README.md b/mrbgems/g/mrblib_example/README.md index 42792567f..906a0d8f2 100644 --- a/mrbgems/g/mrblib_example/README.md +++ b/mrbgems/g/mrblib_example/README.md @@ -1,4 +1,4 @@ -hello world +Pure Ruby Extension Example ========= -This is an example gem which implements just one method +HW.say+ in a C extension. +This is an example gem which implements a pure Ruby extension. -- cgit v1.2.3 From 80b7f45fd17bac6f3623c92eceda26f6fbf72a64 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 21 Sep 2012 20:21:14 +0800 Subject: Rename Gem Examples --- mrbgems/g/c_extension_example/Makefile | 12 ++++++++++++ mrbgems/g/c_extension_example/README.md | 4 ++++ mrbgems/g/c_extension_example/src/example.c | 17 +++++++++++++++++ mrbgems/g/c_extension_example/test/example.rb | 3 +++ mrbgems/g/clib_example/Makefile | 12 ------------ mrbgems/g/clib_example/README.md | 4 ---- mrbgems/g/clib_example/src/clib_example.c | 17 ----------------- mrbgems/g/clib_example/test/clib_example.rb | 3 --- mrbgems/g/mrblib_example/Makefile | 7 ------- mrbgems/g/mrblib_example/README.md | 4 ---- mrbgems/g/mrblib_example/mrblib/mrblib_example.rb | 5 ----- mrbgems/g/mrblib_example/test/mrblib_example.rb | 3 --- mrbgems/g/ruby_extension_example/Makefile | 7 +++++++ mrbgems/g/ruby_extension_example/README.md | 4 ++++ mrbgems/g/ruby_extension_example/mrblib/example.rb | 5 +++++ mrbgems/g/ruby_extension_example/test/example.rb | 3 +++ 16 files changed, 55 insertions(+), 55 deletions(-) create mode 100644 mrbgems/g/c_extension_example/Makefile create mode 100644 mrbgems/g/c_extension_example/README.md create mode 100644 mrbgems/g/c_extension_example/src/example.c create mode 100644 mrbgems/g/c_extension_example/test/example.rb delete mode 100644 mrbgems/g/clib_example/Makefile delete mode 100644 mrbgems/g/clib_example/README.md delete mode 100644 mrbgems/g/clib_example/src/clib_example.c delete mode 100644 mrbgems/g/clib_example/test/clib_example.rb delete mode 100644 mrbgems/g/mrblib_example/Makefile delete mode 100644 mrbgems/g/mrblib_example/README.md delete mode 100644 mrbgems/g/mrblib_example/mrblib/mrblib_example.rb delete mode 100644 mrbgems/g/mrblib_example/test/mrblib_example.rb create mode 100644 mrbgems/g/ruby_extension_example/Makefile create mode 100644 mrbgems/g/ruby_extension_example/README.md create mode 100644 mrbgems/g/ruby_extension_example/mrblib/example.rb create mode 100644 mrbgems/g/ruby_extension_example/test/example.rb diff --git a/mrbgems/g/c_extension_example/Makefile b/mrbgems/g/c_extension_example/Makefile new file mode 100644 index 000000000..b245e9696 --- /dev/null +++ b/mrbgems/g/c_extension_example/Makefile @@ -0,0 +1,12 @@ +include ../../Makefile4gem + +GEM := c_extension_example + +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) + +gem-all : $(GEM_OBJECTS) + $(AR) rs $(LIBR) $< + +gem-clean : + -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/c_extension_example/README.md b/mrbgems/g/c_extension_example/README.md new file mode 100644 index 000000000..3803c2065 --- /dev/null +++ b/mrbgems/g/c_extension_example/README.md @@ -0,0 +1,4 @@ +C Extension Example +========= + +This is an example gem which implements a C extension. diff --git a/mrbgems/g/c_extension_example/src/example.c b/mrbgems/g/c_extension_example/src/example.c new file mode 100644 index 000000000..9f0b07839 --- /dev/null +++ b/mrbgems/g/c_extension_example/src/example.c @@ -0,0 +1,17 @@ +#include +#include + +static struct RClass *_class_cextension; + +static mrb_value +mrb_c_method(mrb_state *mrb, mrb_value self) +{ + puts("A C Extension"); + return self; +} + +void +mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} diff --git a/mrbgems/g/c_extension_example/test/example.rb b/mrbgems/g/c_extension_example/test/example.rb new file mode 100644 index 000000000..367d18029 --- /dev/null +++ b/mrbgems/g/c_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('C Extension Example') do + CExtension.respond_to? :c_method +end diff --git a/mrbgems/g/clib_example/Makefile b/mrbgems/g/clib_example/Makefile deleted file mode 100644 index 2cd523905..000000000 --- a/mrbgems/g/clib_example/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../../Makefile4gem - -GEM := clib_example - -GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) -GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) - -gem-all : $(GEM_OBJECTS) - $(AR) rs $(LIBR) $< - -gem-clean : - -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/clib_example/README.md b/mrbgems/g/clib_example/README.md deleted file mode 100644 index 3803c2065..000000000 --- a/mrbgems/g/clib_example/README.md +++ /dev/null @@ -1,4 +0,0 @@ -C Extension Example -========= - -This is an example gem which implements a C extension. diff --git a/mrbgems/g/clib_example/src/clib_example.c b/mrbgems/g/clib_example/src/clib_example.c deleted file mode 100644 index 2ab8682b2..000000000 --- a/mrbgems/g/clib_example/src/clib_example.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -static struct RClass *_class_clib; - -static mrb_value -mrb_clib_example(mrb_state *mrb, mrb_value self) -{ - puts("A C Extension"); - return self; -} - -void -mrb_clib_example_gem_init(mrb_state* mrb) { - _class_clib = mrb_define_module(mrb, "CLib"); - mrb_define_class_method(mrb, _class_clib, "clib_method", mrb_clib_example, ARGS_NONE()); -} diff --git a/mrbgems/g/clib_example/test/clib_example.rb b/mrbgems/g/clib_example/test/clib_example.rb deleted file mode 100644 index 348b9271d..000000000 --- a/mrbgems/g/clib_example/test/clib_example.rb +++ /dev/null @@ -1,3 +0,0 @@ -assert('CLib Extension') do - CLib.respond_to? :clib_method -end diff --git a/mrbgems/g/mrblib_example/Makefile b/mrbgems/g/mrblib_example/Makefile deleted file mode 100644 index a43677842..000000000 --- a/mrbgems/g/mrblib_example/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../../Makefile4gem - -GEM := mrblib_example - -gem-all : - -gem-clean : diff --git a/mrbgems/g/mrblib_example/README.md b/mrbgems/g/mrblib_example/README.md deleted file mode 100644 index 906a0d8f2..000000000 --- a/mrbgems/g/mrblib_example/README.md +++ /dev/null @@ -1,4 +0,0 @@ -Pure Ruby Extension Example -========= - -This is an example gem which implements a pure Ruby extension. diff --git a/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb b/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb deleted file mode 100644 index 444f32236..000000000 --- a/mrbgems/g/mrblib_example/mrblib/mrblib_example.rb +++ /dev/null @@ -1,5 +0,0 @@ -class MRBLib - def MRBLib.mrblib_method - puts "A Ruby Extension" - end -end diff --git a/mrbgems/g/mrblib_example/test/mrblib_example.rb b/mrbgems/g/mrblib_example/test/mrblib_example.rb deleted file mode 100644 index 40189ffdd..000000000 --- a/mrbgems/g/mrblib_example/test/mrblib_example.rb +++ /dev/null @@ -1,3 +0,0 @@ -assert('MRBLib extension') do - MRBLib.respond_to? :mrblib_method -end diff --git a/mrbgems/g/ruby_extension_example/Makefile b/mrbgems/g/ruby_extension_example/Makefile new file mode 100644 index 000000000..7ebec4f09 --- /dev/null +++ b/mrbgems/g/ruby_extension_example/Makefile @@ -0,0 +1,7 @@ +include ../../Makefile4gem + +GEM := ruby_extension_example + +gem-all : + +gem-clean : diff --git a/mrbgems/g/ruby_extension_example/README.md b/mrbgems/g/ruby_extension_example/README.md new file mode 100644 index 000000000..906a0d8f2 --- /dev/null +++ b/mrbgems/g/ruby_extension_example/README.md @@ -0,0 +1,4 @@ +Pure Ruby Extension Example +========= + +This is an example gem which implements a pure Ruby extension. diff --git a/mrbgems/g/ruby_extension_example/mrblib/example.rb b/mrbgems/g/ruby_extension_example/mrblib/example.rb new file mode 100644 index 000000000..b07a2b580 --- /dev/null +++ b/mrbgems/g/ruby_extension_example/mrblib/example.rb @@ -0,0 +1,5 @@ +class RubyExtension + def RubyExtension.ruby_method + puts "A Ruby Extension" + end +end diff --git a/mrbgems/g/ruby_extension_example/test/example.rb b/mrbgems/g/ruby_extension_example/test/example.rb new file mode 100644 index 000000000..0c1b63469 --- /dev/null +++ b/mrbgems/g/ruby_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('Ruby Extension Example') do + RubyExtension.respond_to? :ruby_method +end -- cgit v1.2.3 From 0e7d5a2e4bcca01a41ea00324261818440808e6f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 01:16:26 +0800 Subject: Move Gem Tests into the main Test target --- Makefile | 1 - mrbgems/Makefile | 7 +- mrbgems/gem_helper.c | 232 --------------------------------------------------- mrbgems/generator.c | 216 +++++++++++++++++++++++++++++++++++++++++++++++ test/Makefile | 7 +- test/init_mrbtest.c | 3 + 6 files changed, 228 insertions(+), 238 deletions(-) delete mode 100644 mrbgems/gem_helper.c create mode 100644 mrbgems/generator.c diff --git a/Makefile b/Makefile index 6866ec9e3..d18222c3c 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,6 @@ all : .PHONY : test test : all @$(MAKE) -C test $(MAKE_FLAGS) - @$(MAKE) test -C mrbgems $(MAKE_FLAGS) # clean up .PHONY : clean diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 1cb5b8a83..d12e85ab4 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -5,7 +5,7 @@ LIBR := ../lib/libmruby.a INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -MMAKER := ./gem_helper +MMAKER := ./generator MMAKER_BIN := $(MMAKER) export CC = gcc export LL = gcc @@ -43,8 +43,9 @@ $(MMAKER_BIN) : $(MMAKER).o $(MMAKER).o : $(MMAKER).c $(CC) $(CC_FLAGS) -MMD -c $< -o $@ -test : - @$(MAKE) test -C g +.PHONY : prepare-test +prepare-test : + @$(MAKE) prepare-test -C g # clean driver and all gems .PHONY : clean diff --git a/mrbgems/gem_helper.c b/mrbgems/gem_helper.c deleted file mode 100644 index 24b959df9..000000000 --- a/mrbgems/gem_helper.c +++ /dev/null @@ -1,232 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -static int -one (const struct dirent *unused) -{ - return 1; -} - -/* - * Does a directory exist? - * yes => TRUE - * no => FALSE - * fs error => FALSE - * - */ -static int -directory_exists(char path[4096]) { - DIR* dir = opendir(path); - if (dir) - return TRUE; - else - return FALSE; -} - -/* - * Template generator for each GEM - * - * Arguments: - * before: - * String before each GEM template - * after: - * String after each GEM template - * start: - * String at the start of the template - * end: - * String at the end of the template - * skip_if_src_not_exist: - * TRUE => skip template for GEMs with SRC directory - * FALSE => template for all GEMs - * - */ -void -for_each_gem (char before[1024], char after[1024], - char start[1024], char end[1024], - char dir_to_skip[1024]) -{ - struct dirent **eps; - int n; - char gemname[1024] = ""; - char gemname_path[4096] = ""; - char complete_line[4096] = ""; - char src_path[4096] = ""; - struct stat attribut; - - strcat(complete_line, start); - - n = scandir("./g", &eps, one, alphasort); - if (n >= 0) { - int cnt; - for (cnt = 0; cnt < n; ++cnt) { - strcpy(gemname, eps[cnt]->d_name); - strcpy(gemname_path, "./g/"); - strcat(gemname_path, gemname); - strcpy(src_path, gemname_path); - strcat(src_path, "/src"); - - if (strcmp(gemname, ".") == 0) - continue; - if (strcmp(gemname, "..") == 0) - continue; - - stat(gemname_path, &attribut); - if (S_ISDIR(attribut.st_mode) == 0) { - continue; - } - - if (strcmp(dir_to_skip, "") != 0) { - strcpy(src_path, gemname_path); - strcat(src_path, "/"); - strcat(src_path, dir_to_skip); - - if (directory_exists(src_path) != TRUE) - continue; - } - - strcat(complete_line, before); - strcat(complete_line, gemname); - strcat(complete_line, after); - } - } - else { - perror("Error while scanning the directory."); - } - - strcat(complete_line, end); - puts(complete_line); -} - -void -make_gem_makefile() -{ - puts("CFLAGS := -I. -I../../include -I../../src"); - puts(""); - puts("ifeq ($(OS),Windows_NT)"); - puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'"); - puts("else"); - puts("MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'"); - puts("endif"); - puts(""); - - puts(".PHONY : all"); - puts("all : all_gems mrblib_gem.o"); - puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); - puts(""); - - puts("all_gems :"); - for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", ""); - puts(""); - - puts("mrblib_gem.o : mrblib_gem.c"); - puts(""); - - puts("mrblib_gem.c : mrblib_gem.ctmp"); - puts("\tcat $< > $@"); - puts(""); - - puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); - puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); - puts(""); - - puts("mrblib_gem.rbtmp :"); - for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib"); - puts(""); - - puts(".PHONY : test"); - puts("test : mrbtest"); - puts("\t@./mrbtest"); - puts(""); - - puts("mrbtest : driver.o mrbtest.o"); - puts("\t$(CC) $(CFLAGS) -o ./mrbtest ./mrbtest.o ../../lib/libmruby.a ./driver.o"); - puts(""); - - puts("driver.o : ../../test/driver.c"); - puts("\t$(CC) $(CFLAGS) -o $@ -c $<"); - puts(""); - - puts("mrbtest.o : mrbtest.c"); - puts(""); - - puts("mrbtest.c : mrbtest.ctmp"); - puts("\tcat ../../test/init_mrbtest.c mrbtest.ctmp > mrbtest.c"); - puts(""); - - puts("mrbtest.ctmp : mrbtest.rbtmp"); - puts("\t../../bin/mrbc -Bmrbtest_irep -omrbtest.ctmp mrbtest.rbtmp"); - puts(""); - - puts("mrbtest.rbtmp :"); - for_each_gem("", "/test/*.rb ", "\tcat ../../test/assert.rb ", "> mrbtest.rbtmp", ""); - puts(""); - - puts(".PHONY : clean"); - puts("clean :"); - puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); - for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", ""); -} - -void -make_init_gems() -{ - puts("/*"); - puts(" * This file contains a list of all"); - puts(" * initializing methods which are"); - puts(" * necessary to bootstrap all gems."); - puts(" *"); - puts(" * IMPORTANT:"); - puts(" * This file was generated!"); - puts(" * All manual changes will get lost."); - puts(" */"); - - puts(""); - puts("#include \"mruby.h\""); - puts("#include \"mruby/irep.h\""); - puts("#include \"mruby/dump.h\""); - puts("#include \"mruby/string.h\""); - puts("#include \"mruby/proc.h\""); - puts(""); - - for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src"); - - puts("extern const char mrblib_gem_irep[];"); - puts(""); - - puts("void"); - puts("mrb_init_mrbgems(mrb_state *mrb) {"); - - for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src"); - - puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); - puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); - puts(" if (mrb->exc) {"); - puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); - puts(" exit(0);"); - puts(" }"); - puts("}"); -} - -int -main (int argc, char *argv[]) -{ - if (argc == 2) { - if (strcmp(argv[1], "makefile") == 0) - make_gem_makefile(); - else if (strcmp(argv[1], "init_gems") == 0) - make_init_gems(); - else - return 1; - } - else { - puts("Argument missing! Options: 'makefile', 'init_gems'"); - return 1; - } - - return 0; -} diff --git a/mrbgems/generator.c b/mrbgems/generator.c new file mode 100644 index 000000000..8d8bee0cf --- /dev/null +++ b/mrbgems/generator.c @@ -0,0 +1,216 @@ +#include +#include +#include +#include +#include +#include +#include + +static int +one (const struct dirent *unused) +{ + return 1; +} + +/* + * Does a directory exist? + * yes => TRUE + * no => FALSE + * fs error => FALSE + * + */ +static int +directory_exists(char path[4096]) { + DIR* dir = opendir(path); + if (dir) + return TRUE; + else + return FALSE; +} + +/* + * Template generator for each GEM + * + * Arguments: + * before: + * String before each GEM template + * after: + * String after each GEM template + * start: + * String at the start of the template + * end: + * String at the end of the template + * skip_if_src_not_exist: + * TRUE => skip template for GEMs with SRC directory + * FALSE => template for all GEMs + * + */ +void +for_each_gem (char before[1024], char after[1024], + char start[1024], char end[1024], + char dir_to_skip[1024]) +{ + struct dirent **eps; + int n; + char gemname[1024] = ""; + char gemname_path[4096] = ""; + char complete_line[4096] = ""; + char src_path[4096] = ""; + struct stat attribut; + + strcat(complete_line, start); + + n = scandir("./g", &eps, one, alphasort); + if (n >= 0) { + int cnt; + for (cnt = 0; cnt < n; ++cnt) { + strcpy(gemname, eps[cnt]->d_name); + strcpy(gemname_path, "./g/"); + strcat(gemname_path, gemname); + strcpy(src_path, gemname_path); + strcat(src_path, "/src"); + + if (strcmp(gemname, ".") == 0) + continue; + if (strcmp(gemname, "..") == 0) + continue; + + stat(gemname_path, &attribut); + if (S_ISDIR(attribut.st_mode) == 0) { + continue; + } + + if (strcmp(dir_to_skip, "") != 0) { + strcpy(src_path, gemname_path); + strcat(src_path, "/"); + strcat(src_path, dir_to_skip); + + if (directory_exists(src_path) != TRUE) + continue; + } + + strcat(complete_line, before); + strcat(complete_line, gemname); + strcat(complete_line, after); + } + } + else { + perror("Error while scanning the directory."); + } + + strcat(complete_line, end); + puts(complete_line); +} + +void +make_gem_makefile() +{ + puts("CFLAGS := -I. -I../../include -I../../src"); + puts(""); + puts("ifeq ($(OS),Windows_NT)"); + puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'"); + puts("else"); + puts("MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'"); + puts("endif"); + puts(""); + + puts(".PHONY : all"); + puts("all : all_gems mrblib_gem.o"); + puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + puts(""); + + puts("all_gems :"); + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", ""); + puts(""); + + puts("mrblib_gem.o : mrblib_gem.c"); + puts(""); + + puts("mrblib_gem.c : mrblib_gem.ctmp"); + puts("\tcat $< > $@"); + puts(""); + + puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); + puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); + puts(""); + + puts("mrblib_gem.rbtmp :"); + for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib"); + puts(""); + + puts(".PHONY : prepare-test"); + puts("prepare-test : mrbgemtest.ctmp"); + puts(""); + + puts("mrbgemtest.ctmp : mrbgemtest.rbtmp"); + puts("\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp"); + puts(""); + + puts("mrbgemtest.rbtmp :"); + for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", ""); + puts(""); + + puts(".PHONY : clean"); + puts("clean :"); + puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); + for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", ""); +} + +void +make_init_gems() +{ + puts("/*"); + puts(" * This file contains a list of all"); + puts(" * initializing methods which are"); + puts(" * necessary to bootstrap all gems."); + puts(" *"); + puts(" * IMPORTANT:"); + puts(" * This file was generated!"); + puts(" * All manual changes will get lost."); + puts(" */"); + + puts(""); + puts("#include \"mruby.h\""); + puts("#include \"mruby/irep.h\""); + puts("#include \"mruby/dump.h\""); + puts("#include \"mruby/string.h\""); + puts("#include \"mruby/proc.h\""); + puts(""); + + for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src"); + + puts("extern const char mrblib_gem_irep[];"); + puts(""); + + puts("void"); + puts("mrb_init_mrbgems(mrb_state *mrb) {"); + + for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src"); + + puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); + puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); + puts(" if (mrb->exc) {"); + puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); + puts(" exit(0);"); + puts(" }"); + puts("}"); +} + +int +main (int argc, char *argv[]) +{ + if (argc == 2) { + if (strcmp(argv[1], "makefile") == 0) + make_gem_makefile(); + else if (strcmp(argv[1], "init_gems") == 0) + make_init_gems(); + else + return 1; + } + else { + puts("Argument missing! Options: 'makefile', 'init_gems'"); + return 1; + } + + return 0; +} diff --git a/test/Makefile b/test/Makefile index 18bc79b5a..efabdc367 100644 --- a/test/Makefile +++ b/test/Makefile @@ -68,13 +68,16 @@ $(OBJS) : %.o : %.c $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ # Compile C source from merged mruby source -$(CLIB) : $(RLIB) $(MRBC) $(INIT) - $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); $(CAT) $(INIT) $(DLIB) > $@ +$(CLIB) : ../mrbgems/g/mrbgemtest.ctmp $(RLIB) $(MRBC) $(INIT) + $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); $(CAT) $(INIT) $(DLIB) ../mrbgems/g/mrbgemtest.ctmp > $@ # merge mruby sources $(RLIB) : $(ASSLIB) $(MRBS) $(CAT) $(ASSLIB) $(MRBS) > $@ +../mrbgems/g/mrbgemtest.ctmp : + @$(MAKE) prepare-test -C ../mrbgems + # clean up .PHONY : clean clean : diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index b9f09dd2f..2bc2f2e4b 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -5,13 +5,16 @@ #include "mruby/proc.h" extern const char mrbtest_irep[]; +extern const char mrbgemtest_irep[]; void mrb_init_mrbtest(mrb_state *mrb) { int n = mrb_read_irep(mrb, mrbtest_irep); + int m = mrb_read_irep(mrb, mrbgemtest_irep); mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); + mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[m]), mrb_top_self(mrb)); if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(0); -- cgit v1.2.3 From df91989bf760d206a3b3d035f2425caa65d35d60 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 02:07:15 +0800 Subject: Optimize Makefiles --- mrbgems/Makefile | 35 ++++++++++++++++++++++------------- mrbgems/generator.c | 8 ++++++++ test/Makefile | 22 +++++++++++++--------- 3 files changed, 43 insertions(+), 22 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index d12e85ab4..466ac18e1 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -5,29 +5,37 @@ LIBR := ../lib/libmruby.a INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include -MMAKER := ./generator -MMAKER_BIN := $(MMAKER) + export CC = gcc export LL = gcc export AR = ar +GENERATOR := ./generator +ifeq ($(OS),Windows_NT) + GENERATOR_BIN := $(GENERATOR).exe +else + GENERATOR_BIN := $(GENERATOR) +endif +GEM_MAKEFILE := g/Makefile +GEMDLIB := g/mrbgemtest.ctmp + ############################## # generic build targets, rules .PHONY : all all : $(INIT).o all_gems -all_gems : g/Makefile +all_gems : GEM_MAKEFILE @echo "Build all gems" $(MAKE) -C g -g/Makefile : $(MMAKER_BIN) +GEM_MAKEFILE : $(GENERATOR_BIN) @echo "Generate Gem Makefile" - $(MMAKER_BIN) makefile > $@ + $(GENERATOR_BIN) makefile > $@ -$(INIT).c : $(MMAKER_BIN) +$(INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" - $(MMAKER_BIN) $(INIT) > $@ + $(GENERATOR_BIN) $(INIT) > $@ $(INIT).o : $(INIT).c @echo "Build the driver which initializes all gems" @@ -36,21 +44,22 @@ $(INIT).o : $(INIT).c # Generator -$(MMAKER_BIN) : $(MMAKER).o +$(GENERATOR_BIN) : $(GENERATOR).o @echo "Build the generator which creates the driver and Gem Makefile" $(LL) -o $@ $(CC_FLAGS) $< -$(MMAKER).o : $(MMAKER).c +$(GENERATOR).o : $(GENERATOR).c $(CC) $(CC_FLAGS) -MMD -c $< -o $@ .PHONY : prepare-test -prepare-test : +prepare-test : $(GEMDLIB) + +$(GEMDLIB) : @$(MAKE) prepare-test -C g # clean driver and all gems .PHONY : clean -clean : $(MMAKER_BIN) +clean : GEM_MAKEFILE @echo "Cleanup Gems" - $(MMAKER_BIN) makefile > g/Makefile $(MAKE) clean -C g - -$(RM_F) $(INIT).c *.o *.d $(MMAKER_BIN) g/Makefile + -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) GEM_MAKEFILE diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 8d8bee0cf..7015f5a4d 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -102,6 +102,10 @@ for_each_gem (char before[1024], char after[1024], puts(complete_line); } +/* + * Gem Makefile Generator + * + */ void make_gem_makefile() { @@ -156,6 +160,10 @@ make_gem_makefile() for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", ""); } +/* + * init_gems.c Generator + * + */ void make_init_gems() { diff --git a/test/Makefile b/test/Makefile index efabdc367..04722e2d1 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,6 +10,8 @@ MLIB := $(TARGET).o CLIB := $(TARGET).c INIT := init_$(TARGET).c DLIB := $(TARGET).ctmp +GEMDIR := ../mrbgems +GEMDLIB := $(GEMDIR)/g/mrbgemtest.ctmp RLIB := $(TARGET).rbtmp DEPLIB := $(TARGET).d driver.d ASSLIB := $(BASEDIR)/assert.rb @@ -42,14 +44,13 @@ endif # mruby compiler and test driver ifeq ($(OS),Windows_NT) -MRBC = ../bin/mrbc.exe -EXE := $(TARGET).exe + MRBC = ../bin/mrbc.exe + EXE := $(TARGET).exe else -MRBC = ../bin/mrbc -EXE := $(TARGET) + MRBC = ../bin/mrbc + EXE := $(TARGET) endif - ############################## # generic build targets, rules @@ -68,15 +69,18 @@ $(OBJS) : %.o : %.c $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ # Compile C source from merged mruby source -$(CLIB) : ../mrbgems/g/mrbgemtest.ctmp $(RLIB) $(MRBC) $(INIT) - $(MRBC) -Bmrbtest_irep -o$(DLIB) $(RLIB); $(CAT) $(INIT) $(DLIB) ../mrbgems/g/mrbgemtest.ctmp > $@ +$(CLIB) : $(DLIB) $(GEMDLIB) $(INIT) + $(CAT) $(INIT) $(DLIB) $(GEMDLIB) > $@ + +$(DLIB) : $(RLIB) $(MRBC) + $(MRBC) -Bmrbtest_irep -o$@ $(RLIB) # merge mruby sources $(RLIB) : $(ASSLIB) $(MRBS) $(CAT) $(ASSLIB) $(MRBS) > $@ -../mrbgems/g/mrbgemtest.ctmp : - @$(MAKE) prepare-test -C ../mrbgems +$(GEMDLIB) : + @$(MAKE) prepare-test -C $(GEMDIR) # clean up .PHONY : clean -- cgit v1.2.3 From 2a6152a1e0f741955befacfa4b3c0ece7b53d007 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 02:14:34 +0800 Subject: Fix Makefile --- mrbgems/Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 466ac18e1..25fe955a4 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -25,11 +25,11 @@ GEMDLIB := g/mrbgemtest.ctmp .PHONY : all all : $(INIT).o all_gems -all_gems : GEM_MAKEFILE +all_gems : $(GEM_MAKEFILE) @echo "Build all gems" $(MAKE) -C g -GEM_MAKEFILE : $(GENERATOR_BIN) +$(GEM_MAKEFILE) : $(GENERATOR_BIN) @echo "Generate Gem Makefile" $(GENERATOR_BIN) makefile > $@ @@ -62,4 +62,4 @@ $(GEMDLIB) : clean : GEM_MAKEFILE @echo "Cleanup Gems" $(MAKE) clean -C g - -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) GEM_MAKEFILE + -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) -- cgit v1.2.3 From 7b8b3c0213eb71df0a10493111ccb383b31b9731 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 02:16:13 +0800 Subject: Another fix for Makefile --- mrbgems/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 25fe955a4..ab8b364ac 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -59,7 +59,7 @@ $(GEMDLIB) : # clean driver and all gems .PHONY : clean -clean : GEM_MAKEFILE +clean : $(GEM_MAKEFILE) @echo "Cleanup Gems" $(MAKE) clean -C g -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) -- cgit v1.2.3 From 62b652c2925b2f71972b201a8134cf22183102b0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 22 Sep 2012 15:42:29 +0800 Subject: Catch some corner cases --- doc/mrbgems/README.md | 54 +++++++ doc/mrbgems/c_extension_example/Makefile | 12 ++ doc/mrbgems/c_extension_example/README.md | 4 + doc/mrbgems/c_extension_example/src/example.c | 17 +++ doc/mrbgems/c_extension_example/test/example.rb | 3 + doc/mrbgems/ruby_extension_example/Makefile | 7 + doc/mrbgems/ruby_extension_example/README.md | 4 + .../ruby_extension_example/mrblib/example.rb | 5 + doc/mrbgems/ruby_extension_example/test/example.rb | 3 + mrbgems/Makefile | 3 +- mrbgems/g/c_extension_example/Makefile | 12 -- mrbgems/g/c_extension_example/README.md | 4 - mrbgems/g/c_extension_example/src/example.c | 17 --- mrbgems/g/c_extension_example/test/example.rb | 3 - mrbgems/g/ruby_extension_example/Makefile | 7 - mrbgems/g/ruby_extension_example/README.md | 4 - mrbgems/g/ruby_extension_example/mrblib/example.rb | 5 - mrbgems/g/ruby_extension_example/test/example.rb | 3 - mrbgems/generator.c | 158 ++++++++++++++++----- 19 files changed, 235 insertions(+), 90 deletions(-) create mode 100644 doc/mrbgems/README.md create mode 100644 doc/mrbgems/c_extension_example/Makefile create mode 100644 doc/mrbgems/c_extension_example/README.md create mode 100644 doc/mrbgems/c_extension_example/src/example.c create mode 100644 doc/mrbgems/c_extension_example/test/example.rb create mode 100644 doc/mrbgems/ruby_extension_example/Makefile create mode 100644 doc/mrbgems/ruby_extension_example/README.md create mode 100644 doc/mrbgems/ruby_extension_example/mrblib/example.rb create mode 100644 doc/mrbgems/ruby_extension_example/test/example.rb delete mode 100644 mrbgems/g/c_extension_example/Makefile delete mode 100644 mrbgems/g/c_extension_example/README.md delete mode 100644 mrbgems/g/c_extension_example/src/example.c delete mode 100644 mrbgems/g/c_extension_example/test/example.rb delete mode 100644 mrbgems/g/ruby_extension_example/Makefile delete mode 100644 mrbgems/g/ruby_extension_example/README.md delete mode 100644 mrbgems/g/ruby_extension_example/mrblib/example.rb delete mode 100644 mrbgems/g/ruby_extension_example/test/example.rb diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md new file mode 100644 index 000000000..e23ffdcf2 --- /dev/null +++ b/doc/mrbgems/README.md @@ -0,0 +1,54 @@ +# mrbgems + +mrbgems is a library manager to integrate C and Ruby extension in an easy and +standardized way into mruby. + +## GEM Structure + ++- GEM_NAME <- Name of Gem + | + +- mrblib/ <- Source for Ruby extension + | + +- src/ <- Source for C extension + | + +- test/ <- Test code (Ruby) + | + +- Makefile <- Makefile for Gem + | + +- README.md <- Readme for Gem + +## C Extension + +### Example + ++- c_extension_example/ + | + +- src/ + | | + | +- example.c <- C extension source + | + +- test/ + | | + | +- example.rb <- Test code for C extension + | + +- Makefile <- Build rules for C extension + | + +- README.md + +## Ruby Extension + +### Example + ++- ruby_extension_example/ + | + +- mrblib/ + | | + | +- example.rb <- Ruby extension source + | + +- test/ + | | + | +- example.rb <- Test code for Ruby extension + | + +- Makefile + | + +- README.md diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile new file mode 100644 index 000000000..b245e9696 --- /dev/null +++ b/doc/mrbgems/c_extension_example/Makefile @@ -0,0 +1,12 @@ +include ../../Makefile4gem + +GEM := c_extension_example + +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) + +gem-all : $(GEM_OBJECTS) + $(AR) rs $(LIBR) $< + +gem-clean : + -$(RM) $(GEM_OBJECTS) diff --git a/doc/mrbgems/c_extension_example/README.md b/doc/mrbgems/c_extension_example/README.md new file mode 100644 index 000000000..3803c2065 --- /dev/null +++ b/doc/mrbgems/c_extension_example/README.md @@ -0,0 +1,4 @@ +C Extension Example +========= + +This is an example gem which implements a C extension. diff --git a/doc/mrbgems/c_extension_example/src/example.c b/doc/mrbgems/c_extension_example/src/example.c new file mode 100644 index 000000000..9f0b07839 --- /dev/null +++ b/doc/mrbgems/c_extension_example/src/example.c @@ -0,0 +1,17 @@ +#include +#include + +static struct RClass *_class_cextension; + +static mrb_value +mrb_c_method(mrb_state *mrb, mrb_value self) +{ + puts("A C Extension"); + return self; +} + +void +mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} diff --git a/doc/mrbgems/c_extension_example/test/example.rb b/doc/mrbgems/c_extension_example/test/example.rb new file mode 100644 index 000000000..367d18029 --- /dev/null +++ b/doc/mrbgems/c_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('C Extension Example') do + CExtension.respond_to? :c_method +end diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile new file mode 100644 index 000000000..7ebec4f09 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -0,0 +1,7 @@ +include ../../Makefile4gem + +GEM := ruby_extension_example + +gem-all : + +gem-clean : diff --git a/doc/mrbgems/ruby_extension_example/README.md b/doc/mrbgems/ruby_extension_example/README.md new file mode 100644 index 000000000..906a0d8f2 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/README.md @@ -0,0 +1,4 @@ +Pure Ruby Extension Example +========= + +This is an example gem which implements a pure Ruby extension. diff --git a/doc/mrbgems/ruby_extension_example/mrblib/example.rb b/doc/mrbgems/ruby_extension_example/mrblib/example.rb new file mode 100644 index 000000000..b07a2b580 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/mrblib/example.rb @@ -0,0 +1,5 @@ +class RubyExtension + def RubyExtension.ruby_method + puts "A Ruby Extension" + end +end diff --git a/doc/mrbgems/ruby_extension_example/test/example.rb b/doc/mrbgems/ruby_extension_example/test/example.rb new file mode 100644 index 000000000..0c1b63469 --- /dev/null +++ b/doc/mrbgems/ruby_extension_example/test/example.rb @@ -0,0 +1,3 @@ +assert('Ruby Extension Example') do + RubyExtension.respond_to? :ruby_method +end diff --git a/mrbgems/Makefile b/mrbgems/Makefile index ab8b364ac..29d71d586 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -59,7 +59,8 @@ $(GEMDLIB) : # clean driver and all gems .PHONY : clean -clean : $(GEM_MAKEFILE) +clean : $(GENERATOR_BIN) @echo "Cleanup Gems" + $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) $(MAKE) clean -C g -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) diff --git a/mrbgems/g/c_extension_example/Makefile b/mrbgems/g/c_extension_example/Makefile deleted file mode 100644 index b245e9696..000000000 --- a/mrbgems/g/c_extension_example/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -include ../../Makefile4gem - -GEM := c_extension_example - -GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) -GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) - -gem-all : $(GEM_OBJECTS) - $(AR) rs $(LIBR) $< - -gem-clean : - -$(RM) $(GEM_OBJECTS) diff --git a/mrbgems/g/c_extension_example/README.md b/mrbgems/g/c_extension_example/README.md deleted file mode 100644 index 3803c2065..000000000 --- a/mrbgems/g/c_extension_example/README.md +++ /dev/null @@ -1,4 +0,0 @@ -C Extension Example -========= - -This is an example gem which implements a C extension. diff --git a/mrbgems/g/c_extension_example/src/example.c b/mrbgems/g/c_extension_example/src/example.c deleted file mode 100644 index 9f0b07839..000000000 --- a/mrbgems/g/c_extension_example/src/example.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -static struct RClass *_class_cextension; - -static mrb_value -mrb_c_method(mrb_state *mrb, mrb_value self) -{ - puts("A C Extension"); - return self; -} - -void -mrb_c_extension_example_gem_init(mrb_state* mrb) { - _class_cextension = mrb_define_module(mrb, "CExtension"); - mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); -} diff --git a/mrbgems/g/c_extension_example/test/example.rb b/mrbgems/g/c_extension_example/test/example.rb deleted file mode 100644 index 367d18029..000000000 --- a/mrbgems/g/c_extension_example/test/example.rb +++ /dev/null @@ -1,3 +0,0 @@ -assert('C Extension Example') do - CExtension.respond_to? :c_method -end diff --git a/mrbgems/g/ruby_extension_example/Makefile b/mrbgems/g/ruby_extension_example/Makefile deleted file mode 100644 index 7ebec4f09..000000000 --- a/mrbgems/g/ruby_extension_example/Makefile +++ /dev/null @@ -1,7 +0,0 @@ -include ../../Makefile4gem - -GEM := ruby_extension_example - -gem-all : - -gem-clean : diff --git a/mrbgems/g/ruby_extension_example/README.md b/mrbgems/g/ruby_extension_example/README.md deleted file mode 100644 index 906a0d8f2..000000000 --- a/mrbgems/g/ruby_extension_example/README.md +++ /dev/null @@ -1,4 +0,0 @@ -Pure Ruby Extension Example -========= - -This is an example gem which implements a pure Ruby extension. diff --git a/mrbgems/g/ruby_extension_example/mrblib/example.rb b/mrbgems/g/ruby_extension_example/mrblib/example.rb deleted file mode 100644 index b07a2b580..000000000 --- a/mrbgems/g/ruby_extension_example/mrblib/example.rb +++ /dev/null @@ -1,5 +0,0 @@ -class RubyExtension - def RubyExtension.ruby_method - puts "A Ruby Extension" - end -end diff --git a/mrbgems/g/ruby_extension_example/test/example.rb b/mrbgems/g/ruby_extension_example/test/example.rb deleted file mode 100644 index 0c1b63469..000000000 --- a/mrbgems/g/ruby_extension_example/test/example.rb +++ /dev/null @@ -1,3 +0,0 @@ -assert('Ruby Extension Example') do - RubyExtension.respond_to? :ruby_method -end diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 7015f5a4d..f33a43944 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -45,10 +45,10 @@ directory_exists(char path[4096]) { * FALSE => template for all GEMs * */ -void -for_each_gem (char before[1024], char after[1024], - char start[1024], char end[1024], - char dir_to_skip[1024]) +static char +*for_each_gem (char before[1024], char after[1024], + char start[1024], char end[1024], + char dir_to_skip[1024]) { struct dirent **eps; int n; @@ -99,7 +99,7 @@ for_each_gem (char before[1024], char after[1024], } strcat(complete_line, end); - puts(complete_line); + return complete_line; } /* @@ -109,6 +109,11 @@ for_each_gem (char before[1024], char after[1024], void make_gem_makefile() { + char *gem_check = ""; + int gem_empty; + int gem_c_empty; + int gem_ruby_empty; + puts("CFLAGS := -I. -I../../include -I../../src"); puts(""); puts("ifeq ($(OS),Windows_NT)"); @@ -118,29 +123,69 @@ make_gem_makefile() puts("endif"); puts(""); + gem_check = for_each_gem("", "", "", "", ""); + if (strcmp(gem_check, "") == 0) + gem_empty = TRUE; + else + gem_empty = FALSE; + + gem_check = for_each_gem("", "", "", "", "src"); + if (strcmp(gem_check, "") == 0) + gem_c_empty = TRUE; + else + gem_c_empty = FALSE; + + gem_check = for_each_gem("", "", "", "", "mrblib"); + if (strcmp(gem_check, "") == 0) + gem_ruby_empty = TRUE; + else + gem_ruby_empty = FALSE; + puts(".PHONY : all"); - puts("all : all_gems mrblib_gem.o"); - puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); - puts(""); + if (gem_empty) { + puts("all :"); + puts(""); + } + else { + if (gem_c_empty) { + puts("all : mrblib_gem.o"); + puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + } + else if (gem_ruby_empty) { + puts("all : all_gems"); + } + else { + puts("all : all_gems mrblib_gem.o"); + puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + } - puts("all_gems :"); - for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", ""); - puts(""); + puts(""); - puts("mrblib_gem.o : mrblib_gem.c"); - puts(""); + // Rule for building all C extensions of each Gem + if (!gem_c_empty) { + puts("all_gems :"); + puts(for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "")); + puts(""); + } - puts("mrblib_gem.c : mrblib_gem.ctmp"); - puts("\tcat $< > $@"); - puts(""); + // Rule for building all Ruby Extension of each Gem + if (!gem_ruby_empty) { + puts("mrblib_gem.o : mrblib_gem.c"); + puts(""); - puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); - puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); - puts(""); + puts("mrblib_gem.c : mrblib_gem.ctmp"); + puts("\tcat $< > $@"); + puts(""); - puts("mrblib_gem.rbtmp :"); - for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib"); - puts(""); + puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); + puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); + puts(""); + + puts("mrblib_gem.rbtmp :"); + puts(for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib")); + puts(""); + } + } puts(".PHONY : prepare-test"); puts("prepare-test : mrbgemtest.ctmp"); @@ -151,13 +196,20 @@ make_gem_makefile() puts(""); puts("mrbgemtest.rbtmp :"); - for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", ""); + + if (!gem_empty) + puts(for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "")); + else + puts("\t../generator rbtmp > mrbgemtest.rbtmp"); + puts(""); puts(".PHONY : clean"); puts("clean :"); puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); - for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", ""); + + if (!gem_empty) + puts(for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", "")); } /* @@ -167,6 +219,29 @@ make_gem_makefile() void make_init_gems() { + char *gem_check = ""; + int gem_empty; + int gem_c_empty; + int gem_ruby_empty; + + gem_check = for_each_gem("", "", "", "", ""); + if (strcmp(gem_check, "") == 0) + gem_empty = TRUE; + else + gem_empty = FALSE; + + gem_check = for_each_gem("", "", "", "", "src"); + if (strcmp(gem_check, "") == 0) + gem_c_empty = TRUE; + else + gem_c_empty = FALSE; + + gem_check = for_each_gem("", "", "", "", "mrblib"); + if (strcmp(gem_check, "") == 0) + gem_ruby_empty = TRUE; + else + gem_ruby_empty = FALSE; + puts("/*"); puts(" * This file contains a list of all"); puts(" * initializing methods which are"); @@ -185,25 +260,38 @@ make_init_gems() puts("#include \"mruby/proc.h\""); puts(""); - for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src"); + if (!gem_c_empty) + puts(for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src")); + + if (!gem_ruby_empty) + puts("extern const char mrblib_gem_irep[];"); - puts("extern const char mrblib_gem_irep[];"); puts(""); puts("void"); puts("mrb_init_mrbgems(mrb_state *mrb) {"); - for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src"); + if (!gem_c_empty) + puts(for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src")); + + if (!gem_ruby_empty) { + puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); + puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); + puts(" if (mrb->exc) {"); + puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); + puts(" exit(0);"); + puts(" }"); + } - puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); - puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); - puts(" if (mrb->exc) {"); - puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); - puts(" exit(0);"); - puts(" }"); puts("}"); } +void +make_rbtmp() +{ + puts(""); +} + int main (int argc, char *argv[]) { @@ -212,11 +300,13 @@ main (int argc, char *argv[]) make_gem_makefile(); else if (strcmp(argv[1], "init_gems") == 0) make_init_gems(); + else if (strcmp(argv[1], "rbtmp") == 0) + make_rbtmp(); else return 1; } else { - puts("Argument missing! Options: 'makefile', 'init_gems'"); + puts("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp'"); return 1; } -- cgit v1.2.3 From b4c4fce03fb21105874f0e37ec091d8bbcd8c81f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 23 Sep 2012 22:59:37 +0800 Subject: Modify generator for using printf --- mrbgems/generator.c | 172 +++++++++++++++++++++++++++------------------------- 1 file changed, 88 insertions(+), 84 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index f33a43944..ddcc6ab3a 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -5,6 +5,7 @@ #include #include #include +#include static int one (const struct dirent *unused) @@ -45,8 +46,8 @@ directory_exists(char path[4096]) { * FALSE => template for all GEMs * */ -static char -*for_each_gem (char before[1024], char after[1024], +static char* +for_each_gem (char before[1024], char after[1024], char start[1024], char end[1024], char dir_to_skip[1024]) { @@ -54,10 +55,12 @@ static char int n; char gemname[1024] = ""; char gemname_path[4096] = ""; - char complete_line[4096] = ""; char src_path[4096] = ""; struct stat attribut; + // return value + char* complete_line = malloc(4096 + sizeof(char)); + strcat(complete_line, start); n = scandir("./g", &eps, one, alphasort); @@ -114,102 +117,100 @@ make_gem_makefile() int gem_c_empty; int gem_ruby_empty; - puts("CFLAGS := -I. -I../../include -I../../src"); - puts(""); - puts("ifeq ($(OS),Windows_NT)"); - puts("MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'"); - puts("else"); - puts("MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'"); - puts("endif"); - puts(""); + printf("CFLAGS := -I. -I../../include -I../../src\n\n" + "ifeq ($(OS),Windows_NT)\n" + "MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'\n" + "else\n" + "MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'\n" + "endif\n\n"); + /* is there any GEM available? */ gem_check = for_each_gem("", "", "", "", ""); if (strcmp(gem_check, "") == 0) gem_empty = TRUE; else gem_empty = FALSE; + /* is there a C extension available? */ gem_check = for_each_gem("", "", "", "", "src"); if (strcmp(gem_check, "") == 0) gem_c_empty = TRUE; - else + else gem_c_empty = FALSE; + /* is there a Ruby extension available */ gem_check = for_each_gem("", "", "", "", "mrblib"); if (strcmp(gem_check, "") == 0) gem_ruby_empty = TRUE; - else + else gem_ruby_empty = FALSE; - puts(".PHONY : all"); + printf(".PHONY : all\n"); if (gem_empty) { - puts("all :"); - puts(""); + printf("all :\n\n"); } else { if (gem_c_empty) { - puts("all : mrblib_gem.o"); - puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + printf("all : mrblib_gem.o\n" + "\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o\n"); } else if (gem_ruby_empty) { - puts("all : all_gems"); + printf("all : all_gems\n"); } else { - puts("all : all_gems mrblib_gem.o"); - puts("\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o"); + printf("all : all_gems mrblib_gem.o\n" + "\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o\n"); } - puts(""); + printf("\n"); // Rule for building all C extensions of each Gem if (!gem_c_empty) { - puts("all_gems :"); - puts(for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "")); - puts(""); + printf("all_gems :\n%s", + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") + ); } // Rule for building all Ruby Extension of each Gem if (!gem_ruby_empty) { - puts("mrblib_gem.o : mrblib_gem.c"); - puts(""); + printf("mrblib_gem.o : mrblib_gem.c\n\n" - puts("mrblib_gem.c : mrblib_gem.ctmp"); - puts("\tcat $< > $@"); - puts(""); + "mrblib_gem.c : mrblib_gem.ctmp\n" + "\tcat $< > $@\n\n" - puts("mrblib_gem.ctmp : mrblib_gem.rbtmp"); - puts("\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<"); - puts(""); + "mrblib_gem.ctmp : mrblib_gem.rbtmp\n" + "\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<\n\n" - puts("mrblib_gem.rbtmp :"); - puts(for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib")); - puts(""); + "mrblib_gem.rbtmp :\n%s", + for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib") + ); } } - puts(".PHONY : prepare-test"); - puts("prepare-test : mrbgemtest.ctmp"); - puts(""); + printf(".PHONY : prepare-test\n" + "prepare-test : mrbgemtest.ctmp\n\n" - puts("mrbgemtest.ctmp : mrbgemtest.rbtmp"); - puts("\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp"); - puts(""); + "mrbgemtest.ctmp : mrbgemtest.rbtmp\n" + "\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n" - puts("mrbgemtest.rbtmp :"); + "mrbgemtest.rbtmp :\n" + ); if (!gem_empty) - puts(for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "")); + printf("%s", + for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "") + ); else - puts("\t../generator rbtmp > mrbgemtest.rbtmp"); + printf("\t../generator rbtmp > mrbgemtest.rbtmp\n"); - puts(""); - - puts(".PHONY : clean"); - puts("clean :"); - puts("\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest"); + printf("\n.PHONY : clean\n" + "clean :\n" + "\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n"); if (!gem_empty) - puts(for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", "")); + printf("%s", + for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", "") + ); } /* @@ -224,72 +225,75 @@ make_init_gems() int gem_c_empty; int gem_ruby_empty; + /* is there any GEM available? */ gem_check = for_each_gem("", "", "", "", ""); if (strcmp(gem_check, "") == 0) gem_empty = TRUE; else gem_empty = FALSE; + /* is there a C extension available? */ gem_check = for_each_gem("", "", "", "", "src"); if (strcmp(gem_check, "") == 0) gem_c_empty = TRUE; else gem_c_empty = FALSE; + /* is there a Ruby extension available */ gem_check = for_each_gem("", "", "", "", "mrblib"); if (strcmp(gem_check, "") == 0) gem_ruby_empty = TRUE; else gem_ruby_empty = FALSE; - puts("/*"); - puts(" * This file contains a list of all"); - puts(" * initializing methods which are"); - puts(" * necessary to bootstrap all gems."); - puts(" *"); - puts(" * IMPORTANT:"); - puts(" * This file was generated!"); - puts(" * All manual changes will get lost."); - puts(" */"); - - puts(""); - puts("#include \"mruby.h\""); - puts("#include \"mruby/irep.h\""); - puts("#include \"mruby/dump.h\""); - puts("#include \"mruby/string.h\""); - puts("#include \"mruby/proc.h\""); - puts(""); + printf("/*\n" + " * This file contains a list of all\n" + " * initializing methods which are\n" + " * necessary to bootstrap all gems.\n" + " *\n" + " * IMPORTANT:\n" + " * This file was generated!\n" + " * All manual changes will get lost.\n" + " */\n\n" + "#include \"mruby.h\"\n" + "#include \"mruby/irep.h\"\n" + "#include \"mruby/dump.h\"\n" + "#include \"mruby/string.h\"\n" + "#include \"mruby/proc.h\"\n" + ""); if (!gem_c_empty) - puts(for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src")); + printf("%s", + for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src") + ); if (!gem_ruby_empty) - puts("extern const char mrblib_gem_irep[];"); - - puts(""); + printf("extern const char mrblib_gem_irep[];\n"); - puts("void"); - puts("mrb_init_mrbgems(mrb_state *mrb) {"); + printf("\nvoid\n" + "mrb_init_mrbgems(mrb_state *mrb) {"); if (!gem_c_empty) - puts(for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src")); + printf("%s", + for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src") + ); if (!gem_ruby_empty) { - puts(" int n = mrb_read_irep(mrb, mrblib_gem_irep);"); - puts(" mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));"); - puts(" if (mrb->exc) {"); - puts(" mrb_p(mrb, mrb_obj_value(mrb->exc));"); - puts(" exit(0);"); - puts(" }"); + printf(" int n = mrb_read_irep(mrb, mrblib_gem_irep);\n" + " mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));\n" + " if (mrb->exc) {\n" + " mrb_p(mrb, mrb_obj_value(mrb->exc));\n" + " exit(0);\n" + " }"); } - puts("}"); + printf("}"); } void make_rbtmp() { - puts(""); + printf("\n"); } int @@ -306,7 +310,7 @@ main (int argc, char *argv[]) return 1; } else { - puts("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp'"); + printf("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp'"); return 1; } -- cgit v1.2.3 From 97a91d28664f5c493048ce9f53593943e2f91d0d Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 23 Sep 2012 23:21:27 +0800 Subject: Beautify generator --- mrbgems/generator.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index ddcc6ab3a..9a76198a5 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -166,7 +166,7 @@ make_gem_makefile() // Rule for building all C extensions of each Gem if (!gem_c_empty) { - printf("all_gems :\n%s", + printf("all_gems :\n%s\n", for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") ); } @@ -181,13 +181,13 @@ make_gem_makefile() "mrblib_gem.ctmp : mrblib_gem.rbtmp\n" "\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<\n\n" - "mrblib_gem.rbtmp :\n%s", + "mrblib_gem.rbtmp :\n%s\n", for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib") ); } } - printf(".PHONY : prepare-test\n" + printf("\n.PHONY : prepare-test\n" "prepare-test : mrbgemtest.ctmp\n\n" "mrbgemtest.ctmp : mrbgemtest.rbtmp\n" @@ -203,7 +203,7 @@ make_gem_makefile() else printf("\t../generator rbtmp > mrbgemtest.rbtmp\n"); - printf("\n.PHONY : clean\n" + printf("\n\n.PHONY : clean\n" "clean :\n" "\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n"); @@ -259,19 +259,18 @@ make_init_gems() "#include \"mruby/irep.h\"\n" "#include \"mruby/dump.h\"\n" "#include \"mruby/string.h\"\n" - "#include \"mruby/proc.h\"\n" - ""); + "#include \"mruby/proc.h\"\n"); if (!gem_c_empty) - printf("%s", + printf("\n%s", for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src") ); if (!gem_ruby_empty) - printf("extern const char mrblib_gem_irep[];\n"); + printf("\nextern const char mrblib_gem_irep[];\n"); printf("\nvoid\n" - "mrb_init_mrbgems(mrb_state *mrb) {"); + "mrb_init_mrbgems(mrb_state *mrb) {\n"); if (!gem_c_empty) printf("%s", @@ -284,7 +283,7 @@ make_init_gems() " if (mrb->exc) {\n" " mrb_p(mrb, mrb_obj_value(mrb->exc));\n" " exit(0);\n" - " }"); + " }\n"); } printf("}"); -- cgit v1.2.3 From 316edbe7c46ac8adfb72256987c1d0fad9354553 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 23 Sep 2012 23:27:39 +0800 Subject: Empty GEM directory --- mrbgems/g/.gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 mrbgems/g/.gitignore diff --git a/mrbgems/g/.gitignore b/mrbgems/g/.gitignore new file mode 100644 index 000000000..f935021a8 --- /dev/null +++ b/mrbgems/g/.gitignore @@ -0,0 +1 @@ +!.gitignore -- cgit v1.2.3 From cad954aa9f76342bbc700d8bacb1d039f2c13b5f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sun, 23 Sep 2012 23:33:08 +0800 Subject: Ignore gitignore --- mrbgems/generator.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 9a76198a5..430dcb354 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -77,6 +77,8 @@ for_each_gem (char before[1024], char after[1024], continue; if (strcmp(gemname, "..") == 0) continue; + if (strcmp(gemname, ".gitignore") == 0) + continue; stat(gemname_path, &attribut); if (S_ISDIR(attribut.st_mode) == 0) { -- cgit v1.2.3 From 0832e26f20882ad6eb10a27ff32d48f1ed6cac04 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:12:16 +0800 Subject: Fix initializing of generator and beautify generator --- mrbgems/Makefile | 11 ++++------- mrbgems/generator.c | 26 ++++++++++---------------- test/Makefile | 6 ++---- 3 files changed, 16 insertions(+), 27 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 29d71d586..a30f804d7 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -25,13 +25,12 @@ GEMDLIB := g/mrbgemtest.ctmp .PHONY : all all : $(INIT).o all_gems -all_gems : $(GEM_MAKEFILE) +all_gems : $(GENERATOR_BIN) + @echo "Generate Gem Makefile" + $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) @echo "Build all gems" $(MAKE) -C g -$(GEM_MAKEFILE) : $(GENERATOR_BIN) - @echo "Generate Gem Makefile" - $(GENERATOR_BIN) makefile > $@ $(INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" @@ -52,9 +51,7 @@ $(GENERATOR).o : $(GENERATOR).c $(CC) $(CC_FLAGS) -MMD -c $< -o $@ .PHONY : prepare-test -prepare-test : $(GEMDLIB) - -$(GEMDLIB) : +prepare-test : @$(MAKE) prepare-test -C g # clean driver and all gems diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 430dcb354..bc1acdaef 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -53,14 +53,14 @@ for_each_gem (char before[1024], char after[1024], { struct dirent **eps; int n; - char gemname[1024] = ""; - char gemname_path[4096] = ""; - char src_path[4096] = ""; + char gemname[1024] = { 0 }; + char gemname_path[4096] = { 0 }; + char src_path[4096] = { 0 }; struct stat attribut; // return value char* complete_line = malloc(4096 + sizeof(char)); - + strcpy(complete_line, ""); strcat(complete_line, start); n = scandir("./g", &eps, one, alphasort); @@ -114,7 +114,7 @@ for_each_gem (char before[1024], char after[1024], void make_gem_makefile() { - char *gem_check = ""; + char *gem_check = { 0 }; int gem_empty; int gem_c_empty; int gem_ruby_empty; @@ -190,25 +190,19 @@ make_gem_makefile() } printf("\n.PHONY : prepare-test\n" - "prepare-test : mrbgemtest.ctmp\n\n" - - "mrbgemtest.ctmp : mrbgemtest.rbtmp\n" - "\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n" - - "mrbgemtest.rbtmp :\n" + "prepare-test :\n" ); - if (!gem_empty) printf("%s", for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "") ); else - printf("\t../generator rbtmp > mrbgemtest.rbtmp\n"); + printf("\t../generator rbtmp > mrbgemtest.rbtmp"); + printf("\n\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n"); - printf("\n\n.PHONY : clean\n" + printf(".PHONY : clean\n" "clean :\n" "\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n"); - if (!gem_empty) printf("%s", for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", "") @@ -222,7 +216,7 @@ make_gem_makefile() void make_init_gems() { - char *gem_check = ""; + char *gem_check = { 0 }; int gem_empty; int gem_c_empty; int gem_ruby_empty; diff --git a/test/Makefile b/test/Makefile index 04722e2d1..183e03438 100644 --- a/test/Makefile +++ b/test/Makefile @@ -69,7 +69,8 @@ $(OBJS) : %.o : %.c $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ # Compile C source from merged mruby source -$(CLIB) : $(DLIB) $(GEMDLIB) $(INIT) +$(CLIB) : $(DLIB) $(INIT) + @$(MAKE) prepare-test -C $(GEMDIR) $(CAT) $(INIT) $(DLIB) $(GEMDLIB) > $@ $(DLIB) : $(RLIB) $(MRBC) @@ -79,9 +80,6 @@ $(DLIB) : $(RLIB) $(MRBC) $(RLIB) : $(ASSLIB) $(MRBS) $(CAT) $(ASSLIB) $(MRBS) > $@ -$(GEMDLIB) : - @$(MAKE) prepare-test -C $(GEMDIR) - # clean up .PHONY : clean clean : -- cgit v1.2.3 From f699d8e41f20e9ed6519af7cfcd30323c783ecd2 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:14:48 +0800 Subject: Remove gem_empty --- mrbgems/generator.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index bc1acdaef..fbcd82c23 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -217,17 +217,9 @@ void make_init_gems() { char *gem_check = { 0 }; - int gem_empty; int gem_c_empty; int gem_ruby_empty; - /* is there any GEM available? */ - gem_check = for_each_gem("", "", "", "", ""); - if (strcmp(gem_check, "") == 0) - gem_empty = TRUE; - else - gem_empty = FALSE; - /* is there a C extension available? */ gem_check = for_each_gem("", "", "", "", "src"); if (strcmp(gem_check, "") == 0) -- cgit v1.2.3 From a7cb9737df8de92a75eddadca01d5227acd60632 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:47:29 +0800 Subject: Improve Gem Readme file --- doc/mrbgems/README.md | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e23ffdcf2..919568a0c 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -5,6 +5,8 @@ standardized way into mruby. ## GEM Structure +The maximal Gem structure looks like this: + +- GEM_NAME <- Name of Gem | +- mrblib/ <- Source for Ruby extension @@ -17,8 +19,40 @@ standardized way into mruby. | +- README.md <- Readme for Gem +The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* +contains C files to extend mruby. The folder *test* contains pure Ruby files +for testing purposes which will be used by mrbtest. The *Makefile* contains +rules to build all C files and integrates them into the normal mruby +build process. +README.md+ is a short description for the Gem. + ## C Extension +mruby can be extended with C. It is possible by using the C API to integrate C +libraries into mruby. You need to use the folder *src* for all C files. Pay +attention that your *Makefile* has to build the source and also add the object +files to libmruby.a + +### Pre-Conditions + +mrbgems will automatically call the +gem-all+ make target of your Gem. Make +sure that you build all files in this target and that you add you object +files to libmruby.a + +mrbgems expects that you have implemented a C method called +*mrb_YOURGEMNAME_gem_init(mrb_state* mrb)*. YOURGEMNAME will be replaced +by the name of you Gem. The directory name of your Gem is considered also +as the name! If you call your Gem directory *c_extension_example*, your +initialisation method could look like this: + + void + mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); + } + +mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement +this target with the necessary rules! + ### Example +- c_extension_example/ @@ -37,6 +71,16 @@ standardized way into mruby. ## Ruby Extension +mruby can be extended with pure Ruby. It is possible to override existing +classes or add new ones in this way. Put all Ruby files into the *mrblib* +folder. At the moment only one directory layer is supported. So don't +use a deeper structure for now! + +The *Makefile* is not used for building a Ruby extension. But you still +should maintain this file so that during the build process the progress +can be visualized. If you want to do additional things during the build +process of your Ruby extension you can use the *Makefile* too. + ### Example +- ruby_extension_example/ -- cgit v1.2.3 From 96afe4bad92fe7820c8716763dc942ac53939c18 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 00:49:31 +0800 Subject: Improve Gem Readme Source --- doc/mrbgems/README.md | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 919568a0c..f46c392ce 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -7,6 +7,7 @@ standardized way into mruby. The maximal Gem structure looks like this: +``` +- GEM_NAME <- Name of Gem | +- mrblib/ <- Source for Ruby extension @@ -18,6 +19,7 @@ The maximal Gem structure looks like this: +- Makefile <- Makefile for Gem | +- README.md <- Readme for Gem +``` The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files @@ -44,17 +46,20 @@ by the name of you Gem. The directory name of your Gem is considered also as the name! If you call your Gem directory *c_extension_example*, your initialisation method could look like this: - void - mrb_c_extension_example_gem_init(mrb_state* mrb) { - _class_cextension = mrb_define_module(mrb, "CExtension"); - mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); - } +``` +void +mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} +``` mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement this target with the necessary rules! ### Example +``` +- c_extension_example/ | +- src/ @@ -68,6 +73,7 @@ this target with the necessary rules! +- Makefile <- Build rules for C extension | +- README.md +``` ## Ruby Extension @@ -83,6 +89,7 @@ process of your Ruby extension you can use the *Makefile* too. ### Example +``` +- ruby_extension_example/ | +- mrblib/ @@ -96,3 +103,4 @@ process of your Ruby extension you can use the *Makefile* too. +- Makefile | +- README.md +``` -- cgit v1.2.3 From ad37ddd823eb7edf3c7908f93fd40167d0562c1c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:00:11 +0800 Subject: Improve documentation for Gem and add limitations --- doc/mrbgems/README.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index f46c392ce..d17547b3d 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -25,7 +25,7 @@ The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files for testing purposes which will be used by mrbtest. The *Makefile* contains rules to build all C files and integrates them into the normal mruby -build process. +README.md+ is a short description for the Gem. +build process. *README.md* is a short description of your Gem. ## C Extension @@ -36,12 +36,12 @@ files to libmruby.a ### Pre-Conditions -mrbgems will automatically call the +gem-all+ make target of your Gem. Make -sure that you build all files in this target and that you add you object +mrbgems will automatically call the *gem-all* make target of your Gem. Make +sure that you build all files in this target and that you add your object files to libmruby.a mrbgems expects that you have implemented a C method called -*mrb_YOURGEMNAME_gem_init(mrb_state* mrb)*. YOURGEMNAME will be replaced +*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced by the name of you Gem. The directory name of your Gem is considered also as the name! If you call your Gem directory *c_extension_example*, your initialisation method could look like this: @@ -104,3 +104,16 @@ process of your Ruby extension you can use the *Makefile* too. | +- README.md ``` + +## Current Limitations + +The following limitations are currently existing: + +* Gem _MUST NOT_ have a *src* folder in case it doesn't have a + C extension +* Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a + Ruby extension +* Only Ruby files in the root directory of *mrblib* will be integrated + +If you have ideas how to fix these issues without implementing to much +complexity into the code please provide your code or idea. -- cgit v1.2.3 From d4631f29a2de3da19382dd6331706574cc5ceaa0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:16:50 +0800 Subject: Spell fix in mrbgems Readme --- doc/mrbgems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index d17547b3d..3082c0df0 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -1,7 +1,7 @@ # mrbgems mrbgems is a library manager to integrate C and Ruby extension in an easy and -standardized way into mruby. +standardised way into mruby. ## GEM Structure -- cgit v1.2.3 From 78a053a1ea5927caa62e3d815a8e6eeb27669935 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:18:10 +0800 Subject: Add location of gem to readme --- doc/mrbgems/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 3082c0df0..ad4b5d5e6 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -27,6 +27,8 @@ for testing purposes which will be used by mrbtest. The *Makefile* contains rules to build all C files and integrates them into the normal mruby build process. *README.md* is a short description of your Gem. +All Gems have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. + ## C Extension mruby can be extended with C. It is possible by using the C API to integrate C -- cgit v1.2.3 From 81bff9aac28d324ab0f1108a57267d54f006f3c7 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:30:48 +0800 Subject: Add a limitation for object files with C Extension --- doc/mrbgems/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index ad4b5d5e6..7eef38222 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -116,6 +116,8 @@ The following limitations are currently existing: * Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a Ruby extension * Only Ruby files in the root directory of *mrblib* will be integrated +* C files in the directory of *src* are overriding object files with + the same name. If you have ideas how to fix these issues without implementing to much complexity into the code please provide your code or idea. -- cgit v1.2.3 From 6e589f57239d5ba04b41a7e23e59e9c30bcb243b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:41:34 +0800 Subject: Fix for not existing tests --- mrbgems/generator.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index fbcd82c23..5f292783f 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -194,7 +194,7 @@ make_gem_makefile() ); if (!gem_empty) printf("%s", - for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "") + for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "test") ); else printf("\t../generator rbtmp > mrbgemtest.rbtmp"); -- cgit v1.2.3 From 4d12ff4978a87f7687a607a3db8afb89d4e90d70 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:50:20 +0800 Subject: Add accidently removed comment --- mrblib/Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/mrblib/Makefile b/mrblib/Makefile index 942b3e1d2..6d7ac65f9 100644 --- a/mrblib/Makefile +++ b/mrblib/Makefile @@ -52,6 +52,7 @@ endif .PHONY : all all : $(LIBR) +# update libmruby.a $(LIBR) : $(MLIB) $(LIBR0) $(CP) $(LIBR0) $(LIBR) $(AR) r $(LIBR) $(MLIB) -- cgit v1.2.3 From 993b37c1b0aa030a18c5162fbd8f5e21501b1138 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 01:55:12 +0800 Subject: used comments to contributer style --- mrbgems/generator.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 5f292783f..aff0fb69e 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -58,7 +58,7 @@ for_each_gem (char before[1024], char after[1024], char src_path[4096] = { 0 }; struct stat attribut; - // return value + /* return value */ char* complete_line = malloc(4096 + sizeof(char)); strcpy(complete_line, ""); strcat(complete_line, start); @@ -166,14 +166,14 @@ make_gem_makefile() printf("\n"); - // Rule for building all C extensions of each Gem + /* Rule for building all C extensions of each Gem */ if (!gem_c_empty) { printf("all_gems :\n%s\n", for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") ); } - // Rule for building all Ruby Extension of each Gem + /* Rule for building all Ruby Extension of each Gem */ if (!gem_ruby_empty) { printf("mrblib_gem.o : mrblib_gem.c\n\n" -- cgit v1.2.3 From 5b2572362966bc8c82ca32c83871bd9c27ce1a2e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 24 Sep 2012 02:02:02 +0800 Subject: Ignore built files of gem --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 02ffb598a..7e6e49b76 100644 --- a/.gitignore +++ b/.gitignore @@ -24,6 +24,9 @@ cscope.out /test/*.*tmp CMakeFiles CMakeCache.txt -/mrbgems/gem_helper +/mrbgems/generator /mrbgems/init_gems.c /mrbgems/g/Makefile +/mrbgems/g/mrblib_gem.c +/mrbgems/g/mrblib_gem.ctmp +/mrbgems/g/mrblib_gem.rbtmp -- cgit v1.2.3 From fcaeec554a9aac77463f1460b469ea5f34a6f2a0 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 8 Nov 2012 17:36:39 +0900 Subject: Fix merge --- test/Makefile | 8 -------- 1 file changed, 8 deletions(-) diff --git a/test/Makefile b/test/Makefile index b06343084..a4d8b7c0b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -51,13 +51,6 @@ endif # mruby compiler and test driver ifeq ($(OS),Windows_NT) -<<<<<<< HEAD - MRBC = ../bin/mrbc.exe - EXE := $(TARGET).exe -else - MRBC = ../bin/mrbc - EXE := $(TARGET) -======= MRBC = ../bin/mrbc.exe MRUBY= ../bin/mruby.exe EXE := $(TARGET).exe @@ -65,7 +58,6 @@ else MRBC = ../bin/mrbc MRUBY= ../bin/mruby EXE := $(TARGET) ->>>>>>> upstream/master endif ############################## -- cgit v1.2.3 From 389ceafbf697f2df2feceb9ba4fb80c37b39ed47 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Tue, 20 Nov 2012 17:31:27 +0800 Subject: Modify comments for generator --- mrbgems/generator.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index aff0fb69e..54cecd128 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -41,9 +41,8 @@ directory_exists(char path[4096]) { * String at the start of the template * end: * String at the end of the template - * skip_if_src_not_exist: - * TRUE => skip template for GEMs with SRC directory - * FALSE => template for all GEMs + * dir_to_skip: + * Name of a directory which will be skipped * */ static char* @@ -166,12 +165,10 @@ make_gem_makefile() printf("\n"); - /* Rule for building all C extensions of each Gem */ - if (!gem_c_empty) { - printf("all_gems :\n%s\n", - for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") - ); - } + /* Rule to make every GEM */ + printf("all_gems :\n%s\n", + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") + ); /* Rule for building all Ruby Extension of each Gem */ if (!gem_ruby_empty) { -- cgit v1.2.3 From 83fdc3d78e59e1c87ba8ba75445b65ff2f146ae3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:54:54 +0800 Subject: Add C and Ruby Extension Example Mixed --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 12 ++++++++++++ doc/mrbgems/c_and_ruby_extension_example/README.md | 4 ++++ .../c_and_ruby_extension_example/mrblib/example.rb | 5 +++++ doc/mrbgems/c_and_ruby_extension_example/src/example.c | 17 +++++++++++++++++ .../c_and_ruby_extension_example/test/example.rb | 7 +++++++ 5 files changed, 45 insertions(+) create mode 100644 doc/mrbgems/c_and_ruby_extension_example/Makefile create mode 100644 doc/mrbgems/c_and_ruby_extension_example/README.md create mode 100644 doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb create mode 100644 doc/mrbgems/c_and_ruby_extension_example/src/example.c create mode 100644 doc/mrbgems/c_and_ruby_extension_example/test/example.rb diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile new file mode 100644 index 000000000..1744d73c3 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -0,0 +1,12 @@ +include ../../Makefile4gem + +GEM := c_and_ruby_extension_example + +GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) +GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) + +GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) + +gem-all : $(GEM_OBJECTS) gem-c-and-rb-files + +gem-clean : gem-clean-c-and-rb-files diff --git a/doc/mrbgems/c_and_ruby_extension_example/README.md b/doc/mrbgems/c_and_ruby_extension_example/README.md new file mode 100644 index 000000000..0b428b0b6 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/README.md @@ -0,0 +1,4 @@ +C and Ruby Extension Example +========= + +This is an example gem which implements a C and Ruby extension. diff --git a/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb b/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb new file mode 100644 index 000000000..0c2d3c7d1 --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/mrblib/example.rb @@ -0,0 +1,5 @@ +class RubyExtension + def CRubyExtension.ruby_method + puts "A Ruby Extension" + end +end diff --git a/doc/mrbgems/c_and_ruby_extension_example/src/example.c b/doc/mrbgems/c_and_ruby_extension_example/src/example.c new file mode 100644 index 000000000..178514ffe --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/src/example.c @@ -0,0 +1,17 @@ +#include +#include + +static struct RClass *_class_cextension; + +static mrb_value +mrb_c_method(mrb_state *mrb, mrb_value self) +{ + puts("A C Extension"); + return self; +} + +void +mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CRubyExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} diff --git a/doc/mrbgems/c_and_ruby_extension_example/test/example.rb b/doc/mrbgems/c_and_ruby_extension_example/test/example.rb new file mode 100644 index 000000000..fffad710f --- /dev/null +++ b/doc/mrbgems/c_and_ruby_extension_example/test/example.rb @@ -0,0 +1,7 @@ +assert('C and Ruby Extension Example 1') do + CRubyExtension.respond_to? :c_method +end + +assert('C and Ruby Extension Example 2') do + CRubyExtension.respond_to? :ruby_method +end -- cgit v1.2.3 From bc26a482d880a1c89bd685d4745f71009686d544 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:55:15 +0800 Subject: Modify C Extension --- doc/mrbgems/c_extension_example/Makefile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index b245e9696..615557aca 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -5,8 +5,6 @@ GEM := c_extension_example GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -gem-all : $(GEM_OBJECTS) - $(AR) rs $(LIBR) $< +gem-all : $(GEM_OBJECTS) gem-c-files -gem-clean : - -$(RM) $(GEM_OBJECTS) +gem-clean : gem-clean-c-files -- cgit v1.2.3 From f591d116b0f2c0952aa63aaf28df1f2574b0e7a3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:55:29 +0800 Subject: Modify Ruby Extension --- doc/mrbgems/ruby_extension_example/Makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 7ebec4f09..33eee97e9 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -2,6 +2,8 @@ include ../../Makefile4gem GEM := ruby_extension_example -gem-all : +GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) -gem-clean : +gem-all : gem-rb-files + +gem-clean : gem-clean-rb-files -- cgit v1.2.3 From f97e3facd2e64ecfdf75be5cb579c47ffade3562 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:56:09 +0800 Subject: Improve building of Gems to single Archive Files --- mrbgems/Makefile | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index a30f804d7..462540c09 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -17,21 +17,26 @@ else GENERATOR_BIN := $(GENERATOR) endif GEM_MAKEFILE := g/Makefile +GEM_MAKEFILE_LIST := g/MakefileGemList GEMDLIB := g/mrbgemtest.ctmp ############################## # generic build targets, rules .PHONY : all -all : $(INIT).o all_gems +all : all_gems gem_init.a + +gem_init.a : $(INIT).o + $(AR) rs gem_init.a $(INIT).o all_gems : $(GENERATOR_BIN) + @echo "Generate Gem List Makefile" + $(GENERATOR_BIN) makefile_list > $(GEM_MAKEFILE_LIST) @echo "Generate Gem Makefile" $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) @echo "Build all gems" $(MAKE) -C g - $(INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" $(GENERATOR_BIN) $(INIT) > $@ @@ -39,7 +44,6 @@ $(INIT).c : $(GENERATOR_BIN) $(INIT).o : $(INIT).c @echo "Build the driver which initializes all gems" $(CC) $(CC_FLAGS) -MMD -c $< -o $@ - $(AR) rs $(LIBR) $@ # Generator @@ -60,4 +64,4 @@ clean : $(GENERATOR_BIN) @echo "Cleanup Gems" $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) $(MAKE) clean -C g - -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) + -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) $(GEM_MAKEFILE_LIST) gem_init.a -- cgit v1.2.3 From f30eedd7e80f39f0cf28a3c70bd00448e10a9ef8 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:56:30 +0800 Subject: Improve Including File to build single archive Files --- mrbgems/Makefile4gem | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/mrbgems/Makefile4gem b/mrbgems/Makefile4gem index a4fa3f3c9..1b6376f9a 100644 --- a/mrbgems/Makefile4gem +++ b/mrbgems/Makefile4gem @@ -11,6 +11,7 @@ RM := rm -f 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 @@ -27,11 +28,55 @@ endif .PHONY : all all : gem-info gem-all - @echo "Gem '$(GEM)' is done" gem-info: @echo "Building Gem '$(GEM)'" +# Building target for C and Ruby files +gem-c-and-rb-files : gem_mixlib.o + $(AR) rs gem.a $(GEM_OBJECTS) $^ + +gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp + cat $^ > $@ + +gem_mixlib_init.ctmp : + ../../generator gem_mixlib $(GEM) > $@ + +# Building target for C files +gem-c-files : gem_srclib.o + $(AR) rs gem.a $(GEM_OBJECTS) $< + +gem_srclib.c : + ../../generator gem_srclib $(GEM) > $@ + +# Building target for Ruby Files +gem-rb-files : gem_mrblib.o + $(AR) rs gem.a $< + +gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp + cat $^ > $@ + +gem_mrblib_header.ctmp : + ../../generator gem_mrblib > $@ + +gem_mrblib_init.ctmp : + ../../generator gem_mrblib $(GEM) > $@ + +gem_mrblib_irep.ctmp : gem_mrblib.rbtmp + ../../../bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< + +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 + +gem-clean-c-files : + -$(RM) gem.a 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 + .PHONY : clean clean : gem-clean @echo "Gem '$(GEM)' is clean" -- cgit v1.2.3 From a9df6f85e67bb5af1e76447248fe95aedd2ec83e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:56:59 +0800 Subject: Improve Generator by handling Ruby and C Extensions in the same way --- mrbgems/generator.c | 211 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 121 insertions(+), 90 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 54cecd128..1d5cdd367 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -115,8 +115,6 @@ make_gem_makefile() { char *gem_check = { 0 }; int gem_empty; - int gem_c_empty; - int gem_ruby_empty; printf("CFLAGS := -I. -I../../include -I../../src\n\n" "ifeq ($(OS),Windows_NT)\n" @@ -132,36 +130,11 @@ make_gem_makefile() else gem_empty = FALSE; - /* is there a C extension available? */ - gem_check = for_each_gem("", "", "", "", "src"); - if (strcmp(gem_check, "") == 0) - gem_c_empty = TRUE; - else - gem_c_empty = FALSE; - - /* is there a Ruby extension available */ - gem_check = for_each_gem("", "", "", "", "mrblib"); - if (strcmp(gem_check, "") == 0) - gem_ruby_empty = TRUE; - else - gem_ruby_empty = FALSE; - printf(".PHONY : all\n"); - if (gem_empty) { + if (gem_empty) printf("all :\n\n"); - } else { - if (gem_c_empty) { - printf("all : mrblib_gem.o\n" - "\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o\n"); - } - else if (gem_ruby_empty) { - printf("all : all_gems\n"); - } - else { - printf("all : all_gems mrblib_gem.o\n" - "\t$(AR) rs ../../lib/libmruby.a mrblib_gem.o\n"); - } + printf("all : all_gems\n"); printf("\n"); @@ -169,21 +142,6 @@ make_gem_makefile() printf("all_gems :\n%s\n", for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") ); - - /* Rule for building all Ruby Extension of each Gem */ - if (!gem_ruby_empty) { - printf("mrblib_gem.o : mrblib_gem.c\n\n" - - "mrblib_gem.c : mrblib_gem.ctmp\n" - "\tcat $< > $@\n\n" - - "mrblib_gem.ctmp : mrblib_gem.rbtmp\n" - "\t../../bin/mrbc -Bmrblib_gem_irep -o$@ $<\n\n" - - "mrblib_gem.rbtmp :\n%s\n", - for_each_gem(" ", "/mrblib/*.rb", "\tcat", "> mrblib_gem.rbtmp", "mrblib") - ); - } } printf("\n.PHONY : prepare-test\n" @@ -207,30 +165,28 @@ make_gem_makefile() } /* - * init_gems.c Generator + * Gem Makefile List Generator * */ void -make_init_gems() +make_gem_makefile_list() { - char *gem_check = { 0 }; - int gem_c_empty; - int gem_ruby_empty; - - /* is there a C extension available? */ - gem_check = for_each_gem("", "", "", "", "src"); - if (strcmp(gem_check, "") == 0) - gem_c_empty = TRUE; - else - gem_c_empty = FALSE; + printf("%s", + for_each_gem(" ", "", "GEM_LIST := ", "\n", "") + ); - /* is there a Ruby extension available */ - gem_check = for_each_gem("", "", "", "", "mrblib"); - if (strcmp(gem_check, "") == 0) - gem_ruby_empty = TRUE; - else - gem_ruby_empty = FALSE; + printf("GEM_ARCHIVE_FILES := $(addprefix $(MRUBY_ROOT)/mrbgems/g/, $(GEM_LIST))\n" + "GEM_ARCHIVE_FILES := $(addsuffix /gem.a, $(GEM_ARCHIVE_FILES))\n" + "GEM_ARCHIVE_FILES += $(MRUBY_ROOT)/mrbgems/gem_init.a\n\n"); +} +/* + * init_gems.c Generator + * + */ +void +make_init_gems() +{ printf("/*\n" " * This file contains a list of all\n" " * initializing methods which are\n" @@ -240,44 +196,101 @@ make_init_gems() " * This file was generated!\n" " * All manual changes will get lost.\n" " */\n\n" + "#include \"mruby.h\"\n"); + + /* Protoype definition of all initialization methods */ + printf("\n%s", + for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", "") + ); + + /* mrb_init_mrbgems(mrb) method for initialization of all GEMs */ + printf("\nvoid\n" + "mrb_init_mrbgems(mrb_state *mrb) {\n"); + printf( "%s", + for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", "") + ); + printf("}"); +} + +void +make_rbtmp() +{ + printf("\n"); +} + +void +make_gem_mrblib_header() +{ + printf("/*\n" + " * This file is loading the irep\n" + " * Ruby GEM code.\n" + " *\n" + " * IMPORTANT:\n" + " * This file was generated!\n" + " * All manual changes will get lost.\n" + " */\n\n" "#include \"mruby.h\"\n" "#include \"mruby/irep.h\"\n" "#include \"mruby/dump.h\"\n" "#include \"mruby/string.h\"\n" - "#include \"mruby/proc.h\"\n"); - - if (!gem_c_empty) - printf("\n%s", - for_each_gem("void mrb_", "_gem_init(mrb_state*);\n", "", "", "src") - ); - - if (!gem_ruby_empty) - printf("\nextern const char mrblib_gem_irep[];\n"); + "#include \"mruby/proc.h\"\n\n"); +} - printf("\nvoid\n" - "mrb_init_mrbgems(mrb_state *mrb) {\n"); +void +make_gem_mrblib(char argv[1024]) +{ + printf("\n" + "void\n" + "GENERATED_TMP_mrb_%s_gem_init(mrb_state *mrb) {\n" + " int n = mrb_read_irep(mrb, gem_mrblib_irep_%s);\n" + " mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));\n" + " if (mrb->exc) {\n" + " mrb_p(mrb, mrb_obj_value(mrb->exc));\n" + " exit(0);\n" + " }\n" + "}", argv, argv); +} - if (!gem_c_empty) - printf("%s", - for_each_gem(" mrb_", "_gem_init(mrb);\n", "", "", "src") - ); +void +make_gem_srclib(char argv[1024]) +{ + printf("/*\n" + " * This file is loading the irep\n" + " * Ruby GEM code.\n" + " *\n" + " * IMPORTANT:\n" + " * This file was generated!\n" + " * All manual changes will get lost.\n" + " */\n\n" + "#include \"mruby.h\"\n"); - if (!gem_ruby_empty) { - printf(" int n = mrb_read_irep(mrb, mrblib_gem_irep);\n" - " mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));\n" - " if (mrb->exc) {\n" - " mrb_p(mrb, mrb_obj_value(mrb->exc));\n" - " exit(0);\n" - " }\n"); - } + printf("\n" + "void mrb_%s_gem_init(mrb_state*);\n", argv); - printf("}"); + printf("\n" + "void\n" + "GENERATED_TMP_mrb_%s_gem_init(mrb_state *mrb) {\n" + " mrb_%s_gem_init(mrb);\n" + "}", argv, argv); } void -make_rbtmp() +make_gem_mixlib(char argv[1024]) { - printf("\n"); + printf("\n" + "void mrb_%s_gem_init(mrb_state*);\n", argv); + + printf("\n" + "void\n" + "GENERATED_TMP_mrb_%s_gem_init(mrb_state *mrb) {\n" + " mrb_%s_gem_init(mrb);\n" + " int n = mrb_read_irep(mrb, gem_mrblib_irep_%s);\n" + " mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb));\n" + " if (mrb->exc) {\n" + " mrb_p(mrb, mrb_obj_value(mrb->exc));\n" + " exit(0);\n" + " }\n" + "}", argv, argv, argv); } int @@ -286,15 +299,33 @@ main (int argc, char *argv[]) if (argc == 2) { if (strcmp(argv[1], "makefile") == 0) make_gem_makefile(); + else if (strcmp(argv[1], "makefile_list") == 0) + make_gem_makefile_list(); else if (strcmp(argv[1], "init_gems") == 0) make_init_gems(); else if (strcmp(argv[1], "rbtmp") == 0) make_rbtmp(); - else + else if (strcmp(argv[1], "gem_mrblib") == 0) + make_gem_mrblib_header(); + else { + printf("Wrong argument! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib', gem_srclib\n"); return 1; + } + } + else if (argc == 3) { + if (strcmp(argv[1], "gem_mrblib") == 0) + make_gem_mrblib(argv[2]); + else if (strcmp(argv[1], "gem_srclib") == 0) + make_gem_srclib(argv[2]); + else if (strcmp(argv[1], "gem_mixlib") == 0) + make_gem_mixlib(argv[2]); + else { + printf("Wrong argument! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib', gem_srclib\n"); + return 1; + } } else { - printf("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp'"); + printf("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib, gem_srclib'\n"); return 1; } -- cgit v1.2.3 From a9513c1d1dd89bd23f3220e3dab37e52a6ed0ae1 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:57:24 +0800 Subject: Include dynamically GEMs into mrbtest --- test/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/Makefile b/test/Makefile index a4d8b7c0b..1cadd90a2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -3,9 +3,18 @@ # project-specific macros # extension of the executable-file is modifiable(.exe .out ...) +MRUBY_ROOT := .. BASEDIR = . TARGET := mrbtest LIBR := ../lib/libmruby.a + +MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList +ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = +else + include $(MAKEFILE_GEM_LIST) +endif + MLIB := $(TARGET).o CLIB := $(TARGET).c INIT := init_$(TARGET).c @@ -77,7 +86,7 @@ all : $(EXE) $(MRUBY) $(TESTRB) $(TESTMRB) # executable constructed using linker from object files $(EXE) : $(OBJS) $(LIBR) - $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(LIBS) + $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(GEM_ARCHIVE_FILES) $(LIBS) -include $(OBJS:.o=.d) -- cgit v1.2.3 From 1e4d20a766a3483fb9be1518253864d5082dbf9d Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:57:41 +0800 Subject: Include dynamically GEMs into mirb --- tools/mirb/Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile index 8dbbc52b3..2729c4829 100644 --- a/tools/mirb/Makefile +++ b/tools/mirb/Makefile @@ -3,9 +3,18 @@ # project-specific macros # extension of the executable-file is modifiable(.exe .out ...) +MRUBY_ROOT := ../.. BASEDIR = ../../src TARGET := ../../bin/mirb LIBR := ../../lib/libmruby.a + +MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList +ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = +else + include $(MAKEFILE_GEM_LIST) +endif + ifeq ($(OS),Windows_NT) EXE := $(TARGET).exe else @@ -49,7 +58,7 @@ all : $(LIBR) $(EXE) # executable constructed using linker from object files $(EXE) : $(LIBR) $(OBJS) $(EXTS) - $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(EXTS) $(LIBS) + $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(GEM_ARCHIVE_FILES) $(EXTS) $(LIBS) -include $(OBJS:.o=.d) -- cgit v1.2.3 From ed92a86212c2428e64d385b2b89f1dcfcec265e6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 21 Nov 2012 15:57:49 +0800 Subject: Include dynamically GEMs into mruby --- tools/mruby/Makefile | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile index e94c1b2b4..53383a70b 100644 --- a/tools/mruby/Makefile +++ b/tools/mruby/Makefile @@ -3,9 +3,18 @@ # project-specific macros # extension of the executable-file is modifiable(.exe .out ...) -BASEDIR = ../../src -TARGET := ../../bin/mruby -LIBR := ../../lib/libmruby.a +MRUBY_ROOT := ../.. +BASEDIR = $(MRUBY_ROOT)/src +TARGET := $(MRUBY_ROOT)/bin/mruby +LIBR := $(MRUBY_ROOT)/lib/libmruby.a + +MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList +ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = +else + include $(MAKEFILE_GEM_LIST) +endif + ifeq ($(OS),Windows_NT) EXE := $(TARGET).exe else @@ -54,7 +63,7 @@ all : $(LIBR) $(EXE) # executable constructed using linker from object files $(EXE) : $(LIBR) $(OBJS) $(EXTS) - $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(EXTS) $(LIBS) + $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(GEM_ARCHIVE_FILES) $(EXTS) $(LIBS) -include $(OBJS:.o=.d) -- cgit v1.2.3 From 953cbff65c322eac30b6a766eac2676e9eb67ac6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 16:13:16 +0800 Subject: Make GEM build choosable. Respect GEMS.active file for choices of which GEM to build --- mrbgems/GEMS.active | 0 mrbgems/generator.c | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 mrbgems/GEMS.active diff --git a/mrbgems/GEMS.active b/mrbgems/GEMS.active new file mode 100644 index 000000000..e69de29bb diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 1d5cdd367..f5cd2b76a 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -50,6 +50,17 @@ for_each_gem (char before[1024], char after[1024], char start[1024], char end[1024], char dir_to_skip[1024]) { + FILE *fp; + char *active_gems = NULL; + char ch; + char gem_name[1024] = { 0 }; + int char_index; + char gem_list[1024][1024] = { { 0 }, { 0 } }; + int gem_index; + int i; + int b; + int cnt; + struct dirent **eps; int n; char gemname[1024] = { 0 }; @@ -57,6 +68,27 @@ for_each_gem (char before[1024], char after[1024], char src_path[4096] = { 0 }; struct stat attribut; + fp = fopen("GEMS.active", "r+"); + if (fp != NULL) { + char_index = 0; + gem_index = 0; + while((ch = fgetc(fp)) != EOF) { + if (ch == '\n') { + gem_name[char_index++] = '\0'; + strcpy(gem_list[gem_index++], gem_name); + + gem_name[0] = '\0'; + char_index = 0; + } + else { + gem_name[char_index++] = ch; + } + } + + fclose(fp); + } + else { /* Error: Active GEM list couldn't be loaded */ } + /* return value */ char* complete_line = malloc(4096 + sizeof(char)); strcpy(complete_line, ""); @@ -64,13 +96,10 @@ for_each_gem (char before[1024], char after[1024], n = scandir("./g", &eps, one, alphasort); if (n >= 0) { - int cnt; for (cnt = 0; cnt < n; ++cnt) { strcpy(gemname, eps[cnt]->d_name); strcpy(gemname_path, "./g/"); strcat(gemname_path, gemname); - strcpy(src_path, gemname_path); - strcat(src_path, "/src"); if (strcmp(gemname, ".") == 0) continue; @@ -84,6 +113,21 @@ for_each_gem (char before[1024], char after[1024], continue; } + b = 0; + for(i = 0; i <= gem_index; i++) { + if (strcmp(gem_list[i], gemname) != 0) + b = 0; + else { + /* Current GEM is active */ + b = 1; + break; + } + } + + /* In case the current GEM isn't active we skip it */ + if (b == 0) + continue; + if (strcmp(dir_to_skip, "") != 0) { strcpy(src_path, gemname_path); strcat(src_path, "/"); -- cgit v1.2.3 From 8c86ee93e34fa524d1992b326587339719288736 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 16:51:33 +0800 Subject: Adapt new GEM compile process to ignore list --- .gitignore | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 4bb5041e7..420533b61 100644 --- a/.gitignore +++ b/.gitignore @@ -26,8 +26,8 @@ cscope.out CMakeFiles CMakeCache.txt /mrbgems/generator -/mrbgems/init_gems.c +/mrbgems/gem_init.c /mrbgems/g/Makefile -/mrbgems/g/mrblib_gem.c -/mrbgems/g/mrblib_gem.ctmp -/mrbgems/g/mrblib_gem.rbtmp +/mrbgems/g/MakefileGemList +/mrbgems/g/mrbgemtest.ctmp +/mrbgems/g/mrbgemtest.rbtmp -- cgit v1.2.3 From d1efcb4c8585837426eadf6f04f6cae38f22d35b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 16:52:07 +0800 Subject: Rename GEM init file --- mrbgems/Makefile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 462540c09..a0381d042 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -2,7 +2,6 @@ # add gems to the ruby library LIBR := ../lib/libmruby.a -INIT := init_gems RM_F := rm -f CC_FLAGS := -Wall -Werror-implicit-function-declaration -g -O3 -MMD -I. -I./../include @@ -16,6 +15,7 @@ ifeq ($(OS),Windows_NT) else GENERATOR_BIN := $(GENERATOR) endif +GEM_INIT := gem_init GEM_MAKEFILE := g/Makefile GEM_MAKEFILE_LIST := g/MakefileGemList GEMDLIB := g/mrbgemtest.ctmp @@ -24,10 +24,10 @@ GEMDLIB := g/mrbgemtest.ctmp # generic build targets, rules .PHONY : all -all : all_gems gem_init.a +all : all_gems $(GEM_INIT).a -gem_init.a : $(INIT).o - $(AR) rs gem_init.a $(INIT).o +$(GEM_INIT).a : $(GEM_INIT).o + $(AR) rs gem_init.a $(GEM_INIT).o all_gems : $(GENERATOR_BIN) @echo "Generate Gem List Makefile" @@ -37,11 +37,11 @@ all_gems : $(GENERATOR_BIN) @echo "Build all gems" $(MAKE) -C g -$(INIT).c : $(GENERATOR_BIN) +$(GEM_INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" - $(GENERATOR_BIN) $(INIT) > $@ + $(GENERATOR_BIN) $(GEM_INIT) > $@ -$(INIT).o : $(INIT).c +$(GEM_INIT).o : $(GEM_INIT).c @echo "Build the driver which initializes all gems" $(CC) $(CC_FLAGS) -MMD -c $< -o $@ @@ -64,4 +64,4 @@ clean : $(GENERATOR_BIN) @echo "Cleanup Gems" $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) $(MAKE) clean -C g - -$(RM_F) $(INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) $(GEM_MAKEFILE_LIST) gem_init.a + -$(RM_F) $(GEM_INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) $(GEM_MAKEFILE_LIST) gem_init.a -- cgit v1.2.3 From 74121d624f80bb876c1918f8680d0714fd5df946 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 17:40:53 +0800 Subject: Clean GEM Generator a bit more --- mrbgems/generator.c | 139 ++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 102 insertions(+), 37 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index f5cd2b76a..a00079098 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -30,7 +30,7 @@ directory_exists(char path[4096]) { } /* - * Template generator for each GEM + * Template generator for each active GEM * * Arguments: * before: @@ -50,17 +50,18 @@ for_each_gem (char before[1024], char after[1024], char start[1024], char end[1024], char dir_to_skip[1024]) { - FILE *fp; - char *active_gems = NULL; - char ch; + /* active GEM check */ + FILE *active_gem_file; + char gem_char; char gem_name[1024] = { 0 }; int char_index; char gem_list[1024][1024] = { { 0 }, { 0 } }; int gem_index; int i; - int b; + int gem_active; int cnt; + /* folder check */ struct dirent **eps; int n; char gemname[1024] = { 0 }; @@ -68,39 +69,47 @@ for_each_gem (char before[1024], char after[1024], char src_path[4096] = { 0 }; struct stat attribut; - fp = fopen("GEMS.active", "r+"); - if (fp != NULL) { + /* return value */ + char* complete_line = malloc(4096 + sizeof(char)); + strcpy(complete_line, ""); + strcat(complete_line, start); + + /* Read out the active GEMs */ + active_gem_file = fopen("GEMS.active", "r+"); + if (active_gem_file != NULL) { char_index = 0; gem_index = 0; - while((ch = fgetc(fp)) != EOF) { - if (ch == '\n') { + while((gem_char = fgetc(active_gem_file)) != EOF) { + if (gem_char == '\n') { + /* Every line contains one active GEM */ gem_name[char_index++] = '\0'; strcpy(gem_list[gem_index++], gem_name); gem_name[0] = '\0'; char_index = 0; } - else { - gem_name[char_index++] = ch; - } + else + gem_name[char_index++] = gem_char; + } + if (gem_index > 0) { + /* clean close of the last GEM name */ + gem_name[char_index++] = '\0'; + strcpy(gem_list[gem_index++], gem_name); } - fclose(fp); + fclose(active_gem_file); } else { /* Error: Active GEM list couldn't be loaded */ } - /* return value */ - char* complete_line = malloc(4096 + sizeof(char)); - strcpy(complete_line, ""); - strcat(complete_line, start); - n = scandir("./g", &eps, one, alphasort); if (n >= 0) { + /* iterate over each file and figure out what is a GEM and what not */ for (cnt = 0; cnt < n; ++cnt) { strcpy(gemname, eps[cnt]->d_name); strcpy(gemname_path, "./g/"); strcat(gemname_path, gemname); + /* we ignore all the default files */ if (strcmp(gemname, ".") == 0) continue; if (strcmp(gemname, "..") == 0) @@ -108,26 +117,30 @@ for_each_gem (char before[1024], char after[1024], if (strcmp(gemname, ".gitignore") == 0) continue; + /* In case the current location isn't a folder we skip it */ stat(gemname_path, &attribut); if (S_ISDIR(attribut.st_mode) == 0) { continue; } - b = 0; + /* Check if user has activated this GEM */ + gem_active = 0; for(i = 0; i <= gem_index; i++) { if (strcmp(gem_list[i], gemname) != 0) - b = 0; + gem_active = FALSE; else { /* Current GEM is active */ - b = 1; + gem_active = TRUE; break; } } - /* In case the current GEM isn't active we skip it */ - if (b == 0) + if (gem_active == FALSE) continue; + /* sometimes we are only interested in GEMs + with a specific folder. + */ if (strcmp(dir_to_skip, "") != 0) { strcpy(src_path, gemname_path); strcat(src_path, "/"); @@ -153,6 +166,9 @@ for_each_gem (char before[1024], char after[1024], /* * Gem Makefile Generator * + * Global Makefile which starts the build process + * for every active GEM. + * */ void make_gem_makefile() @@ -174,21 +190,24 @@ make_gem_makefile() else gem_empty = FALSE; + /* Makefile Rules to build every single GEM */ + printf(".PHONY : all\n"); if (gem_empty) printf("all :\n\n"); else { - printf("all : all_gems\n"); + printf("all : all_gems\n\n"); - printf("\n"); - - /* Rule to make every GEM */ + /* Call make for every GEM */ printf("all_gems :\n%s\n", for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") ); + printf("\n"); } - printf("\n.PHONY : prepare-test\n" + /* Makefile Rules to Test GEMs */ + + printf(".PHONY : prepare-test\n" "prepare-test :\n" ); if (!gem_empty) @@ -197,8 +216,11 @@ make_gem_makefile() ); else printf("\t../generator rbtmp > mrbgemtest.rbtmp"); + printf("\n\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n"); - + + /* Makefile Rules to Clean GEMs */ + printf(".PHONY : clean\n" "clean :\n" "\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n"); @@ -211,6 +233,9 @@ make_gem_makefile() /* * Gem Makefile List Generator * + * Creates a Makefile which will be included by other Makefiles + * which need to know which GEMs are active. + * */ void make_gem_makefile_list() @@ -225,11 +250,11 @@ make_gem_makefile_list() } /* - * init_gems.c Generator + * gem_init.c Generator * */ void -make_init_gems() +make_gem_init() { printf("/*\n" " * This file contains a list of all\n" @@ -246,9 +271,10 @@ make_init_gems() printf("\n%s", for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", "") ); + printf("\n"); /* mrb_init_mrbgems(mrb) method for initialization of all GEMs */ - printf("\nvoid\n" + printf("void\n" "mrb_init_mrbgems(mrb_state *mrb) {\n"); printf( "%s", for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", "") @@ -256,12 +282,24 @@ make_init_gems() printf("}"); } +/* + * Empty Generator + * + * Generates a clean file. + * + */ void make_rbtmp() { printf("\n"); } +/* + * Header Generator + * + * Head of the C Code for loading the GEMs into the interpreter. + * + */ void make_gem_mrblib_header() { @@ -280,6 +318,13 @@ make_gem_mrblib_header() "#include \"mruby/proc.h\"\n\n"); } +/* + * mrblib Generator + * + * Generates the C Code for loading + * the pure Ruby GEMs into the interpreter. + * + */ void make_gem_mrblib(char argv[1024]) { @@ -295,6 +340,13 @@ make_gem_mrblib(char argv[1024]) "}", argv, argv); } +/* + * srclib Generator + * + * Generates the C Code for loading + * the pure C GEMs into the interpreter. + * + */ void make_gem_srclib(char argv[1024]) { @@ -318,6 +370,14 @@ make_gem_srclib(char argv[1024]) "}", argv, argv); } +/* + * mixlib Generator + * + * Generates the C Code for loading + * the mixed Ruby and C GEMs + * into the interpreter. + * + */ void make_gem_mixlib(char argv[1024]) { @@ -337,22 +397,27 @@ make_gem_mixlib(char argv[1024]) "}", argv, argv, argv); } +/* + * Start the generator and decide what to generate. + * + */ int main (int argc, char *argv[]) { + const char * argument_info = "Wrong argument! Options: 'makefile', 'gem_init', 'rbtmp', 'gem_mrblib', gem_srclib\n"; if (argc == 2) { if (strcmp(argv[1], "makefile") == 0) make_gem_makefile(); else if (strcmp(argv[1], "makefile_list") == 0) make_gem_makefile_list(); - else if (strcmp(argv[1], "init_gems") == 0) - make_init_gems(); + else if (strcmp(argv[1], "gem_init") == 0) + make_gem_init(); else if (strcmp(argv[1], "rbtmp") == 0) make_rbtmp(); else if (strcmp(argv[1], "gem_mrblib") == 0) make_gem_mrblib_header(); else { - printf("Wrong argument! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib', gem_srclib\n"); + printf("%s", argument_info); return 1; } } @@ -364,12 +429,12 @@ main (int argc, char *argv[]) else if (strcmp(argv[1], "gem_mixlib") == 0) make_gem_mixlib(argv[2]); else { - printf("Wrong argument! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib', gem_srclib\n"); + printf("%s", argument_info); return 1; } } else { - printf("Argument missing! Options: 'makefile', 'init_gems', 'rbtmp', 'gem_mrblib, gem_srclib'\n"); + printf("%s", argument_info); return 1; } -- cgit v1.2.3 From dbde619bc51f93706e3c944e1d9f88210b4d8a06 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 18:59:59 +0800 Subject: Deactivate / Activate GEMs Flag introduced into Makefile --- Makefile | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d18222c3c..07006a0bf 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,11 @@ export LL = gcc export AR = ar export YACC = bison +ifeq ($(strip $(ENABLE_GEMS)),) + # by default GEMs are deactivated + ENABLE_GEMS = false +endif + ifeq ($(strip $(COMPILE_MODE)),) # default compile option COMPILE_MODE = debug @@ -22,9 +27,9 @@ endif ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) - MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' + MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' else - MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' + MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' endif ############################## @@ -44,8 +49,11 @@ export CAT := cat all : @$(MAKE) -C src $(MAKE_FLAGS) @$(MAKE) -C mrblib $(MAKE_FLAGS) +ifeq ($(ENABLE_GEMS),true) + @echo "-- MAKE mrbgems --" @$(MAKE) -C mrbgems $(MAKE_FLAGS) - @$(MAKE) -C tools/mruby $(MAKE_FLAGS) +endif + $(MAKE) -C tools/mruby $(MAKE_FLAGS) @$(MAKE) -C tools/mirb $(MAKE_FLAGS) # mruby test @@ -57,7 +65,10 @@ test : all .PHONY : clean clean : @$(MAKE) clean -C src $(MAKE_FLAGS) +ifeq ($(ENABLE_GEMS),true) + @echo "-- CLEAN mrbgems --" @$(MAKE) clean -C mrbgems $(MAKE_FLAGS) +endif @$(MAKE) clean -C tools/mruby $(MAKE_FLAGS) @$(MAKE) clean -C tools/mirb $(MAKE_FLAGS) @$(MAKE) clean -C test $(MAKE_FLAGS) -- cgit v1.2.3 From 6ebc1918dee7d2f7d647cc65f3e97009990cbd9e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:00:11 +0800 Subject: Deactivate / Activate GEMs Flag introduced into mrbconf.h --- include/mrbconf.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/mrbconf.h b/include/mrbconf.h index 20c9a59a8..42ff4b80c 100644 --- a/include/mrbconf.h +++ b/include/mrbconf.h @@ -50,6 +50,7 @@ //#define DISABLE_TIME /* Time class */ //#define DISABLE_STRUCT /* Struct class */ //#define DISABLE_STDIO /* use of stdio */ +#define DISABLE_GEMS /* Package Manager mrbgems */ #undef HAVE_UNISTD_H /* WINDOWS */ #define HAVE_UNISTD_H /* LINUX */ -- cgit v1.2.3 From 35edbb06883b0c943ec1b1f7d4662b90b26375b6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:00:24 +0800 Subject: Deactivate / Activate GEMs Flag introduced into src/init.c --- src/init.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/init.c b/src/init.c index 1a7e72686..98b68006d 100644 --- a/src/init.c +++ b/src/init.c @@ -67,7 +67,9 @@ mrb_init_core(mrb_state *mrb) #endif mrb_init_mrblib(mrb); +#ifdef ENABLE_GEMS mrb_init_mrbgems(mrb); +#endif mrb_gc_arena_restore(mrb, 0); } -- cgit v1.2.3 From 2a2e20680966c674786011450eb59abb595147fd Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:00:39 +0800 Subject: Deactivate / Activate GEMs Flag introduced into mrbtest --- test/Makefile | 21 ++++++++++++++++----- test/init_mrbtest.c | 4 ++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/test/Makefile b/test/Makefile index 1cadd90a2..dfbcd8ce2 100644 --- a/test/Makefile +++ b/test/Makefile @@ -8,19 +8,28 @@ BASEDIR = . TARGET := mrbtest LIBR := ../lib/libmruby.a -MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList -ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) +ifeq ($(strip $(ENABLE_GEMS)),) + # by default GEMs are deactivated + ENABLE_GEMS = false +endif + +ifeq ($(ENABLE_GEMS),false) GEM_ARCHIVE_FILES = else - include $(MAKEFILE_GEM_LIST) + GEMDIR := ../mrbgems + GEMDLIB := $(GEMDIR)/g/mrbgemtest.ctmp + MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList + ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = + else + include $(MAKEFILE_GEM_LIST) + endif endif MLIB := $(TARGET).o CLIB := $(TARGET).c INIT := init_$(TARGET).c DLIB := $(TARGET).ctmp -GEMDIR := ../mrbgems -GEMDLIB := $(GEMDIR)/g/mrbgemtest.ctmp RLIB := $(TARGET).rbtmp DEPLIB := $(TARGET).d driver.d ASSLIB := $(BASEDIR)/assert.rb @@ -96,7 +105,9 @@ $(OBJS) : %.o : %.c # Compile C source from merged mruby source $(CLIB) : $(DLIB) $(INIT) +ifeq ($(ENABLE_GEMS),true) @$(MAKE) prepare-test -C $(GEMDIR) +endif $(CAT) $(INIT) $(DLIB) $(GEMDLIB) > $@ $(DLIB) : $(RLIB) $(MRBC) diff --git a/test/init_mrbtest.c b/test/init_mrbtest.c index 2bc2f2e4b..ce9dd4cdd 100644 --- a/test/init_mrbtest.c +++ b/test/init_mrbtest.c @@ -11,10 +11,14 @@ void mrb_init_mrbtest(mrb_state *mrb) { int n = mrb_read_irep(mrb, mrbtest_irep); +#ifdef ENABLE_GEMS int m = mrb_read_irep(mrb, mrbgemtest_irep); +#endif mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[n]), mrb_top_self(mrb)); +#ifdef ENABLE_GEMS mrb_run(mrb, mrb_proc_new(mrb, mrb->irep[m]), mrb_top_self(mrb)); +#endif if (mrb->exc) { mrb_p(mrb, mrb_obj_value(mrb->exc)); exit(0); -- cgit v1.2.3 From a26e5c05c76c2ebba298c2cee8df44541784f801 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:00:52 +0800 Subject: Deactivate / Activate GEMs Flag introduced into mirb --- tools/mirb/Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/mirb/Makefile b/tools/mirb/Makefile index 2729c4829..c44af4c6b 100644 --- a/tools/mirb/Makefile +++ b/tools/mirb/Makefile @@ -8,11 +8,20 @@ BASEDIR = ../../src TARGET := ../../bin/mirb LIBR := ../../lib/libmruby.a -MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList -ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) +ifeq ($(strip $(ENABLE_GEMS)),) + # by default GEMs are deactivated + ENABLE_GEMS = false +endif + +ifeq ($(ENABLE_GEMS),false) GEM_ARCHIVE_FILES = else - include $(MAKEFILE_GEM_LIST) + MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList + ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = + else + include $(MAKEFILE_GEM_LIST) + endif endif ifeq ($(OS),Windows_NT) -- cgit v1.2.3 From 4f55a3e0b477509a9bd3b44f9eccc4613d29fc1b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:01:02 +0800 Subject: Deactivate / Activate GEMs Flag introduced into mruby --- tools/mruby/Makefile | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile index 53383a70b..b31ed4941 100644 --- a/tools/mruby/Makefile +++ b/tools/mruby/Makefile @@ -8,11 +8,20 @@ BASEDIR = $(MRUBY_ROOT)/src TARGET := $(MRUBY_ROOT)/bin/mruby LIBR := $(MRUBY_ROOT)/lib/libmruby.a -MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList -ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) +ifeq ($(strip $(ENABLE_GEMS)),) + # by default GEMs are deactivated + ENABLE_GEMS = false +endif + +ifeq ($(ENABLE_GEMS),false) GEM_ARCHIVE_FILES = else - include $(MAKEFILE_GEM_LIST) + MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList + ifeq ($(wildcard $(MAKEFILE_GEM_LIST)),) + GEM_ARCHIVE_FILES = + else + include $(MAKEFILE_GEM_LIST) + endif endif ifeq ($(OS),Windows_NT) -- cgit v1.2.3 From 4e2161c7eefa05bdabab18cbfcd018f815b5a2b6 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 19:18:01 +0800 Subject: Deactivate / Activate GEMs Flag introduced into mrbc --- tools/mrbc/mrbc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tools/mrbc/mrbc.c b/tools/mrbc/mrbc.c index 6d9c85fa9..5a92cd479 100644 --- a/tools/mrbc/mrbc.c +++ b/tools/mrbc/mrbc.c @@ -226,7 +226,9 @@ mrb_init_mrblib(mrb_state *mrb) { } +#ifdef ENABLE_GEMS void mrb_init_mrbgems(mrb_state *mrb) { } +#endif -- cgit v1.2.3 From 1c8bc4d9a1b27e4beadb02709185a49053d050ed Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:22:26 +0800 Subject: Improve README --- doc/mrbgems/README.md | 114 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 79 insertions(+), 35 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 7eef38222..e799448f4 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -5,10 +5,10 @@ standardised way into mruby. ## GEM Structure -The maximal Gem structure looks like this: +The maximal GEM structure looks like this: ``` -+- GEM_NAME <- Name of Gem ++- GEM_NAME <- Name of GEM | +- mrblib/ <- Source for Ruby extension | @@ -16,36 +16,39 @@ The maximal Gem structure looks like this: | +- test/ <- Test code (Ruby) | - +- Makefile <- Makefile for Gem + +- Makefile <- Makefile for GEM | - +- README.md <- Readme for Gem + +- README.md <- Readme for GEM ``` The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files for testing purposes which will be used by mrbtest. The *Makefile* contains -rules to build all C files and integrates them into the normal mruby -build process. *README.md* is a short description of your Gem. +rules to build a *gem.a* file inside of the GEM directory. Which will be used +for integration into the normal mruby build process. *README.md* is a short +description of your GEM. -All Gems have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. +All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## C Extension -mruby can be extended with C. It is possible by using the C API to integrate C -libraries into mruby. You need to use the folder *src* for all C files. Pay -attention that your *Makefile* has to build the source and also add the object -files to libmruby.a +mruby can be extended with C. It is possible by using the C API to +integrate C libraries into mruby. + +The *Makefile* is used for building a C extension. You should +define *GEM* (GEM name), *GEM_C_FILES* (all C files) and +*GEM_OBJECTS* (all Object files). Pay also attention that your +*Makefile* has to build the object files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your Gem. Make -sure that you build all files in this target and that you add your object -files to libmruby.a +mrbgems will automatically call the *gem-all* make target of your GEM. Make +sure that you build all files in this target. mrbgems expects that you have implemented a C method called *mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced -by the name of you Gem. The directory name of your Gem is considered also -as the name! If you call your Gem directory *c_extension_example*, your +by the name of you GEM. The directory name of your GEM is considered also +as the name! If you call your GEM directory *c_extension_example*, your initialisation method could look like this: ``` @@ -56,7 +59,7 @@ mrb_c_extension_example_gem_init(mrb_state* mrb) { } ``` -mrbgems will also use the *gem-clean* make target to clean up your Gem. Implement +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement this target with the necessary rules! ### Example @@ -80,14 +83,17 @@ this target with the necessary rules! ## Ruby Extension mruby can be extended with pure Ruby. It is possible to override existing -classes or add new ones in this way. Put all Ruby files into the *mrblib* -folder. At the moment only one directory layer is supported. So don't -use a deeper structure for now! +or add new ones in this way. Put all Ruby files into the *mrblib* folder. + +The *Makefile* is used for building a Ruby extension. You should define +define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). + +### Pre-Conditions + +mrbgems will automatically call the *gem-all* make target of your GEM. -The *Makefile* is not used for building a Ruby extension. But you still -should maintain this file so that during the build process the progress -can be visualized. If you want to do additional things during the build -process of your Ruby extension you can use the *Makefile* too. +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement +this target with the necessary rules! ### Example @@ -107,17 +113,55 @@ process of your Ruby extension you can use the *Makefile* too. +- README.md ``` -## Current Limitations +## C and Ruby Extension -The following limitations are currently existing: +mruby can be extended with C and Ruby at the same time. It is possible to +override existing classes or add new ones in this way. Put all Ruby files +into the *mrblib* folder and all C files into the *srclib* folder. -* Gem _MUST NOT_ have a *src* folder in case it doesn't have a - C extension -* Gem _MUST NOT_ have a *mrblib* folder in case it doesn't have a - Ruby extension -* Only Ruby files in the root directory of *mrblib* will be integrated -* C files in the directory of *src* are overriding object files with - the same name. +The *Makefile* is used for building a C and Ruby extension. You should +define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* +(all Object files) and *GEM_RB_FILES* (all Ruby files). + +### Pre-Conditions + +mrbgems will automatically call the *gem-all* make target of your GEM. Make +sure that you build all files in this target. + +mrbgems expects that you have implemented a C method called +*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced +by the name of you GEM. The directory name of your GEM is considered also +as the name! If you call your GEM directory *c_extension_example*, your +initialisation method could look like this: + +``` +void +mrb_c_extension_example_gem_init(mrb_state* mrb) { + _class_cextension = mrb_define_module(mrb, "CExtension"); + mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); +} +``` -If you have ideas how to fix these issues without implementing to much -complexity into the code please provide your code or idea. +mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement +this target with the necessary rules! + +### Example + +``` ++- c_and_ruby_extension_example/ + | + +- mrblib/ + | | + | +- example.rb <- Ruby extension source + | + +- src/ + | | + | +- example.c <- C extension source + | + +- test/ + | | + | +- example.rb <- Test code for C and Ruby extension + | + +- Makefile + | + +- README.md -- cgit v1.2.3 From 151521b325c375f84a0c4c19dbf73bae2dd4df7f Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:37:16 +0800 Subject: Fix some build documentation for mrbgems --- doc/mrbgems/README.md | 53 +++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e799448f4..480e034a5 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -30,6 +30,19 @@ description of your GEM. All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. +## Build process + +mrbgems will call *make* to build and *make clean* to clean your GEM. You +have to create *gem.a* file during the build process. How you are going +to do this is you decision. + +To make your build process more easier and more standardized we suggest +to include *mrbgems/Makefile4gem* which defines some helper rules. In +case you include this Makefile you have to define specific pre-defined +rules like *gem-all* for the build process and *gem-clean* for the clean +process. There are additional helper rules for specific GEM examples +below. + ## C Extension mruby can be extended with C. It is possible by using the C API to @@ -38,13 +51,12 @@ integrate C libraries into mruby. The *Makefile* is used for building a C extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files) and *GEM_OBJECTS* (all Object files). Pay also attention that your -*Makefile* has to build the object files. +*Makefile* has to build the object files. You can use +*gem-c-files* to build a *gem.a* out of your Object code and use +*gem-clean-c-files* to clean the object files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your GEM. Make -sure that you build all files in this target. - mrbgems expects that you have implemented a C method called *mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced by the name of you GEM. The directory name of your GEM is considered also @@ -83,10 +95,13 @@ this target with the necessary rules! ## Ruby Extension mruby can be extended with pure Ruby. It is possible to override existing -or add new ones in this way. Put all Ruby files into the *mrblib* folder. +classes or add new ones in this way. Put all Ruby files into the *mrblib* +folder. The *Makefile* is used for building a Ruby extension. You should define -define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). +define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use +*gem-rb-files* to build a *gem.a* out of your Ruby code and use +*gem-clean-rb-files* to clean the generated C files. ### Pre-Conditions @@ -117,33 +132,17 @@ this target with the necessary rules! mruby can be extended with C and Ruby at the same time. It is possible to override existing classes or add new ones in this way. Put all Ruby files -into the *mrblib* folder and all C files into the *srclib* folder. +into the *mrblib* folder and all C files into the *src* folder. The *Makefile* is used for building a C and Ruby extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* -(all Object files) and *GEM_RB_FILES* (all Ruby files). +(all Object files) and *GEM_RB_FILES* (all Ruby files). You can use +*gem-c-and-rb-files* to build a *gem.a* out of your Object and Ruby code +and use *gem-clean-c-and-rb-files* to clean the generated C files. ### Pre-Conditions -mrbgems will automatically call the *gem-all* make target of your GEM. Make -sure that you build all files in this target. - -mrbgems expects that you have implemented a C method called -*mrb_YOURGEMNAME_gem_init(mrb_state)*. YOURGEMNAME will be replaced -by the name of you GEM. The directory name of your GEM is considered also -as the name! If you call your GEM directory *c_extension_example*, your -initialisation method could look like this: - -``` -void -mrb_c_extension_example_gem_init(mrb_state* mrb) { - _class_cextension = mrb_define_module(mrb, "CExtension"); - mrb_define_class_method(mrb, _class_cextension, "c_method", mrb_c_method, ARGS_NONE()); -} -``` - -mrbgems will also use the *gem-clean* make target to clean up your GEM. Implement -this target with the necessary rules! +See C and Ruby example. ### Example -- cgit v1.2.3 From a76647ead7d8af214de46a2eb4185b979964c88b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Thu, 22 Nov 2012 20:44:34 +0800 Subject: Clean build documentation for mrbgems a bit more --- doc/mrbgems/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index 480e034a5..e1de425f1 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -33,8 +33,8 @@ All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -have to create *gem.a* file during the build process. How you are going -to do this is you decision. +have to build a *gem.a* file during this build process. How you are going +to do this is up to you. To make your build process more easier and more standardized we suggest to include *mrbgems/Makefile4gem* which defines some helper rules. In @@ -99,7 +99,7 @@ classes or add new ones in this way. Put all Ruby files into the *mrblib* folder. The *Makefile* is used for building a Ruby extension. You should define -define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use +*GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use *gem-rb-files* to build a *gem.a* out of your Ruby code and use *gem-clean-rb-files* to clean the generated C files. -- cgit v1.2.3 From e162f6d20be33280305d6a58208c1ecf919f05c5 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:07:20 +0800 Subject: Modify GEM build process to support external GEMs outside of the mruby tree --- mrbgems/Makefile4gem | 16 ++++--- mrbgems/generator.c | 119 ++++++++------------------------------------------- 2 files changed, 28 insertions(+), 107 deletions(-) diff --git a/mrbgems/Makefile4gem b/mrbgems/Makefile4gem index 1b6376f9a..358716fdf 100644 --- a/mrbgems/Makefile4gem +++ b/mrbgems/Makefile4gem @@ -2,8 +2,10 @@ # by each Gem. It integrates important constants # for usage inside of a Gem. -# mruby src root -MRUBY_ROOT := ../../../ +ifeq ($(strip $(MRUBY_ROOT)),) + # mruby src root + MRUBY_ROOT := ../../../ +endif # Tools CC := gcc @@ -40,14 +42,14 @@ gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp cat $^ > $@ gem_mixlib_init.ctmp : - ../../generator gem_mixlib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mixlib $(GEM) > $@ # Building target for C files gem-c-files : gem_srclib.o $(AR) rs gem.a $(GEM_OBJECTS) $< gem_srclib.c : - ../../generator gem_srclib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_srclib $(GEM) > $@ # Building target for Ruby Files gem-rb-files : gem_mrblib.o @@ -57,13 +59,13 @@ gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp cat $^ > $@ gem_mrblib_header.ctmp : - ../../generator gem_mrblib > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mrblib > $@ gem_mrblib_init.ctmp : - ../../generator gem_mrblib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mrblib $(GEM) > $@ gem_mrblib_irep.ctmp : gem_mrblib.rbtmp - ../../../bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< + $(MRUBY_ROOT)bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< gem_mrblib.rbtmp : cat $(GEM_RB_FILES) > $@ diff --git a/mrbgems/generator.c b/mrbgems/generator.c index a00079098..12bc2a63a 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -7,26 +7,10 @@ #include #include -static int -one (const struct dirent *unused) +char *get_file_name(char *path) { - return 1; -} - -/* - * Does a directory exist? - * yes => TRUE - * no => FALSE - * fs error => FALSE - * - */ -static int -directory_exists(char path[4096]) { - DIR* dir = opendir(path); - if (dir) - return TRUE; - else - return FALSE; + char *base = strrchr(path, '/'); + return base ? base+1 : path; } /* @@ -48,7 +32,7 @@ directory_exists(char path[4096]) { static char* for_each_gem (char before[1024], char after[1024], char start[1024], char end[1024], - char dir_to_skip[1024]) + int full_path) { /* active GEM check */ FILE *active_gem_file; @@ -58,16 +42,6 @@ for_each_gem (char before[1024], char after[1024], char gem_list[1024][1024] = { { 0 }, { 0 } }; int gem_index; int i; - int gem_active; - int cnt; - - /* folder check */ - struct dirent **eps; - int n; - char gemname[1024] = { 0 }; - char gemname_path[4096] = { 0 }; - char src_path[4096] = { 0 }; - struct stat attribut; /* return value */ char* complete_line = malloc(4096 + sizeof(char)); @@ -91,72 +65,18 @@ for_each_gem (char before[1024], char after[1024], else gem_name[char_index++] = gem_char; } - if (gem_index > 0) { - /* clean close of the last GEM name */ - gem_name[char_index++] = '\0'; - strcpy(gem_list[gem_index++], gem_name); - } fclose(active_gem_file); } else { /* Error: Active GEM list couldn't be loaded */ } - n = scandir("./g", &eps, one, alphasort); - if (n >= 0) { - /* iterate over each file and figure out what is a GEM and what not */ - for (cnt = 0; cnt < n; ++cnt) { - strcpy(gemname, eps[cnt]->d_name); - strcpy(gemname_path, "./g/"); - strcat(gemname_path, gemname); - - /* we ignore all the default files */ - if (strcmp(gemname, ".") == 0) - continue; - if (strcmp(gemname, "..") == 0) - continue; - if (strcmp(gemname, ".gitignore") == 0) - continue; - - /* In case the current location isn't a folder we skip it */ - stat(gemname_path, &attribut); - if (S_ISDIR(attribut.st_mode) == 0) { - continue; - } - - /* Check if user has activated this GEM */ - gem_active = 0; - for(i = 0; i <= gem_index; i++) { - if (strcmp(gem_list[i], gemname) != 0) - gem_active = FALSE; - else { - /* Current GEM is active */ - gem_active = TRUE; - break; - } - } - /* In case the current GEM isn't active we skip it */ - if (gem_active == FALSE) - continue; - - /* sometimes we are only interested in GEMs - with a specific folder. - */ - if (strcmp(dir_to_skip, "") != 0) { - strcpy(src_path, gemname_path); - strcat(src_path, "/"); - strcat(src_path, dir_to_skip); - - if (directory_exists(src_path) != TRUE) - continue; - } - - strcat(complete_line, before); - strcat(complete_line, gemname); - strcat(complete_line, after); - } - } - else { - perror("Error while scanning the directory."); + for(i = 0; i < gem_index; i++) { + strcat(complete_line, before); + if (full_path == TRUE) + strcat(complete_line, gem_list[i]); + else + strcat(complete_line, get_file_name(gem_list[i])); + strcat(complete_line, after); } strcat(complete_line, end); @@ -184,7 +104,7 @@ make_gem_makefile() "endif\n\n"); /* is there any GEM available? */ - gem_check = for_each_gem("", "", "", "", ""); + gem_check = for_each_gem("", "", "", "", TRUE); if (strcmp(gem_check, "") == 0) gem_empty = TRUE; else @@ -200,7 +120,7 @@ make_gem_makefile() /* Call make for every GEM */ printf("all_gems :\n%s\n", - for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", "") + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", TRUE) ); printf("\n"); } @@ -212,7 +132,7 @@ make_gem_makefile() ); if (!gem_empty) printf("%s", - for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", "test") + for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE) ); else printf("\t../generator rbtmp > mrbgemtest.rbtmp"); @@ -226,7 +146,7 @@ make_gem_makefile() "\t$(RM) *.c *.d *.rbtmp *.ctmp *.o mrbtest\n"); if (!gem_empty) printf("%s", - for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", "") + for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", TRUE) ); } @@ -241,11 +161,10 @@ void make_gem_makefile_list() { printf("%s", - for_each_gem(" ", "", "GEM_LIST := ", "\n", "") + for_each_gem(" ", "", "GEM_LIST := ", "\n", TRUE) ); - printf("GEM_ARCHIVE_FILES := $(addprefix $(MRUBY_ROOT)/mrbgems/g/, $(GEM_LIST))\n" - "GEM_ARCHIVE_FILES := $(addsuffix /gem.a, $(GEM_ARCHIVE_FILES))\n" + printf("GEM_ARCHIVE_FILES := $(addsuffix /gem.a, $(GEM_LIST))\n" "GEM_ARCHIVE_FILES += $(MRUBY_ROOT)/mrbgems/gem_init.a\n\n"); } @@ -269,7 +188,7 @@ make_gem_init() /* Protoype definition of all initialization methods */ printf("\n%s", - for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", "") + for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", FALSE) ); printf("\n"); @@ -277,7 +196,7 @@ make_gem_init() printf("void\n" "mrb_init_mrbgems(mrb_state *mrb) {\n"); printf( "%s", - for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", "") + for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", FALSE) ); printf("}"); } -- cgit v1.2.3 From e8b99155329fd8e6ade4de675904e5f9fc8a2c75 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:54:49 +0800 Subject: Change build process to create meaningful Archive file instead of gem.a --- mrbgems/Makefile4gem | 14 ++++++++------ mrbgems/generator.c | 43 ++++++++++++++++++++++++++++++++++++++----- 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"); } -- cgit v1.2.3 From 7e7b89a6fab07e92eb42d2a5768f7c714135ba5e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:18 +0800 Subject: Adapt c and ruby example to meaningful archive name --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile index 1744d73c3..0f562584e 100644 --- a/doc/mrbgems/c_and_ruby_extension_example/Makefile +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := c_and_ruby_extension_example +include ../../Makefile4gem + GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -- cgit v1.2.3 From 71bb91d72af3280e1d7f2c22f53d42486666a533 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:35 +0800 Subject: Adapt c example to meaningful archive name --- doc/mrbgems/c_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index 615557aca..4f78a0222 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := c_extension_example +include ../../Makefile4gem + GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) -- cgit v1.2.3 From 8a5d40785c597dd7ba20b38313df5fbee20a0e86 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 02:55:52 +0800 Subject: Adapt Ruby example to meaningful archive name --- doc/mrbgems/ruby_extension_example/Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 33eee97e9..50c99829e 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -1,7 +1,7 @@ -include ../../Makefile4gem - GEM := ruby_extension_example +include ../../Makefile4gem + GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) gem-all : gem-rb-files -- cgit v1.2.3 From c73fa1e1da8571f785f35f6bbac41920f6059c3e Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:19:47 +0800 Subject: Add ACTIVE_GEMS flag to Makefile --- Makefile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 07006a0bf..f2617b11b 100644 --- a/Makefile +++ b/Makefile @@ -12,6 +12,11 @@ ifeq ($(strip $(ENABLE_GEMS)),) ENABLE_GEMS = false endif +ifeq ($(strip $(ACTIVE_GEMS)),) + # the default file which contains the active GEMs + ACTIVE_GEMS = mrbgems/GEMS.active +endif + ifeq ($(strip $(COMPILE_MODE)),) # default compile option COMPILE_MODE = debug @@ -27,9 +32,9 @@ endif ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) - MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' + MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' else - MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' + MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' endif ############################## -- cgit v1.2.3 From fdc030ab46a14be9c007d91f9bda47ad76e4b098 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:41:13 +0800 Subject: Change default location of GEMS.active file --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f2617b11b..2174eef7b 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ endif ifeq ($(strip $(ACTIVE_GEMS)),) # the default file which contains the active GEMs - ACTIVE_GEMS = mrbgems/GEMS.active + ACTIVE_GEMS = GEMS.active endif ifeq ($(strip $(COMPILE_MODE)),) -- cgit v1.2.3 From 755938aa5786cba80797cef56b728798003ad9c3 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:41:44 +0800 Subject: Respect dynamic GEMS.active file --- mrbgems/Makefile | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/mrbgems/Makefile b/mrbgems/Makefile index a0381d042..564f07ed4 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -20,6 +20,11 @@ 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 @@ -31,15 +36,15 @@ $(GEM_INIT).a : $(GEM_INIT).o all_gems : $(GENERATOR_BIN) @echo "Generate Gem List Makefile" - $(GENERATOR_BIN) makefile_list > $(GEM_MAKEFILE_LIST) + $(GENERATOR_BIN) makefile_list "$(ACTIVE_GEMS)" > $(GEM_MAKEFILE_LIST) @echo "Generate Gem Makefile" - $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) + $(GENERATOR_BIN) makefile "$(ACTIVE_GEMS)" > $(GEM_MAKEFILE) @echo "Build all gems" $(MAKE) -C g $(GEM_INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" - $(GENERATOR_BIN) $(GEM_INIT) > $@ + $(GENERATOR_BIN) $(GEM_INIT) "$(ACTIVE_GEMS)" > $@ $(GEM_INIT).o : $(GEM_INIT).c @echo "Build the driver which initializes all gems" @@ -56,12 +61,12 @@ $(GENERATOR).o : $(GENERATOR).c .PHONY : prepare-test prepare-test : - @$(MAKE) prepare-test -C g + @$(MAKE) prepare-test -C g ACTIVE_GEMS="$(ACTIVE_GEMS)" # clean driver and all gems .PHONY : clean clean : $(GENERATOR_BIN) @echo "Cleanup Gems" - $(GENERATOR_BIN) makefile > $(GEM_MAKEFILE) + $(GENERATOR_BIN) makefile "$(ACTIVE_GEMS)" > $(GEM_MAKEFILE) $(MAKE) clean -C g -$(RM_F) $(GEM_INIT).c *.o *.d $(GENERATOR_BIN) $(GEM_MAKEFILE) $(GEM_MAKEFILE_LIST) gem_init.a -- cgit v1.2.3 From 660eb545dbb60bbf0c338a3b381aef4dc3734c51 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:42:10 +0800 Subject: Respect dynamic GEMS.active file in mrbgems/Makefile4gem --- mrbgems/Makefile4gem | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mrbgems/Makefile4gem b/mrbgems/Makefile4gem index 3a2e74096..a24b162ab 100644 --- a/mrbgems/Makefile4gem +++ b/mrbgems/Makefile4gem @@ -26,6 +26,11 @@ endif GEM_PACKAGE := mrb-$(GEM)-gem.a +ifeq ($(strip $(ACTIVE_GEMS)),) + # the default file which contains the active GEMs + ACTIVE_GEMS = GEMS.active +endif + # Default rules which are calling the # gem specific gem-all and gem-clean # implementations of a gem @@ -44,14 +49,14 @@ gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp cat $^ > $@ gem_mixlib_init.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mixlib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mixlib $(GEM) "$(ACTIVE_GEMS)" > $@ # Building target for C files gem-c-files : gem_srclib.o $(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $< gem_srclib.c : - $(MRUBY_ROOT)mrbgems/generator gem_srclib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_srclib $(GEM) "$(ACTIVE_GEMS)" > $@ # Building target for Ruby Files gem-rb-files : gem_mrblib.o @@ -61,10 +66,10 @@ gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp cat $^ > $@ gem_mrblib_header.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mrblib > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mrblib "$(ACTIVE_GEMS)" > $@ gem_mrblib_init.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mrblib $(GEM) > $@ + $(MRUBY_ROOT)mrbgems/generator gem_mrblib $(GEM) "$(ACTIVE_GEMS)" > $@ gem_mrblib_irep.ctmp : gem_mrblib.rbtmp $(MRUBY_ROOT)bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< -- cgit v1.2.3 From e32077fed14a322dc465e9fc751fdf659e254515 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:42:29 +0800 Subject: Respect dynamic GEMS.active file in mrbgems/generator.c --- mrbgems/generator.c | 56 ++++++++++++++++++++++++++--------------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index a167b848b..668f7471c 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -65,7 +65,7 @@ char *replace(const char *s, const char *old, const char *new) static char* for_each_gem (char before[1024], char after[1024], char start[1024], char end[1024], - int full_path) + int full_path, char active_gems[1024]) { /* active GEM check */ FILE *active_gem_file; @@ -82,7 +82,7 @@ for_each_gem (char before[1024], char after[1024], strcat(complete_line, start); /* Read out the active GEMs */ - active_gem_file = fopen("GEMS.active", "r+"); + active_gem_file = fopen(active_gems, "r+"); if (active_gem_file != NULL) { char_index = 0; gem_index = 0; @@ -124,7 +124,7 @@ for_each_gem (char before[1024], char after[1024], * */ void -make_gem_makefile() +make_gem_makefile(char active_gems[1024]) { char *gem_check = { 0 }; int gem_empty; @@ -137,7 +137,7 @@ make_gem_makefile() "endif\n\n"); /* is there any GEM available? */ - gem_check = for_each_gem("", "", "", "", TRUE); + gem_check = for_each_gem("", "", "", "", TRUE, active_gems); if (strcmp(gem_check, "") == 0) gem_empty = TRUE; else @@ -153,7 +153,7 @@ make_gem_makefile() /* Call make for every GEM */ printf("all_gems :\n%s\n", - for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", TRUE) + for_each_gem("\t@$(MAKE) -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems) ); printf("\n"); } @@ -165,10 +165,10 @@ make_gem_makefile() ); if (!gem_empty) printf("%s", - for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE) + for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE, active_gems) ); else - printf("\t../generator rbtmp > mrbgemtest.rbtmp"); + printf("\t../generator rbtmp \"%s\"> mrbgemtest.rbtmp", active_gems); printf("\n\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n"); @@ -179,7 +179,7 @@ make_gem_makefile() "\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) + for_each_gem("\t@$(MAKE) clean -C ", " $(MAKE_FLAGS)\n", "", "", TRUE, active_gems) ); } @@ -191,10 +191,10 @@ make_gem_makefile() * */ void -make_gem_makefile_list() +make_gem_makefile_list(char active_gems[1024]) { printf("%s", - for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE) + for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE, active_gems) ); printf("GEM_ARCHIVE_FILES := $(GEM_LIST)\n" @@ -206,7 +206,7 @@ make_gem_makefile_list() * */ void -make_gem_init() +make_gem_init(char active_gems[1024]) { printf("/*\n" " * This file contains a list of all\n" @@ -221,7 +221,7 @@ make_gem_init() /* Protoype definition of all initialization methods */ printf("\n%s", - for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", FALSE) + for_each_gem("void GENERATED_TMP_mrb_", "_gem_init(mrb_state*);\n", "", "", FALSE, active_gems) ); printf("\n"); @@ -229,7 +229,7 @@ make_gem_init() printf("void\n" "mrb_init_mrbgems(mrb_state *mrb) {\n"); printf( "%s", - for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", FALSE) + for_each_gem(" GENERATED_TMP_mrb_", "_gem_init(mrb);\n", "", "", FALSE, active_gems) ); printf("}"); } @@ -241,7 +241,7 @@ make_gem_init() * */ void -make_rbtmp() +make_rbtmp(char active_gems[1024]) { printf("\n"); } @@ -253,7 +253,7 @@ make_rbtmp() * */ void -make_gem_mrblib_header() +make_gem_mrblib_header(char active_gems[1024]) { printf("/*\n" " * This file is loading the irep\n" @@ -278,7 +278,7 @@ make_gem_mrblib_header() * */ void -make_gem_mrblib(char argv[1024]) +make_gem_mrblib(char argv[1024], char active_gems[1024]) { printf("\n" "void\n" @@ -300,7 +300,7 @@ make_gem_mrblib(char argv[1024]) * */ void -make_gem_srclib(char argv[1024]) +make_gem_srclib(char argv[1024], char active_gems[1024]) { printf("/*\n" " * This file is loading the irep\n" @@ -331,7 +331,7 @@ make_gem_srclib(char argv[1024]) * */ void -make_gem_mixlib(char argv[1024]) +make_gem_mixlib(char argv[1024], char active_gems[1024]) { printf("\n" "void mrb_%s_gem_init(mrb_state*);\n", argv); @@ -357,29 +357,29 @@ int main (int argc, char *argv[]) { const char * argument_info = "Wrong argument! Options: 'makefile', 'gem_init', 'rbtmp', 'gem_mrblib', gem_srclib\n"; - if (argc == 2) { + if (argc == 3) { if (strcmp(argv[1], "makefile") == 0) - make_gem_makefile(); + make_gem_makefile(argv[2]); else if (strcmp(argv[1], "makefile_list") == 0) - make_gem_makefile_list(); + make_gem_makefile_list(argv[2]); else if (strcmp(argv[1], "gem_init") == 0) - make_gem_init(); + make_gem_init(argv[2]); else if (strcmp(argv[1], "rbtmp") == 0) - make_rbtmp(); + make_rbtmp(argv[2]); else if (strcmp(argv[1], "gem_mrblib") == 0) - make_gem_mrblib_header(); + make_gem_mrblib_header(argv[2]); else { printf("%s", argument_info); return 1; } } - else if (argc == 3) { + else if (argc == 4) { if (strcmp(argv[1], "gem_mrblib") == 0) - make_gem_mrblib(argv[2]); + make_gem_mrblib(argv[2], argv[3]); else if (strcmp(argv[1], "gem_srclib") == 0) - make_gem_srclib(argv[2]); + make_gem_srclib(argv[2], argv[3]); else if (strcmp(argv[1], "gem_mixlib") == 0) - make_gem_mixlib(argv[2]); + make_gem_mixlib(argv[2], argv[3]); else { printf("%s", argument_info); return 1; -- cgit v1.2.3 From b7911ad18e437395c0ace808005e5b42ce329237 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 19:48:06 +0800 Subject: Improve documentation to latest changes --- doc/mrbgems/README.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index e1de425f1..da64446d7 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -33,8 +33,8 @@ All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -have to build a *gem.a* file during this build process. How you are going -to do this is up to you. +have to build a *mrb-GEMNAME-gem.a* file during this build process. How you +are going to do this is up to you. To make your build process more easier and more standardized we suggest to include *mrbgems/Makefile4gem* which defines some helper rules. In @@ -52,8 +52,8 @@ The *Makefile* is used for building a C extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files) and *GEM_OBJECTS* (all Object files). Pay also attention that your *Makefile* has to build the object files. You can use -*gem-c-files* to build a *gem.a* out of your Object code and use -*gem-clean-c-files* to clean the object files. +*gem-c-files* to build a *mrb-GEMNAME-gem.a* out of your +Object code and use *gem-clean-c-files* to clean the object files. ### Pre-Conditions @@ -100,7 +100,7 @@ folder. The *Makefile* is used for building a Ruby extension. You should define *GEM* (GEM name) and *GEM_RB_FILES* (all Ruby files). You can use -*gem-rb-files* to build a *gem.a* out of your Ruby code and use +*gem-rb-files* to build a *mrb-GEMNAME-gem.a* out of your Ruby code and use *gem-clean-rb-files* to clean the generated C files. ### Pre-Conditions @@ -137,8 +137,9 @@ into the *mrblib* folder and all C files into the *src* folder. The *Makefile* is used for building a C and Ruby extension. You should define *GEM* (GEM name), *GEM_C_FILES* (all C files), *GEM_OBJECTS* (all Object files) and *GEM_RB_FILES* (all Ruby files). You can use -*gem-c-and-rb-files* to build a *gem.a* out of your Object and Ruby code -and use *gem-clean-c-and-rb-files* to clean the generated C files. +*gem-c-and-rb-files* to build a *mrb-GEMNAME-gem.a* out of your Object +and Ruby code. Use *gem-clean-c-and-rb-files* to clean the generated +C files. ### Pre-Conditions -- cgit v1.2.3 From 3d81ed3dc17e1112e9e47877946dea78a366a663 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 22:48:31 +0800 Subject: Improve examples with an absolute path to the mruby tree --- doc/mrbgems/c_and_ruby_extension_example/Makefile | 2 +- doc/mrbgems/c_extension_example/Makefile | 2 +- doc/mrbgems/ruby_extension_example/Makefile | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/doc/mrbgems/c_and_ruby_extension_example/Makefile b/doc/mrbgems/c_and_ruby_extension_example/Makefile index 0f562584e..57912a936 100644 --- a/doc/mrbgems/c_and_ruby_extension_example/Makefile +++ b/doc/mrbgems/c_and_ruby_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := c_and_ruby_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) diff --git a/doc/mrbgems/c_extension_example/Makefile b/doc/mrbgems/c_extension_example/Makefile index 4f78a0222..339669970 100644 --- a/doc/mrbgems/c_extension_example/Makefile +++ b/doc/mrbgems/c_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := c_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_C_FILES := $(wildcard $(SRC_DIR)/*.c) GEM_OBJECTS := $(patsubst %.c, %.o, $(GEM_C_FILES)) diff --git a/doc/mrbgems/ruby_extension_example/Makefile b/doc/mrbgems/ruby_extension_example/Makefile index 50c99829e..9c5026744 100644 --- a/doc/mrbgems/ruby_extension_example/Makefile +++ b/doc/mrbgems/ruby_extension_example/Makefile @@ -1,6 +1,6 @@ GEM := ruby_extension_example -include ../../Makefile4gem +include $(MAKEFILE_4_GEM) GEM_RB_FILES := $(wildcard $(MRB_DIR)/*.rb) -- cgit v1.2.3 From cc382f9bacf43e901ec2c87616c987c7f0a3e686 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 23 Nov 2012 22:49:21 +0800 Subject: Add the usage of MRUBY_ROOT to the mrbgems build system, so that we can easily build everywhere --- Makefile | 6 ++++-- mrbgems/Makefile | 12 ++++++++---- mrbgems/Makefile4gem | 16 ++++++++-------- mrbgems/generator.c | 14 +++++++++----- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 2174eef7b..475db6440 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,8 @@ export LL = gcc export AR = ar export YACC = bison +MRUBY_ROOT := $(realpath .) + ifeq ($(strip $(ENABLE_GEMS)),) # by default GEMs are deactivated ENABLE_GEMS = false @@ -32,9 +34,9 @@ endif ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) ifeq ($(OS),Windows_NT) - MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' + MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' MRUBY_ROOT='$(MRUBY_ROOT)' else - MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' + MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' ENABLE_GEMS='$(ENABLE_GEMS)' ACTIVE_GEMS='$(ACTIVE_GEMS)' MRUBY_ROOT='$(MRUBY_ROOT)' endif ############################## diff --git a/mrbgems/Makefile b/mrbgems/Makefile index 564f07ed4..c7d1f577d 100644 --- a/mrbgems/Makefile +++ b/mrbgems/Makefile @@ -1,6 +1,10 @@ # 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 @@ -9,7 +13,7 @@ export CC = gcc export LL = gcc export AR = ar -GENERATOR := ./generator +GENERATOR := $(MRUBY_ROOT)/mrbgems/generator ifeq ($(OS),Windows_NT) GENERATOR_BIN := $(GENERATOR).exe else @@ -40,7 +44,7 @@ all_gems : $(GENERATOR_BIN) @echo "Generate Gem Makefile" $(GENERATOR_BIN) makefile "$(ACTIVE_GEMS)" > $(GEM_MAKEFILE) @echo "Build all gems" - $(MAKE) -C g + $(MAKE) -C g MRUBY_ROOT='$(MRUBY_ROOT)' ACTIVE_GEMS="$(ACTIVE_GEMS)" $(GEM_INIT).c : $(GENERATOR_BIN) @echo "Generate Gem driver" @@ -61,12 +65,12 @@ $(GENERATOR).o : $(GENERATOR).c .PHONY : prepare-test prepare-test : - @$(MAKE) prepare-test -C g ACTIVE_GEMS="$(ACTIVE_GEMS)" + @$(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)" > $(GEM_MAKEFILE) - $(MAKE) clean -C g + $(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 a24b162ab..763210659 100644 --- a/mrbgems/Makefile4gem +++ b/mrbgems/Makefile4gem @@ -4,7 +4,7 @@ ifeq ($(strip $(MRUBY_ROOT)),) # mruby src root - MRUBY_ROOT := ../../../ + MRUBY_ROOT := $(realpath ../../..) endif # Tools @@ -15,13 +15,13 @@ AR := ar SRC_DIR := src MRB_DIR := mrblib -INCLUDES := -I$(SRC_DIR) -I$(MRUBY_ROOT)include -I$(MRUBY_ROOT)src -I. +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 - LIBR := $(MRUBY_ROOT)lib/libmruby.a + LIBR := $(MRUBY_ROOT)/lib/libmruby.a endif GEM_PACKAGE := mrb-$(GEM)-gem.a @@ -49,14 +49,14 @@ gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp cat $^ > $@ gem_mixlib_init.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mixlib $(GEM) "$(ACTIVE_GEMS)" > $@ + $(MRUBY_ROOT)/mrbgems/generator gem_mixlib $(GEM) "$(ACTIVE_GEMS)" > $@ # Building target for C files gem-c-files : gem_srclib.o $(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $< gem_srclib.c : - $(MRUBY_ROOT)mrbgems/generator gem_srclib $(GEM) "$(ACTIVE_GEMS)" > $@ + $(MRUBY_ROOT)/mrbgems/generator gem_srclib $(GEM) "$(ACTIVE_GEMS)" > $@ # Building target for Ruby Files gem-rb-files : gem_mrblib.o @@ -66,13 +66,13 @@ gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp cat $^ > $@ gem_mrblib_header.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mrblib "$(ACTIVE_GEMS)" > $@ + $(MRUBY_ROOT)/mrbgems/generator gem_mrblib "$(ACTIVE_GEMS)" > $@ gem_mrblib_init.ctmp : - $(MRUBY_ROOT)mrbgems/generator gem_mrblib $(GEM) "$(ACTIVE_GEMS)" > $@ + $(MRUBY_ROOT)/mrbgems/generator gem_mrblib $(GEM) "$(ACTIVE_GEMS)" > $@ gem_mrblib_irep.ctmp : gem_mrblib.rbtmp - $(MRUBY_ROOT)bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< + $(MRUBY_ROOT)/bin/mrbc -Bgem_mrblib_irep_$(GEM) -o$@ $< gem_mrblib.rbtmp : cat $(GEM_RB_FILES) > $@ diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 668f7471c..c1727670a 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -129,11 +129,15 @@ make_gem_makefile(char active_gems[1024]) char *gem_check = { 0 }; int gem_empty; - printf("CFLAGS := -I. -I../../include -I../../src\n\n" + 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" "ifeq ($(OS),Windows_NT)\n" - "MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL) ALL_CFLAGS='$(ALL_CFLAGS)'\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" "else\n" - "MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)'\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" "endif\n\n"); /* is there any GEM available? */ @@ -168,9 +172,9 @@ make_gem_makefile(char active_gems[1024]) for_each_gem(" ", "/test/*.rb ", "\tcat", " > mrbgemtest.rbtmp", TRUE, active_gems) ); else - printf("\t../generator rbtmp \"%s\"> mrbgemtest.rbtmp", active_gems); + printf("\t$(MRUBY_ROOT)/mrbgems/generator rbtmp \"%s\"> mrbgemtest.rbtmp", active_gems); - printf("\n\t../../bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n"); + printf("\n\t$(MRUBY_ROOT)/bin/mrbc -Bmrbgemtest_irep -omrbgemtest.ctmp mrbgemtest.rbtmp\n\n"); /* Makefile Rules to Clean GEMs */ -- cgit v1.2.3 From e9f87368825dc7061035bdc51e45f7d8f9ef66c9 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Sat, 24 Nov 2012 14:33:19 +0800 Subject: Add usage documentation for mrbgems --- doc/mrbgems/README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index da64446d7..c11e8a05f 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -3,6 +3,20 @@ mrbgems is a library manager to integrate C and Ruby extension in an easy and standardised way into mruby. +## Usage + +By default mrbgems is currently deactivated. As long as mrbgems is deactivated +there is no overhead inside of the mruby interpreter. + +To activate you have to make the following changes: +* set *ENABLE_GEMS* to *true* in *$(MRUBY_ROOT)/Makefile* +* define *ENABLE_GEMS* in *$(MRUBY_ROOT)/include/mrbconf.h* +* activate GEMs in *$(MRUBY_ROOT)/mrbgems/GEMS.active* + +Every activated GEM has to be listed with his absolute path in *GEMS.active*. It +is possible to point to an alternative activate file: +* set *ACTIVE_GEMS* to your customized GEM list in *$(MRUBY_ROOT)/Makefile* + ## GEM Structure The maximal GEM structure looks like this: @@ -28,8 +42,6 @@ rules to build a *gem.a* file inside of the GEM directory. Which will be used for integration into the normal mruby build process. *README.md* is a short description of your GEM. -All GEMs have to be located under *$(MRUBY_ROOT)/mrbgems/g/*. - ## Build process mrbgems will call *make* to build and *make clean* to clean your GEM. You -- cgit v1.2.3 From 712d6b8cd27e3f06dc08ea62b2a100ae0c328235 Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Mon, 26 Nov 2012 12:09:06 +0800 Subject: Change link-order for mrbgems as suggested by @sogabe to avoid linking-error --- mrbgems/generator.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index c1727670a..55861e4b4 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -201,8 +201,8 @@ make_gem_makefile_list(char active_gems[1024]) for_each_gem(" ", "/mrb-#GEMNAME#-gem.a", "GEM_LIST := ", "\n", TRUE, active_gems) ); - printf("GEM_ARCHIVE_FILES := $(GEM_LIST)\n" - "GEM_ARCHIVE_FILES += $(MRUBY_ROOT)/mrbgems/gem_init.a\n\n"); + printf("GEM_ARCHIVE_FILES := $(MRUBY_ROOT)/mrbgems/gem_init.a\n" + "GEM_ARCHIVE_FILES += $(GEM_LIST)\n\n"); } /* -- cgit v1.2.3 From 5f00a837edd0f55ed56d4d532d06ee45d9850f3c Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Wed, 28 Nov 2012 13:47:32 +0800 Subject: Small cosmetic change in the documentation for mrbgems --- doc/mrbgems/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/mrbgems/README.md b/doc/mrbgems/README.md index c11e8a05f..98ff44720 100644 --- a/doc/mrbgems/README.md +++ b/doc/mrbgems/README.md @@ -37,7 +37,7 @@ The maximal GEM structure looks like this: The folder *mrblib* contains pure Ruby files to extend mruby. The folder *src* contains C files to extend mruby. The folder *test* contains pure Ruby files -for testing purposes which will be used by mrbtest. The *Makefile* contains +for testing purposes which will be used by *mrbtest*. The *Makefile* contains rules to build a *gem.a* file inside of the GEM directory. Which will be used for integration into the normal mruby build process. *README.md* is a short description of your GEM. -- cgit v1.2.3 From bb6d42d987d2d03e20b7f0c8c8cd081a1082095b Mon Sep 17 00:00:00 2001 From: Daniel Bovensiepen Date: Fri, 7 Dec 2012 16:10:58 +0800 Subject: Remove non C99 confirm headers and add function comments --- mrbgems/generator.c | 58 +++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 17 deletions(-) diff --git a/mrbgems/generator.c b/mrbgems/generator.c index 55861e4b4..7f524cdbe 100644 --- a/mrbgems/generator.c +++ b/mrbgems/generator.c @@ -1,19 +1,43 @@ +/* +** generator.c - Generator for mrbgems +** +** See Copyright Notice in mruby.h +*/ + #include #include -#include -#include -#include -#include -#include #include - -char *get_file_name(char *path) +#include + +/* + * Get the file name part of *path* + * + * Arguments: + * path: + * String which represents the path + * + */ +static char +*get_file_name(char *path) { char *base = strrchr(path, '/'); return base ? base+1 : path; } -char *replace(const char *s, const char *old, const char *new) +/* + * Search in *s* for *old* and replace with *new*. + * + * Arguments: + * s: + * String in which the the replacement will be done + * old: + * String which will be replaced + * new: + * String which will be the replacement + * + */ +static char +*replace(const char *s, const char *old, const char *new) { char *ret; int i, count = 0; @@ -123,7 +147,7 @@ for_each_gem (char before[1024], char after[1024], * for every active GEM. * */ -void +static void make_gem_makefile(char active_gems[1024]) { char *gem_check = { 0 }; @@ -194,7 +218,7 @@ make_gem_makefile(char active_gems[1024]) * which need to know which GEMs are active. * */ -void +static void make_gem_makefile_list(char active_gems[1024]) { printf("%s", @@ -209,7 +233,7 @@ make_gem_makefile_list(char active_gems[1024]) * gem_init.c Generator * */ -void +static void make_gem_init(char active_gems[1024]) { printf("/*\n" @@ -241,10 +265,10 @@ make_gem_init(char active_gems[1024]) /* * Empty Generator * - * Generates a clean file. + * Generates a clean file with one new line. * */ -void +static void make_rbtmp(char active_gems[1024]) { printf("\n"); @@ -256,7 +280,7 @@ make_rbtmp(char active_gems[1024]) * Head of the C Code for loading the GEMs into the interpreter. * */ -void +static void make_gem_mrblib_header(char active_gems[1024]) { printf("/*\n" @@ -281,7 +305,7 @@ make_gem_mrblib_header(char active_gems[1024]) * the pure Ruby GEMs into the interpreter. * */ -void +static void make_gem_mrblib(char argv[1024], char active_gems[1024]) { printf("\n" @@ -303,7 +327,7 @@ make_gem_mrblib(char argv[1024], char active_gems[1024]) * the pure C GEMs into the interpreter. * */ -void +static void make_gem_srclib(char argv[1024], char active_gems[1024]) { printf("/*\n" @@ -334,7 +358,7 @@ make_gem_srclib(char argv[1024], char active_gems[1024]) * into the interpreter. * */ -void +static void make_gem_mixlib(char argv[1024], char active_gems[1024]) { printf("\n" -- cgit v1.2.3