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 --- 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 +++++++++++++++++++++++++++++++++++++++++ 10 files changed, 245 insertions(+), 150 deletions(-) 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 (limited to 'tools') 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