From 9f89da6eef2c830db6fc3abb08fe755ae7ce9b6c Mon Sep 17 00:00:00 2001 From: Jon Date: Wed, 2 May 2012 20:46:09 -0400 Subject: Add native and cross compiling CMake build support --- src/CMakeLists.txt | 23 +++++--------------- src/Makefile | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/Makefile.orig | 64 ------------------------------------------------------ 3 files changed, 70 insertions(+), 81 deletions(-) create mode 100644 src/Makefile delete mode 100644 src/Makefile.orig (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b25711ae3..390129eb9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,23 +1,12 @@ -# Build the C files in the mruby src directory - -cmake_minimum_required(VERSION 2.6) -if(CMAKE_VERSION VERSION_GREATER "2.8.0") - cmake_policy(SET CMP0012 OLD) -endif() +# build the core mruby C files find_package(BISON) -BISON_TARGET(mruby parse.y ${CMAKE_CURRENT_BINARY_DIR}/parse.c) +bison_target(mruby parse.y "${CMAKE_CURRENT_BINARY_DIR}/parse.c") -# configure_file("config.in.h" "config.h") file(GLOB MRUBY_SRC_C "*.c") -add_library(ritevm_object OBJECT ${MRUBY_SRC_C}) -add_library(ritevm_static STATIC $) -add_library(ritevm SHARED $) - +list(APPEND MRUBY_SRC_C "${CMAKE_CURRENT_BINARY_DIR}/parse.c") -# target_link_libraries(ritevm ${MRUBY_LIBS}) -# target_link_libraries(ritevm_static ${MRUBY_LIBS}) -# install(TARGETS ritevm ritevm_static -# LIBRARY DESTINATION lib -# ARCHIVE DESTINATION lib) +add_library(mruby_object OBJECT ${MRUBY_SRC_C} ${BISON_mruby_OUTPUTS}) +add_library(mruby_static STATIC EXCLUDE_FROM_ALL $) +# vim: ts=2 sts=2 sw=2 et diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 000000000..14485041d --- /dev/null +++ b/src/Makefile @@ -0,0 +1,64 @@ +# makefile discription. +# basic build file for mruby library + +# project-specific macros +# extension of the executable-file is modifiable(.exe .out ...) +BASEDIR = . +TARGET := ../lib/libmruby_core.a +YSRC := $(BASEDIR)/parse.y +YC := $(BASEDIR)/y.tab.c +EXCEPT1 := $(YC) $(BASEDIR)/minimain.c +OBJY := $(patsubst %.c,%.o,$(YC)) +OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c))) +#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c)) +#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c)) +OBJS := $(OBJ1) $(OBJ2) $(OBJ3) + +# libraries, includes +INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include + +# compiler, linker (gcc) +CC = gcc +LL = gcc +AR = ar +YACC = bison + +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g -O3 +else +CFLAGS = -O3 +endif +ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) + +############################## +# generic build targets, rules + +.PHONY : all +all : $(TARGET) + +# executable constructed using linker from object files +$(TARGET) : $(OBJS) $(OBJY) + $(AR) r $@ $(OBJS) $(OBJY) + +-include $(OBJS:.o=.d) $(OBJY:.o=.d) + +# objects compiled from source +$(OBJS) : %.o : %.c + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ + +# parser complie +$(OBJY) : $(YC) + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(YC) -o $(OBJY) + +# yacc complie +$(YC) : $(YSRC) + $(YACC) -o $(YC) $(YSRC) + +# clean up +.PHONY : clean #cleandep +clean : + @echo "make: removing targets, objects and depend files of `pwd`" + -rm -f $(TARGET) $(OBJS) $(OBJY) $(YC) + -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) + -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) diff --git a/src/Makefile.orig b/src/Makefile.orig deleted file mode 100644 index 14485041d..000000000 --- a/src/Makefile.orig +++ /dev/null @@ -1,64 +0,0 @@ -# makefile discription. -# basic build file for mruby library - -# project-specific macros -# extension of the executable-file is modifiable(.exe .out ...) -BASEDIR = . -TARGET := ../lib/libmruby_core.a -YSRC := $(BASEDIR)/parse.y -YC := $(BASEDIR)/y.tab.c -EXCEPT1 := $(YC) $(BASEDIR)/minimain.c -OBJY := $(patsubst %.c,%.o,$(YC)) -OBJ1 := $(patsubst %.c,%.o,$(filter-out $(EXCEPT1),$(wildcard $(BASEDIR)/*.c))) -#OBJ2 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/regex/*.c)) -#OBJ3 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/ext/enc/*.c)) -OBJS := $(OBJ1) $(OBJ2) $(OBJ3) - -# libraries, includes -INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include - -# compiler, linker (gcc) -CC = gcc -LL = gcc -AR = ar -YACC = bison - -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 -endif -ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) - -############################## -# generic build targets, rules - -.PHONY : all -all : $(TARGET) - -# executable constructed using linker from object files -$(TARGET) : $(OBJS) $(OBJY) - $(AR) r $@ $(OBJS) $(OBJY) - --include $(OBJS:.o=.d) $(OBJY:.o=.d) - -# objects compiled from source -$(OBJS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# parser complie -$(OBJY) : $(YC) - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(YC) -o $(OBJY) - -# yacc complie -$(YC) : $(YSRC) - $(YACC) -o $(YC) $(YSRC) - -# clean up -.PHONY : clean #cleandep -clean : - @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(TARGET) $(OBJS) $(OBJY) $(YC) - -rm -f $(OBJS:.o=.d) $(OBJY:.o=.d) - -rm -f $(patsubst %.c,%.o,$(EXCEPT1)) $(patsubst %.c,%.d,$(EXCEPT1)) -- cgit v1.2.3