forked from mruby/mruby
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Makefile
120 lines (102 loc) · 3.12 KB
/
Makefile
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
# makefile discription.
# basic build file for Rite-VM(mruby)
# 11.Apr.2011 coded by Kenji Yoshimoto.
# 17.Jan.2012 coded by Hiroshi Mimaki.
# project-specific macros
# extension of the executable-file is modifiable(.exe .out ...)
TARGET := bin/mrubysample
RITEVM := lib/ritevm
MRUBY := tools/mruby/mruby
ifeq ($(OS),Windows_NT)
EXE := $(TARGET).exe
LIB := $(RITEVM).lib
MRB := $(MRUBY).exe
else
EXE := $(TARGET)
LIB := $(RITEVM).a
MRB := $(MRUBY)
endif
MSRC := src/minimain.c
YSRC := src/parse.y
YC := src/y.tab.c
EXCEPT1 := $(YC) $(MSRC)
OBJM := $(patsubst %.c,%.o,$(MSRC))
OBJY := $(patsubst %.c,%.o,$(YC))
OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard src/*.c)))
#OBJ2 := $(patsubst %.c,%.o,$(wildcard ext/regex/*.c))
#OBJ3 := $(patsubst %.c,%.o,$(wildcard ext/enc/*.c))
OBJS := $(OBJ1) $(OBJ2) $(OBJ3)
# mruby libraries
EXTC := mrblib/mrblib.c
EXTRB := $(wildcard mrblib/*.rb)
EXT0 := $(patsubst %.c,%.o,src/$(EXTC))
# ext libraries
EXTS := $(EXT0)
# libraries, includes
LIBS = $(LIB) -lm
INCLUDES = -I./src -I./include
# library for iOS
IOSLIB := $(RITEVM)-ios.a
IOSSIMLIB := $(RITEVM)-iossim.a
IOSDEVLIB := $(RITEVM)-iosdev.a
IOSSIMCC := xcrun -sdk iphoneos llvm-gcc-4.2 -arch i386 -isysroot "/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk/"
IOSDEVCC := xcrun -sdk iphoneos llvm-gcc-4.2 -arch armv7 -isysroot "/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/"
# compiler, linker (gcc)
CC = gcc
LL = gcc
YACC = bison
DEBUG_MODE = 1
ifeq ($(DEBUG_MODE),1)
CFLAGS = -g
else
CFLAGS = -O3
endif
ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS)
MAKE_FLAGS = --no-print-directory CC=$(CC) LL=$(LL)
##############################
# generic build targets, rules
.PHONY : all
all : $(LIB) $(MRB) $(EXE)
@echo "make: built targets of `pwd`"
##############################
# make library for iOS
.PHONY : ios
ios : $(IOSLIB)
$(IOSLIB) : $(IOSSIMLIB) $(IOSDEVLIB)
lipo -arch i386 $(IOSSIMLIB) -arch armv7 $(IOSDEVLIB) -create -output $(IOSLIB)
$(IOSSIMLIB) :
$(MAKE) clean -C src $(MAKE_FLAGS)
$(MAKE) -C src $(MAKE_FLAGS) CC="$(IOSSIMCC)" LL="$(IOSSIMCC)"
cp $(LIB) $(IOSSIMLIB)
$(IOSDEVLIB) :
$(MAKE) clean -C src $(MAKE_FLAGS)
$(MAKE) -C src $(MAKE_FLAGS) CC="$(IOSDEVCC)" LL="$(IOSDEVCC)"
cp $(LIB) $(IOSDEVLIB)
# executable constructed using linker from object files
$(EXE) : $(OBJM) $(LIB)
$(LL) -o $@ $(OBJM) $(LIBS)
-include $(OBJS:.o=.d)
# src compile
$(LIB) : $(EXTS) $(OBJS) $(OBJY)
$(MAKE) -C src $(MAKE_FLAGS)
# mruby interpreter compile
$(MRB) : $(EXTS) $(OBJS) $(OBJY)
$(MAKE) -C tools/mruby $(MAKE_FLAGS)
# objects compiled from source
$(OBJS) :
$(MAKE) -C src $(MAKE_FLAGS) && $(MAKE) -C tools/mruby $(MAKE_FLAGS)
# extend libraries complile
$(EXTS) : $(EXTRB)
$(MAKE) -C mrblib $(MAKE_FLAGS)
# test module compile
$(OBJM) : $(MSRC)
$(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(MSRC) -o $(OBJM)
# clean up
.PHONY : clean
clean :
$(MAKE) clean -C src $(MAKE_FLAGS)
$(MAKE) clean -C tools/mruby $(MAKE_FLAGS)
-rm -f $(EXE) $(OBJM)
-rm -f $(OBJM:.o=.d)
-rm -f $(IOSLIB) $(IOSSIMLIB) $(IOSDEVLIB)
@echo "make: removing targets, objects and depend files of `pwd`"