1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
# This is the default Makefile integrated
# by each Gem. It integrates important constants
# for usage inside of a Gem.
ifeq ($(strip $(MRUBY_ROOT)),)
# mruby src root
MRUBY_ROOT := $(realpath ../../..)
endif
# Tools
CC := gcc
RM := rm -f
AR := ar
# mruby compiler
ifeq ($(OS),Windows_NT)
MRBC = $(MRUBY_ROOT)/bin/mrbc.exe
else
MRBC = $(MRUBY_ROOT)/bin/mrbc
endif
SRC_DIR := src
MRB_DIR := mrblib
TEST_DIR := test
GEM_TEST_RB_FILES := $(wildcard $(TEST_DIR)/*.rb)
GEM_TEST_C_FILES := $(wildcard $(TEST_DIR)/*.c)
# LIBR can be manipulated with command line arguments
ifeq ($(strip $(LIBR)),)
# default mruby library
LIBR := $(MRUBY_ROOT)/lib/libmruby.a
endif
GEM_PACKAGE := mrb-$(GEM)-gem.a
ifeq ($(strip $(ACTIVE_GEMS)),)
# the default file which contains the active GEMs
ACTIVE_GEMS = GEMS.active
endif
MAKEFILE_GEM_LIST := $(MRUBY_ROOT)/mrbgems/g/MakefileGemList
-include $(MAKEFILE_GEM_LIST)
# Default rules which are calling the
# gem specific gem-all and gem-clean
# implementations of a gem
.PHONY : all
all : gem-info gem-all
gem-info:
@echo "Building Gem '$(GEM)'"
# Building target for C and Ruby files
gem-c-and-rb-files : gem_mixlib.o
$(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $^
gem_mixlib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp
cat $^ > $@
gem_mixlib_init.ctmp :
ruby $(MRUBY_ROOT)/mrbgems/generate_gem_mixlib.rb '$(GEM)' > $@
# Building target for C files
gem-c-files : gem_srclib.o
$(AR) rs $(GEM_PACKAGE) $(GEM_OBJECTS) $<
gem_srclib.c :
ruby $(MRUBY_ROOT)/mrbgems/generate_gem_srclib.rb '$(GEM)' > $@
# Building target for Ruby Files
gem-rb-files : gem_mrblib.o
$(AR) rs $(GEM_PACKAGE) $<
gem_mrblib.c : gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mrblib_init.ctmp
cat $^ > $@
gem_mrblib_header.ctmp :
ruby $(MRUBY_ROOT)/mrbgems/generate_gem_mrblib_header.rb '$(GEM)' > $@
gem_mrblib_init.ctmp :
ruby $(MRUBY_ROOT)/mrbgems/generate_gem_mrblib.rb '$(GEM)' > $@
gem_mrblib_irep.ctmp : gem_mrblib.rbtmp
$(MRBC) -Bgem_mrblib_irep_$(subst -,_,$(GEM)) -o$@ $<
gem_mrblib.rbtmp :
cat $(GEM_RB_FILES) > $@
gem_test.ctmp : gem_test.rbtmp $(GEM_TEST_C_FILES)
$(MRBC) -Bgem_mrblib_irep_$(subst -,_,$(GEM))_test -o$@ $<
ifeq ($(GEM_TEST_C_FILES),)
echo "void mrb_$(subst -,_,$(GEM))_gem_test_init(mrb_state* mrb) { }" >> $@
else
cat $(GEM_TEST_C_FILES) >> $@
endif
gem_test.rbtmp : $(GEM_TEST_RB_FILES)
ifeq ($(GEM_TEST_RB_FILES),)
echo > $@
else
cat $(GEM_TEST_RB_FILES) > $@
endif
gem-test-c-and-rb-files : gem_test.ctmp
gem-test-c-files : gem_test.ctmp
gem-test-rb-files : gem_test.ctmp
gem-clean-c-and-rb-files :
-$(RM) $(GEM_PACKAGE) gem_mixlib.o gem_mixlib.c gem_mrblib_header.ctmp gem_mrblib_irep.ctmp gem_mixlib_init.ctmp gem_mrblib.rbtmp
-$(RM) gem_srclib.c gem_srclib.o $(GEM_OBJECTS) gem_test.ctmp gem_test.rbtmp gem-cflags.tmp gem-ldflags.tmp
gem-clean-c-files :
-$(RM) $(GEM_PACKAGE) gem_srclib.c gem_srclib.o $(GEM_OBJECTS) gem_test.ctmp gem_test.rbtmp gem-cflags.tmp gem-ldflags.tmp
gem-clean-rb-files :
-$(RM) $(GEM_PACKAGE) gem_mrblib.o gem_mrblib.c gem_mrblib_header.ctmp gem_mrblib_init.ctmp gem_mrblib_irep.ctmp gem_mrblib.rbtmp
-$(RM) gem_test.ctmp gem_test.rbtmp gem-cflags.tmp gem-ldflags.tmp
%.o : %.c
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(GEM_CFLAGS_LIST) $< -o $@
.PHONY : clean
clean : gem-clean
@echo "Gem '$(GEM)' is clean"
.PHONY : gem-flags
gem-flags :
@echo "$(MRUBY_CFLAGS) -I`pwd`/include" > gem-cflags.tmp
@echo "$(MRUBY_LDFLAGS)" > gem-ldflags.tmp
|