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 --- .gitignore | 1 + AUTHORS | 1 + CMakeLists.txt | 199 +++++++++++++--------------- INSTALL | 14 +- Makefile | 41 ++++++ Makefile.orig | 41 ------ cmake/Toolchain-Arch-mingw32.cmake.sample | 30 +++++ cmake/Toolchain-OSX-mingw32.cmake.sample | 32 +++++ cmake/Toolchain-Ubuntu-mingw32.cmake.sample | 30 +++++ cmake/modules/IntrospectSystem.cmake | 52 ++++++++ mrblib/CMakeLists.txt | 89 ++++++++----- mrblib/Makefile | 73 ++++++++++ mrblib/Makefile.orig | 73 ---------- src/CMakeLists.txt | 23 +--- src/Makefile | 64 +++++++++ src/Makefile.orig | 64 --------- test/CMakeLists.txt | 42 ++++++ tools/CMakeLists.txt | 8 ++ tools/mirb/CMakeLists.txt | 9 ++ tools/mrbc/CMakeLists.txt | 8 +- tools/mrbc/Makefile | 67 ++++++++++ tools/mrbc/Makefile.orig | 67 ---------- tools/mruby/CMakeLists.txt | 8 +- tools/mruby/Makefile | 77 +++++++++++ tools/mruby/Makefile.orig | 77 ----------- tools/xpcat/CMakeLists.txt | 5 + tools/xpcat/xpcat.c | 69 ++++++++++ 27 files changed, 772 insertions(+), 492 deletions(-) create mode 100644 Makefile delete mode 100644 Makefile.orig create mode 100644 cmake/Toolchain-Arch-mingw32.cmake.sample create mode 100644 cmake/Toolchain-OSX-mingw32.cmake.sample create mode 100644 cmake/Toolchain-Ubuntu-mingw32.cmake.sample create mode 100644 cmake/modules/IntrospectSystem.cmake create mode 100644 mrblib/Makefile delete mode 100644 mrblib/Makefile.orig create mode 100644 src/Makefile delete mode 100644 src/Makefile.orig create mode 100644 test/CMakeLists.txt create mode 100644 tools/CMakeLists.txt create mode 100644 tools/mirb/CMakeLists.txt create mode 100644 tools/mrbc/Makefile delete mode 100644 tools/mrbc/Makefile.orig create mode 100644 tools/mruby/Makefile delete mode 100644 tools/mruby/Makefile.orig create mode 100644 tools/xpcat/CMakeLists.txt create mode 100644 tools/xpcat/xpcat.c diff --git a/.gitignore b/.gitignore index 1f700fa66..9389c11da 100644 --- a/.gitignore +++ b/.gitignore @@ -19,6 +19,7 @@ cscope.out /bin /mrblib/mrblib.c /mrblib/*.*tmp +/build /test/mrbtest /test/mrbtest.c /test/*.*tmp diff --git a/AUTHORS b/AUTHORS index b39a69220..b4554be64 100644 --- a/AUTHORS +++ b/AUTHORS @@ -4,3 +4,4 @@ Original Authors "mruby developers" are: Kyushu Institute of Technology Network Applied Communication Laboratory, Inc. Daniel Bovensiepen + Jon Maken diff --git a/CMakeLists.txt b/CMakeLists.txt index 752222db0..ee97ad8b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,124 +1,109 @@ -# -# Cmake build system for muby by beoran@rubyforhe.org, 2012. -# Released under the same license as mruby. -# -# NOTE: the original Makefile build system had a few hacks in them, -# whch I didn't duplicate. In stead the build logic is like this: -# 1) First libritevm_object is built -# 2) From this libritevm_static.a is built. -# 2) Then mrbc is built and linked with libritevm_static.a . -# 4) Then libmrblib_object is builtfrom are built from the rb files in -# the mrblib subdirectory -# 5) Then libmrblib_object & libritevm_object are linked together into -# a single library libmrubylib_static.a -# 6) Finally, mruby is built and linked with libmrubylib_static.a -# -# As a result, applications that embed mruby will have to link against -# libmrubylib_static.a only.. -# -# TODO: make this work on windows too, support build options to generate -# mrbconf.h, etc... +# CMake build system for mruby +# License: released under the same license as mruby +# Author: jonforums@gmail.com +# Author: beoran@gmail.com # +# Usage example: +# 1. Ensure CMake, Bison, and a build toolchain are on `PATH` +# 2. Change to a build directory outside source tree, eg - `build` subdir +# 3. Create build Makefiles or project files. +# `cmake ..` (UNIX-like system) +# `cmake -G "MSYS Makefiles" ..` +# `cmake -G "Visual Studio 10" ..` +# `cmake -G "NMake Makefiles" ..` +# ** to cross-compile: add -DCMAKE_TOOLCHAIN_FILE=/path/to/toolchain/file +# ** to set install dir: add -DCMAKE_INSTALL_PREFIX=/path/to/installdir +# 4a. Build: `make` (to make noisy, add `VERBOSE=1`) +# 4b. Build and test: `make all test` +# 4c. Build, test, and install: `make all test install` +# 4d. Build, test, and package: `make all test package` -# Setup -# Need at least cmake version 2.8.8 cmake_minimum_required(VERSION 2.8.8 FATAL_ERROR) + +# Default build mode is Release With Debug Info unless specified +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo CACHE STRING + "Choose build type: empty Debug Release RelWithDebInfo MinSizeRel" + FORCE) + message(STATUS "Build type not set, defaulting to 'RelWithDebInfo'") +endif() + +project(mruby C) + +# TODO stop polluting source tree with CMakeFiles/ and CMakeCache.txt +# on build location check failure +# Make sure we are not trying to generate in in-tree build unless building +# with a MSVC IDE where it's OK. +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR AND NOT MSVC_IDE) + message(FATAL_ERROR + "\nIn-source builds are not allowed as CMake would overwrite the " + "Makefiles distributed with mruby. Please change to the 'build' " + "subdirectory and run CMake from there.") +endif() + if(COMMAND cmake_policy) - cmake_policy(SET CMP0003 NEW) - cmake_policy(SET CMP0015 NEW) + cmake_policy(SET CMP0003 NEW) # don't split absolute link paths + cmake_policy(SET CMP0012 NEW) # recognize number & boolean literals + cmake_policy(SET CMP0015 NEW) # convert relative link paths to absolute endif(COMMAND cmake_policy) -# Set the project name, we use only plain C. -project(MRUBY C) - -# C compiler flags. -set(CMAKE_C_FLAGS "-Wall -g") -# should use -O3 if it's a release build.bin/mrb +# Match original Makefile's default in-tree install. +if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR} CACHE PATH + "Install path prefix prepended to install directories." + FORCE + ) +endif() +# TODO refactor to use an option when adding shared lib support +set(BUILD_SHARED_LIBS OFF) # Version of mruby, useful for versoning .so and .dll files. -set(MRUBY_VERSION 1.0.0) +# TODO automate by parsing src/version.h -or- extract git info? +set(MRUBY_VERSION 1.0.0dev) string(REGEX MATCH "^[0-9]+[.][0-9]+" MRUBY_SOVERSION ${MRUBY_VERSION}) string(REPLACE "." "" MRUBY_DLL_SHORTVER ${MRUBY_SOVERSION}) -# Search in the `cmake' directory for additional CMake modules if needed. -list(APPEND CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake) +# Search in the `cmake` directory for custom CMake helper modules. +list(APPEND CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules") +include(IntrospectSystem) # Search for C header files in these directories. -include_directories(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/src) - -# Search for libaries too link tools with here: -link_directories("lib") -link_directories("mrblib") - -# put binaries that get built in bin -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin) -# Put libraries that get built into `lib'. -set(LIBRARY_OUTPUT_PATH ${CMAKE_BINARY_DIR}/lib) - -if(NOT IPHONE) -option(SHARED "Build shared libraries" on) -set(BUILD_SHARED_LIBS ${SHARED}) # actual CMake variable -endif(NOT IPHONE) +include_directories("${CMAKE_SOURCE_DIR}/include" "${CMAKE_SOURCE_DIR}/src") +# TODO re-enable (and implement) if needed # On some 64-bit platforms, libraries should be installed into `lib64' # instead of `lib'. Set this to 64 to do that. -set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'") - -set(FRAMEWORK_INSTALL_PREFIX "/Library/Frameworks" CACHE STRING - "Directory in which to install Mac OS X frameworks") - -# Options (none yet). - -# Set up compilers. - -include(CheckCSourceCompiles) - -# Begin tests - -include(CheckFunctionExists) -include(CheckIncludeFiles) -include(CheckLibraryExists) -include(CheckSymbolExists) -include(CheckTypeSize) -include(FindPkgConfig) -include(TestBigEndian) - - -# lib Libraries that mruby uses itself (just libm) -set(MRUBY_LIBS m) - -# Compile the sources to make libritevm -add_subdirectory("src") - -# compile the compiler tool -add_subdirectory("tools/mrbc") - -# compile libmrblib -add_subdirectory("mrblib") - -# generate final library -add_library(mrubylib_static STATIC - $ $) -add_library(mrubylib SHARED - $ $) - -install(TARGETS mrubylib mrubylib_static - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib) - -# compile the interpreter tool -add_subdirectory("tools/mruby") - -# for make install, install the header files -install(FILES include/mruby.h DESTINATION include) -install(FILES include/mrbconf.h DESTINATION include) -install(DIRECTORY include/mruby DESTINATION include) -# For now, also install header files in src dir to ${PREFIX}include/mruby -file(GLOB SRC_HEADERS src/*.h) -install (FILES ${SRC_HEADERS} DESTINATION include/mruby) - - - - - +#set(LIB_SUFFIX "" CACHE STRING "Suffix for 'lib' directories, e.g. '64'") + +# build the components +add_subdirectory(src) +add_subdirectory(mrblib) +add_subdirectory(tools) +add_subdirectory(test) + +# install the header files +install(FILES include/mruby.h DESTINATION include) +install(FILES include/mrbconf.h DESTINATION include) +install(DIRECTORY include/mruby DESTINATION include FILES_MATCHING PATTERN "*.h") + +# TODO refactor once proper versioning scheme implemented +# archive packaging +set(CPACK_GENERATOR "TGZ;ZIP") +string(TOLOWER ${CMAKE_SYSTEM_NAME} MRUBY_HOST) +if(CMAKE_C_COMPILER_VERSION) + string(REPLACE "." "" MRUBY_GCC_VERSION ${CMAKE_C_COMPILER_VERSION}) +endif() + +# TODO add build info suffix for non-Windows builds? +if(MINGW) + set(MRUBY_BUILD "-mingw${MRUBY_GCC_VERSION}") +elseif(MSVC) + set(MRUBY_BUILD "-msvc${MSVC_VERSION}") +endif() +set(CPACK_PACKAGE_FILE_NAME + "${CMAKE_PROJECT_NAME}-${MRUBY_VERSION}-${MRUBY_HOST}${MRUBY_BUILD}" + ) +include(CPack) + +# vim: ts=2 sts=2 sw=2 et diff --git a/INSTALL b/INSTALL index 0aae03655..92851c86d 100644 --- a/INSTALL +++ b/INSTALL @@ -1,21 +1,17 @@ * Prerequisites 1. Make sure you have bison (http://www.gnu.org/software/bison/) installed in your system. - 2 Make sure you have cmake (http://www.cmake.org version 2.8.8 or - later installed). - * Compilation and Installation - 1. Run cmake . ; make ; make install in the top directory. - - + 1. Run make in the top directory. + This command will create the following directories and store libraries and binaries files into them. - * /usr/local/bin - * /usr/local/lib - * /usr/local/include + * bin + * lib + * include If an error occurs when compiling mruby, it will be helpful for others if you send a detailed report to the developers that includes the error log, machine, diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..fc22089a9 --- /dev/null +++ b/Makefile @@ -0,0 +1,41 @@ +# makefile discription. +# basic build file for mruby + +# compiler, linker (gcc) +CC = gcc +LL = gcc +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g -O3 +else +CFLAGS = -O3 +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)' +else + MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' +endif + +############################## +# generic build targets, rules + +.PHONY : all +all : + @$(MAKE) -C src $(MAKE_FLAGS) + @$(MAKE) -C mrblib $(MAKE_FLAGS) + @$(MAKE) -C tools/mruby $(MAKE_FLAGS) + @$(MAKE) -C tools/mirb $(MAKE_FLAGS) + +# mruby test +.PHONY : test +test : all + @$(MAKE) -C test $(MAKE_FLAGS) + +# clean up +.PHONY : clean +clean : + @$(MAKE) clean -C src $(MAKE_FLAGS) + @$(MAKE) clean -C tools/mruby $(MAKE_FLAGS) + @$(MAKE) clean -C tools/mirb $(MAKE_FLAGS) + @$(MAKE) clean -C test $(MAKE_FLAGS) diff --git a/Makefile.orig b/Makefile.orig deleted file mode 100644 index fc22089a9..000000000 --- a/Makefile.orig +++ /dev/null @@ -1,41 +0,0 @@ -# makefile discription. -# basic build file for mruby - -# compiler, linker (gcc) -CC = gcc -LL = gcc -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 -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)' -else - MAKE_FLAGS = --no-print-directory CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif - -############################## -# generic build targets, rules - -.PHONY : all -all : - @$(MAKE) -C src $(MAKE_FLAGS) - @$(MAKE) -C mrblib $(MAKE_FLAGS) - @$(MAKE) -C tools/mruby $(MAKE_FLAGS) - @$(MAKE) -C tools/mirb $(MAKE_FLAGS) - -# mruby test -.PHONY : test -test : all - @$(MAKE) -C test $(MAKE_FLAGS) - -# clean up -.PHONY : clean -clean : - @$(MAKE) clean -C src $(MAKE_FLAGS) - @$(MAKE) clean -C tools/mruby $(MAKE_FLAGS) - @$(MAKE) clean -C tools/mirb $(MAKE_FLAGS) - @$(MAKE) clean -C test $(MAKE_FLAGS) diff --git a/cmake/Toolchain-Arch-mingw32.cmake.sample b/cmake/Toolchain-Arch-mingw32.cmake.sample new file mode 100644 index 000000000..727fa04ce --- /dev/null +++ b/cmake/Toolchain-Arch-mingw32.cmake.sample @@ -0,0 +1,30 @@ +# Sample toolchain file for building for Windows from an Arch Linux system. +# +# Typical usage: +# 1) install cross compiler: `sudo pacman -S mingw32-gcc` +# 2) cp cmake/Toolchain-Arch-mingw32.cmake.sample ~/Toolchain-Arch-mingw32.cmake +# 3) tweak toolchain values as needed +# 4) cd build +# 5) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-Arch-mingw32.cmake .. + +# name of the target OS on which the built artifacts will run +# and the toolchain prefix +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX i486-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +# set 2nd to dir containing personal cross development headers/libs +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX} ~/crossdev/w32) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/Toolchain-OSX-mingw32.cmake.sample b/cmake/Toolchain-OSX-mingw32.cmake.sample new file mode 100644 index 000000000..4926645e7 --- /dev/null +++ b/cmake/Toolchain-OSX-mingw32.cmake.sample @@ -0,0 +1,32 @@ +# Sample toolchain file for building for Windows from an OS X system. +# +# Typical usage: +# 1) install a mingw-w64 cross compiler +# a) darwin toolchain targeting win32: http://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/ +# b) extract toolchain into ~/mingw/w32 +# 2) cp cmake/Toolchain-OSX-mingw32.cmake.sample ~/Toolchain-OSX-mingw32.cmake +# 3) tweak toolchain values as needed +# 4) cd build +# 5) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-OSX-mingw32.cmake .. + +# name of the target OS on which the built artifacts will run +# and the toolchain prefix +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX i686-w64-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment(s) on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +# set 2nd to dir containing personal cross development headers/libs +set(CMAKE_FIND_ROOT_PATH ~/mingw/w32/${TOOLCHAIN_PREFIX} ~/crossdev/w32) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/Toolchain-Ubuntu-mingw32.cmake.sample b/cmake/Toolchain-Ubuntu-mingw32.cmake.sample new file mode 100644 index 000000000..adc24e501 --- /dev/null +++ b/cmake/Toolchain-Ubuntu-mingw32.cmake.sample @@ -0,0 +1,30 @@ +# Sample toolchain file for building for Windows from an Ubuntu Linux system. +# +# Typical usage: +# 1) install cross compiler: `sudo apt-get install mingw-w64 g++-mingw-w64` +# 2) cp cmake/Toolchain-Ubuntu-mingw32.cmake.sample ~/Toolchain-Ubuntu-mingw32.cmake +# 3) tweak toolchain values as needed +# 4) cd build +# 5) cmake -DCMAKE_TOOLCHAIN_FILE=~/Toolchain-Ubuntu-mingw32.cmake .. + +# name of the target OS on which the built artifacts will run +# and the toolchain prefix +set(CMAKE_SYSTEM_NAME Windows) +set(TOOLCHAIN_PREFIX i686-w64-mingw32) + +# cross compilers to use for C and C++ +set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) +set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) +set(CMAKE_RC_COMPILER ${TOOLCHAIN_PREFIX}-windres) + +# target environment on the build host system +# set 1st to dir with the cross compiler's C/C++ headers/libs +# set 2nd to dir containing personal cross development headers/libs +set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX} ~/crossdev/w32) + +# modify default behavior of FIND_XXX() commands to +# search for headers/libs in the target environment and +# search for programs in the build host environment +set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) +set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) +set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) diff --git a/cmake/modules/IntrospectSystem.cmake b/cmake/modules/IntrospectSystem.cmake new file mode 100644 index 000000000..e148563fa --- /dev/null +++ b/cmake/modules/IntrospectSystem.cmake @@ -0,0 +1,52 @@ +# system capabilities checking + +# initial system defaults +if(CMAKE_COMPILER_IS_GNUCC) + set(MRUBY_DEFAULT_CFLAGS "-Wall -Werror-implicit-function-declaration") + set(CMAKE_C_FLAGS "${MRUBY_DEFAULT_CFLAGS}") + set(CMAKE_C_FLAGS_DEBUG "-O3 -ggdb") + set(CMAKE_C_FLAGS_MINSIZEREL "-Os -DNDEBUG") + set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O3 -g") + set(CMAKE_C_FLAGS_RELEASE "-O3 -DNDEBUG") + + set(MRUBY_LIBS m) +else() + if(MSVC) + # TODO default MSVC flags + add_definitions( + -D_CRT_SECURE_NO_WARNINGS + -wd4018 # suppress 'signed/unsigned mismatch' + ) + endif() +endif() + +if(MSVC) + add_definitions( + -DRUBY_EXPORT # required by oniguruma.h + ) +endif() + + +# include helpers +include(CheckIncludeFile) +include(CheckSymbolExists) + +# header checks +CHECK_INCLUDE_FILE(string.h HAVE_STRING_H) +if(HAVE_STRING_H) + add_definitions(-DHAVE_STRING_H) +endif() + +CHECK_INCLUDE_FILE(float.h HAVE_FLOAT_H) +if(HAVE_FLOAT_H) + add_definitions(-DHAVE_FLOAT_H) +endif() + + +# symbol checks +CHECK_SYMBOL_EXISTS(gettimeofday sys/time.h HAVE_GETTIMEOFDAY) +if(NOT HAVE_GETTIMEOFDAY) + add_definitions(-DNO_GETTIMEOFDAY) +endif() + +# vim: ts=2 sts=2 sw=2 et diff --git a/mrblib/CMakeLists.txt b/mrblib/CMakeLists.txt index 30881c611..b9fa22587 100644 --- a/mrblib/CMakeLists.txt +++ b/mrblib/CMakeLists.txt @@ -1,35 +1,62 @@ -# build mrblib -# need custom commands -# Compile C source from merged mruby source +# transform mruby's standard lib into a C library file(GLOB MRBLIB_SRC_RB "*.rb") -# generate the a single rubu file from all the existing ones. -add_custom_command(OUTPUT mrblib.rbtmp -COMMAND cat ${MRBLIB_SRC_RB} > mrblib.rbtmp -DEPENDS ${MRBLIB_SRC_RB} -) - -# generate the intermediate representation in C -add_custom_command(OUTPUT mrblib_irep.c -COMMAND echo -B mrblib_irep -o mrblib_irep.c mrblib.rbtmp -COMMAND mrbc -Bmrblib_irep -omrblib_irep.c mrblib.rbtmp -DEPENDS mrblib.rbtmp -) - -# finally generate the library's c file -add_custom_command(OUTPUT mrblib.c -COMMAND cat init_mrblib.c mrblib_irep.c > mrblib.c -DEPENDS init_mrblib.c mrblib_irep.c -) - -# only use this C file to generate mrblib. -set(MRBLIB_SRC_C mrblib.c) -# add_library(mrblib_static STATIC ${MRBLIB_SRC_C}) -add_library(mrblib_object OBJECT ${MRBLIB_SRC_C}) -# target_link_libraries(mrblib ritevm ${MRUBY_LIBS}) -# target_link_libraries(mrblib_static ritevm_static ${MRUBY_LIBS}) -# install(TARGETS mrblib mrblib_static -# LIBRARY DESTINATION lib -# ARCHIVE DESTINATION lib) +if(CMAKE_CROSSCOMPILING) + # create native tools and `mrblib.ctmp` required to build `mrblib.c` + include(ExternalProject) + ExternalProject_Add(mruby-native + DOWNLOAD_COMMAND "" + SOURCE_DIR "${CMAKE_SOURCE_DIR}" + CONFIGURE_COMMAND "${CMAKE_COMMAND}" "${CMAKE_SOURCE_DIR}" + INSTALL_COMMAND "" + BINARY_DIR "${CMAKE_BINARY_DIR}/native" + ) + # aggregate mruby's standard library as a single C file + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c" + DEPENDS mruby-native init_mrblib.c "${CMAKE_BINARY_DIR}/native/mrblib/mrblib.ctmp" + COMMAND "${CMAKE_BINARY_DIR}/native/tools/xpcat/xpcat" + -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c" + "${CMAKE_CURRENT_SOURCE_DIR}/init_mrblib.c" + "${CMAKE_BINARY_DIR}/native/mrblib/mrblib.ctmp" + ) +else() + # generate a single rb file from all existing ones + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp" + DEPENDS xpcat + COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp" ${MRBLIB_SRC_RB} + ) + + # mruby compile and generate C byte array representation + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp" + DEPENDS mrbc "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp" + COMMAND mrbc -Bmrblib_irep -o"${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp" + "${CMAKE_CURRENT_BINARY_DIR}/mrblib.rbtmp" + ) + + # aggregate mruby's standard library as a single C file + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c" + DEPENDS xpcat init_mrblib.c "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp" + COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrblib.c" + "${CMAKE_CURRENT_SOURCE_DIR}/init_mrblib.c" + "${CMAKE_CURRENT_BINARY_DIR}/mrblib.ctmp" + ) +endif() + + +add_library(mrblib_object OBJECT mrblib.c) + +# generate final static libmruby archive library +add_library(libmruby_static STATIC + $ + $ + ) +set_target_properties(libmruby_static PROPERTIES OUTPUT_NAME mruby) + +install(TARGETS libmruby_static + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) + +# vim: ts=2 sts=2 sw=2 et diff --git a/mrblib/Makefile b/mrblib/Makefile new file mode 100644 index 000000000..d22c4509f --- /dev/null +++ b/mrblib/Makefile @@ -0,0 +1,73 @@ +# makefile discription. +# basic build file for mruby library (Ruby part) + +# project-specific macros +# extension of the executable-file is modifiable(.exe .out ...) +BASEDIR = . +TARGET := mrblib +MLIB := $(TARGET).o +CLIB := $(TARGET).c +DLIB := $(TARGET).ctmp +RLIB := $(TARGET).rbtmp +DEPLIB := $(TARGET).d +MRB1 := $(BASEDIR)/*.rb +MRBS := $(MRB1) +LIBR0 := ../lib/libmruby_core.a +LIBR := ../lib/libmruby.a + +# C compiler (gcc) +CC = gcc +LL = gcc +AR = ar +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g +else +CFLAGS = -O3 +endif +INCLUDES = -I../src -I../include +ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) +ifeq ($(OS),Windows_NT) + MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" +else + MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' +endif + +# mruby compiler +ifeq ($(OS),Windows_NT) +MRBC = ../bin/mrbc.exe +else +MRBC = ../bin/mrbc +endif + +############################## +# generic build targets, rules + +.PHONY : all +all : $(LIBR) + +# update libmruby.a +$(LIBR) : $(MLIB) $(LIBR0) + cp $(LIBR0) $(LIBR) + $(AR) r $(LIBR) $(MLIB) + +# Compile mrblib source +$(MLIB) : $(CLIB) + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(CLIB) -o $(MLIB) + +# Compile C source from merged mruby source +$(CLIB) : $(RLIB) $(MRBC) + $(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); cat init_$(TARGET).c $(DLIB) > $@ + +$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y + $(MAKE) -C ../tools/mrbc $(MAKE_FLAGS) + +# merge mruby sources +$(RLIB) : $(MRBS) + cat $? > $@ + +# clean up +.PHONY : clean +clean : + @echo "make: removing targets, objects and depend files of `pwd`" + -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR) diff --git a/mrblib/Makefile.orig b/mrblib/Makefile.orig deleted file mode 100644 index d22c4509f..000000000 --- a/mrblib/Makefile.orig +++ /dev/null @@ -1,73 +0,0 @@ -# makefile discription. -# basic build file for mruby library (Ruby part) - -# project-specific macros -# extension of the executable-file is modifiable(.exe .out ...) -BASEDIR = . -TARGET := mrblib -MLIB := $(TARGET).o -CLIB := $(TARGET).c -DLIB := $(TARGET).ctmp -RLIB := $(TARGET).rbtmp -DEPLIB := $(TARGET).d -MRB1 := $(BASEDIR)/*.rb -MRBS := $(MRB1) -LIBR0 := ../lib/libmruby_core.a -LIBR := ../lib/libmruby.a - -# C compiler (gcc) -CC = gcc -LL = gcc -AR = ar -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -else -CFLAGS = -O3 -endif -INCLUDES = -I../src -I../include -ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) -ifeq ($(OS),Windows_NT) - MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -else - MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif - -# mruby compiler -ifeq ($(OS),Windows_NT) -MRBC = ../bin/mrbc.exe -else -MRBC = ../bin/mrbc -endif - -############################## -# generic build targets, rules - -.PHONY : all -all : $(LIBR) - -# update libmruby.a -$(LIBR) : $(MLIB) $(LIBR0) - cp $(LIBR0) $(LIBR) - $(AR) r $(LIBR) $(MLIB) - -# Compile mrblib source -$(MLIB) : $(CLIB) - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $(CLIB) -o $(MLIB) - -# Compile C source from merged mruby source -$(CLIB) : $(RLIB) $(MRBC) - $(MRBC) -Bmrblib_irep -o$(DLIB) $(RLIB); cat init_$(TARGET).c $(DLIB) > $@ - -$(MRBC) : ../src/opcode.h ../src/codegen.c ../src/parse.y - $(MAKE) -C ../tools/mrbc $(MAKE_FLAGS) - -# merge mruby sources -$(RLIB) : $(MRBS) - cat $? > $@ - -# clean up -.PHONY : clean -clean : - @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(MRBC) $(MLIB) $(CLIB) $(RLIB) $(DLIB) $(DEPLIB) $(LIBR) 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)) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 000000000..45031fc72 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,42 @@ +# build standalone mrbtest runner containing all *.rb tests + +if(NOT CMAKE_CROSSCOMPILING) + + file(GLOB MRBTEST_SRC_RB "assert.rb" "t/*.rb") + + # generate a single rb file from all existing test *.rb + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.rbtmp" + DEPENDS xpcat + COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.rbtmp" ${MRBTEST_SRC_RB} + ) + + # mruby compile and generate C byte array representation + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.ctmp" + DEPENDS mrbc "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.rbtmp" + COMMAND mrbc -Bmrbtest_irep -o"${CMAKE_CURRENT_BINARY_DIR}/mrbtest.ctmp" + "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.rbtmp" + ) + + # aggregate mruby's *.rb test files as a single C file + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.c" + DEPENDS xpcat init_mrbtest.c "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.ctmp" + COMMAND xpcat -o "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.c" + "${CMAKE_CURRENT_SOURCE_DIR}/init_mrbtest.c" + "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.ctmp" + ) + + add_executable(mrbtest + EXCLUDE_FROM_ALL + "${CMAKE_CURRENT_SOURCE_DIR}/driver.c" + "${CMAKE_CURRENT_BINARY_DIR}/mrbtest.c" + ) + target_link_libraries(mrbtest libmruby_static ${MRUBY_LIBS}) + + add_custom_target(test + DEPENDS mrbtest + COMMAND "${CMAKE_CURRENT_BINARY_DIR}/mrbtest" + ) + +endif() + +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 000000000..ce348f3aa --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,8 @@ +# specify the internal and external tools to be built + +add_subdirectory(xpcat) +add_subdirectory(mrbc) +add_subdirectory(mruby) +add_subdirectory(mirb) + +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/mirb/CMakeLists.txt b/tools/mirb/CMakeLists.txt new file mode 100644 index 000000000..a9f52db1f --- /dev/null +++ b/tools/mirb/CMakeLists.txt @@ -0,0 +1,9 @@ +# build tools/mirb executable + +file(GLOB MIRBBIN_SRC_C "*.c") +add_executable(mirb ${MIRBBIN_SRC_C}) +target_link_libraries(mirb libmruby_static ${MRUBY_LIBS}) + +install(TARGETS mirb RUNTIME DESTINATION bin) + +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/mrbc/CMakeLists.txt b/tools/mrbc/CMakeLists.txt index 073ac1743..71a3a937d 100644 --- a/tools/mrbc/CMakeLists.txt +++ b/tools/mrbc/CMakeLists.txt @@ -1,7 +1,9 @@ -# builds tools/mrbc +# build tools/mrbc executable + file(GLOB MRBC_SRC_C "*.c") add_executable(mrbc ${MRBC_SRC_C}) -target_link_libraries(mrbc ritevm_static ${MRUBY_LIBS}) -install(TARGETS mrbc RUNTIME DESTINATION bin) +target_link_libraries(mrbc mruby_static ${MRUBY_LIBS}) +install(TARGETS mrbc RUNTIME DESTINATION bin) +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/mrbc/Makefile b/tools/mrbc/Makefile new file mode 100644 index 000000000..9ecda4a59 --- /dev/null +++ b/tools/mrbc/Makefile @@ -0,0 +1,67 @@ +# makefile discription. +# basic build file for mruby-compiler + +# project-specific macros +# extension of the executable-file is modifiable(.exe .out ...) +BASEDIR := ../../src +TARGET := ../../bin/mrbc +LIBR := ../../lib/libmruby_core.a +ifeq ($(OS),Windows_NT) +EXE := $(TARGET).exe +else +EXE := $(TARGET) +endif +EXCEPT1 := +OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mrbc/*.c)) +#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 := $(OBJ0) + +# libraries, includes +LIBS = -lm +INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include + +# compiler, linker (gcc) +CC = gcc +LL = gcc +YACC = bison +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g -O3 +else +CFLAGS = -O3 +endif +ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) +ifeq ($(OS),Windows_NT) + MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" +else + MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' +endif + +############################## +# generic build targets, rules + +.PHONY : all +all : $(EXE) + +# executable constructed using linker from object files +$(EXE) : $(OBJS) $(LIBR) + $(LL) -o $@ $(OBJS) $(LIBR) $(LIBS) + +-include $(OBJS:.o=.d) + +# objects compiled from source +$(OBJS) : %.o : %.c + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ + +# C library compile +$(LIBR) : + @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) + +# clean up +.PHONY : clean +clean : + @echo "make: removing targets, objects and depend files of `pwd`" + -rm -f $(EXE) $(OBJS) + -rm -f $(OBJS:.o=.d) diff --git a/tools/mrbc/Makefile.orig b/tools/mrbc/Makefile.orig deleted file mode 100644 index 9ecda4a59..000000000 --- a/tools/mrbc/Makefile.orig +++ /dev/null @@ -1,67 +0,0 @@ -# makefile discription. -# basic build file for mruby-compiler - -# project-specific macros -# extension of the executable-file is modifiable(.exe .out ...) -BASEDIR := ../../src -TARGET := ../../bin/mrbc -LIBR := ../../lib/libmruby_core.a -ifeq ($(OS),Windows_NT) -EXE := $(TARGET).exe -else -EXE := $(TARGET) -endif -EXCEPT1 := -OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mrbc/*.c)) -#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 := $(OBJ0) - -# libraries, includes -LIBS = -lm -INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include - -# compiler, linker (gcc) -CC = gcc -LL = gcc -YACC = bison -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 -endif -ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) -ifeq ($(OS),Windows_NT) - MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -else - MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif - -############################## -# generic build targets, rules - -.PHONY : all -all : $(EXE) - -# executable constructed using linker from object files -$(EXE) : $(OBJS) $(LIBR) - $(LL) -o $@ $(OBJS) $(LIBR) $(LIBS) - --include $(OBJS:.o=.d) - -# objects compiled from source -$(OBJS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# C library compile -$(LIBR) : - @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) - -# clean up -.PHONY : clean -clean : - @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(EXE) $(OBJS) - -rm -f $(OBJS:.o=.d) diff --git a/tools/mruby/CMakeLists.txt b/tools/mruby/CMakeLists.txt index ab0e3acc1..beff6280d 100644 --- a/tools/mruby/CMakeLists.txt +++ b/tools/mruby/CMakeLists.txt @@ -1,7 +1,9 @@ -# builds tools/mrbc +# build tools/mruby executable + file(GLOB MRUBYBIN_SRC_C "*.c") add_executable(mruby ${MRUBYBIN_SRC_C}) -target_link_libraries(mruby mrubylib_static ${MRUBY_LIBS}) -install(TARGETS mruby RUNTIME DESTINATION bin) +target_link_libraries(mruby libmruby_static ${MRUBY_LIBS}) +install(TARGETS mruby RUNTIME DESTINATION bin) +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/mruby/Makefile b/tools/mruby/Makefile new file mode 100644 index 000000000..052aa93d6 --- /dev/null +++ b/tools/mruby/Makefile @@ -0,0 +1,77 @@ +# makefile discription. +# basic build file for mruby executable + +# project-specific macros +# extension of the executable-file is modifiable(.exe .out ...) +BASEDIR = ../../src +TARGET := ../../bin/mruby +LIBR := ../../lib/libmruby.a +ifeq ($(OS),Windows_NT) +EXE := $(TARGET).exe +else +EXE := $(TARGET) +endif +OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mruby/*.c)) +#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 := $(OBJ0) + +# ext libraries +#EXT1 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../ext/socket/*.c)) +EXTS := $(EXT1) + +# libraries, includes +LIBS = -lm +INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include + +# compiler, linker (gcc) +CC = gcc +LL = gcc +YACC = bison +DEBUG_MODE = 1 +ifeq ($(DEBUG_MODE),1) +CFLAGS = -g -O3 +else +CFLAGS = -O3 +endif +ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) +ifeq ($(OS),Windows_NT) + MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" +else + MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' +endif + +############################## +# generic build targets, rules + +.PHONY : all +all : $(LIBR) $(EXE) + +# executable constructed using linker from object files +$(EXE) : $(LIBR) $(OBJS) $(EXTS) + $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(EXTS) $(LIBS) + +-include $(OBJS:.o=.d) + +# objects compiled from source +$(OBJS) : %.o : %.c + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ + +# C library compile +$(LIBR) : + @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) + +# mruby library compile +# extend libraries complile +$(EXTS) : %.o : %.c + $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ + +# clean up +.PHONY : clean #cleandep +clean : + $(MAKE) clean -C ../../mrblib $(MAKE_FLAGS) + $(MAKE) clean -C ../mrbc $(MAKE_FLAGS) + @echo "make: removing targets, objects and depend files of `pwd`" + -rm -f $(EXE) $(OBJS) + -rm -f $(OBJS:.o=.d) diff --git a/tools/mruby/Makefile.orig b/tools/mruby/Makefile.orig deleted file mode 100644 index 052aa93d6..000000000 --- a/tools/mruby/Makefile.orig +++ /dev/null @@ -1,77 +0,0 @@ -# makefile discription. -# basic build file for mruby executable - -# project-specific macros -# extension of the executable-file is modifiable(.exe .out ...) -BASEDIR = ../../src -TARGET := ../../bin/mruby -LIBR := ../../lib/libmruby.a -ifeq ($(OS),Windows_NT) -EXE := $(TARGET).exe -else -EXE := $(TARGET) -endif -OBJ0 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../tools/mruby/*.c)) -#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 := $(OBJ0) - -# ext libraries -#EXT1 := $(patsubst %.c,%.o,$(wildcard $(BASEDIR)/../ext/socket/*.c)) -EXTS := $(EXT1) - -# libraries, includes -LIBS = -lm -INCLUDES = -I$(BASEDIR) -I$(BASEDIR)/../include - -# compiler, linker (gcc) -CC = gcc -LL = gcc -YACC = bison -DEBUG_MODE = 1 -ifeq ($(DEBUG_MODE),1) -CFLAGS = -g -O3 -else -CFLAGS = -O3 -endif -ALL_CFLAGS = -Wall -Werror-implicit-function-declaration $(CFLAGS) -ifeq ($(OS),Windows_NT) - MAKE_FLAGS = CC=$(CC) LL=$(LL) ALL_CFLAGS="$(ALL_CFLAGS)" -else - MAKE_FLAGS = CC='$(CC)' LL='$(LL)' ALL_CFLAGS='$(ALL_CFLAGS)' -endif - -############################## -# generic build targets, rules - -.PHONY : all -all : $(LIBR) $(EXE) - -# executable constructed using linker from object files -$(EXE) : $(LIBR) $(OBJS) $(EXTS) - $(LL) -o $@ $(CFLAGS) $(OBJS) $(LIBR) $(EXTS) $(LIBS) - --include $(OBJS:.o=.d) - -# objects compiled from source -$(OBJS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# C library compile -$(LIBR) : - @$(MAKE) -C $(BASEDIR) $(MAKE_FLAGS) - -# mruby library compile -# extend libraries complile -$(EXTS) : %.o : %.c - $(CC) $(ALL_CFLAGS) -MMD $(INCLUDES) -c $< -o $@ - -# clean up -.PHONY : clean #cleandep -clean : - $(MAKE) clean -C ../../mrblib $(MAKE_FLAGS) - $(MAKE) clean -C ../mrbc $(MAKE_FLAGS) - @echo "make: removing targets, objects and depend files of `pwd`" - -rm -f $(EXE) $(OBJS) - -rm -f $(OBJS:.o=.d) diff --git a/tools/xpcat/CMakeLists.txt b/tools/xpcat/CMakeLists.txt new file mode 100644 index 000000000..bb4d326f5 --- /dev/null +++ b/tools/xpcat/CMakeLists.txt @@ -0,0 +1,5 @@ +# build tools/xpcat internal executable + +add_executable(xpcat xpcat.c) + +# vim: ts=2 sts=2 sw=2 et diff --git a/tools/xpcat/xpcat.c b/tools/xpcat/xpcat.c new file mode 100644 index 000000000..c9d1abe73 --- /dev/null +++ b/tools/xpcat/xpcat.c @@ -0,0 +1,69 @@ +#include +#include +#include + +static void +usage(const char *program) +{ + printf("Usage: %s -o outputfile FILE...\n", program); +} + +int +main(int argc, char *argv[]) +{ + int i, ch; + const char *output = NULL; + FILE *infile = NULL; + FILE *outfile = NULL; + + if (argc < 4) { + usage(argv[0]); + return EXIT_FAILURE; + } + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-o") == 0) { + i++; + if (i < argc) + output = argv[i]; + else + return EXIT_FAILURE; + } + } + + if (output) { + outfile = fopen(output, "wb"); + if (!outfile) { + fprintf(stderr, "[ERROR] unable to open output file: %s\n", output); + return EXIT_FAILURE; + } + setbuf(outfile, NULL); + + for (i = 1; i < argc; i++) { + if (strcmp(argv[i], "-o") == 0) { i++; continue; } + + infile = fopen(argv[i], "rb"); + if (!infile) { + fprintf(stderr, "[ERROR] unable to open input file: %s\n", argv[i]); + return EXIT_FAILURE; + } + setbuf(infile, NULL); + + while ((ch = getc(infile)) != EOF) { + if (putc(ch, outfile) == EOF) { + fprintf(stderr, "[ERROR] error writing output file: %s\n", output); + return EXIT_FAILURE; + } + } + + fclose(infile); + } + } + +done: + fclose(outfile); + + return EXIT_SUCCESS; +} + +/* vim: set ts=2 sts=2 sw=2 et: */ -- cgit v1.2.3