diff --git a/.gitignore b/.gitignore index 51f1d410..a2b1c37c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,6 @@ -bin/* +build/* src/lex.yy.c src/lex.yy.h -src/y.tab.c -src/y.tab.h -lib/* .dir-locals.el GPATH GRTAGS diff --git a/.travis.yml b/.travis.yml index 8d0bd1c2..b101d255 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: c compiler: - gcc - clang +before_script: + - cd build script: - - make && make no-act - - make debug && make no-act + - cmake .. && make && make no-act + - cmake -DCMAKE_BUILD_TYPE=Debug .. && make && make no-act diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..4090ea75 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,38 @@ +cmake_minimum_required(VERSION 2.8) + +project(picrin) + +# git submodule update --init +execute_process( + COMMAND ${GIT_EXECUTABLE} submodule update --init + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + ) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) +set(CMAKE_C_FLAGS "-Wall -Wextra -std=c99") +set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=1") + +# external libraries +add_library(xfile SHARED extlib/xfile/xfile.c) + +# build picrin +include_directories(include extlib) +include(src/CMakeLists.txt) +include(tools/CMakeLists.txt) + +# copy runtime files +file(COPY piclib DESTINATION .) +file(COPY etc DESTINATION .) + +# $ make run +add_custom_target(run bin/picrin DEPENDS repl) + +# $ make no-act +add_custom_target(no-act bin/picrin -e '' > /dev/null DEPENDS repl) + +# $ make tak +add_custom_target(tak bin/picrin etc/tak.scm DEPENDS repl) + +# $ make lines +add_custom_target(lines find . -name "*.[chyl]" | xargs wc -l WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}) diff --git a/Makefile b/Makefile deleted file mode 100644 index fc555f7d..00000000 --- a/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -CFLAGS=-Wall -Wextra -std=c99 - -ifeq ($(findstring CYGWIN,$(shell uname -s)), CYGWIN) - XFILE_LIB=cygxfile.dll - PICRIN_LIB=cygpicrin.dll -else - XFILE_LIB=libxfile.so - PICRIN_LIB=libpicrin.so -endif - -all: deps release - -deps: - git submodule update --init - $(CC) $(CFLAGS) -shared -fPIC extlib/xfile/*.c -o lib/$(XFILE_LIB) -I./extlib/xfile - -release: CFLAGS += -DDEBUG=0 -O3 -release: build - -debug: CFLAGS += -g -DDEBUG=1 -O0 -debug: build - -build: build-lib build-main - -build-main: - $(CC) $(CFLAGS) -D_GNU_SOURCE -Wl,-rpath lib tools/main.c -o bin/picrin -I./include -I./extlib -L./lib -lreadline -lm -lxfile -lpicrin - -build-lib: - cd src; \ - flex scan.l - $(CC) $(CFLAGS) -shared -fPIC src/*.c -o lib/$(PICRIN_LIB) -I./include -I./extlib -L./lib -lm -lxfile - -clean: - rm -f src/lex.yy.c src/lex.yy.h - rm -f lib/$(PICRIN_LIB) - rm -f bin/picrin - -run: - bin/picrin - -tak: release - bin/picrin etc/tak.scm - -lines: clean - wc -l `find . -name "*.[chyl]"` - -no-act: - bin/picrin -e '' > /dev/null diff --git a/README.md b/README.md index 110685ba..9974c5bb 100644 --- a/README.md +++ b/README.md @@ -126,13 +126,22 @@ https://github.com/wasabiz/picrin ## How to use it +- make `Makefile` + + Change directory to `build` then run `cmake` to create Makefile. Once `Makefile` is generated you can run `make` command to build picrin. + + $ cd build + $ cmake .. + + Of course you don't need to move to `build` directory before running `cmake` (in that case `$ cmake .`), but I strongly recommend to follow above instruction. + - build - A built executable binary will be under bin/ directory and a shared library `libpicrin.so` under lib/. - - $ make + A built executable binary will be under bin/ directory and shared libraries under lib/. - If you want to build picrin on other systems than x86_64, make sure PIC_NAN_BOXING flag is turned off (see include/config.h for detail). + $ make + + If you are building picrin on other systems than x86_64, PIC_NAN_BOXING flag is automatically turned on (see include/config.h for detail). - run @@ -140,15 +149,15 @@ https://github.com/wasabiz/picrin $ make run -- debug-run +- debug - When `make` command is called with an argument `debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG). + If you execute `cmake` with debug flag `-DCMAKE_BUILD_TYPE=Debug`, it builds the binary with all debug flags enabled (PIC_GC_STRESS, VM_DEBUG, DEBUG). - $ make debug + $ cmake -DCMAKE_BUILD_TYPE=Debug .. - install - As of now picrin does not provide a command automatically installs the binary. If you want to place picrin library and binary in a parmanent directory, please do it by hand. + As of this writing picrin does not provide a command automatically installs the binary. If you want to place picrin library and binary in a parmanent directory, please do it by hand. (TODO) ## Requirement @@ -157,7 +166,7 @@ picrin scheme depends on some external libraries to build the binary: - lex (preferably, flex) - readline (optional) -The compilation is tested only on Mac OSX. I think (or hope) it'll be ok to compile and run on other operating systems such as Linux or Windows, but there's no guarantee :( +The compilation is tested only on Mac OSX and Ubuntu. I think (or hope) it'll be ok to compile and run on other operating systems such as Arch or Windows, but I don't guarantee :( ## Authors diff --git a/bin/.gitkeep b/build/.gitkeep similarity index 100% rename from bin/.gitkeep rename to build/.gitkeep diff --git a/lib/.gitkeep b/lib/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..e80d7cc3 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +find_package(FLEX REQUIRED) +flex_target(scan src/scan.l ${PROJECT_SOURCE_DIR}/src/lex.yy.c COMPILE_FLAGS --header-file="src/lex.yy.h") + +add_library(picrin SHARED + src/blob.c src/bool.c src/char.c src/codegen.c src/cont.c src/error.c + src/file.c src/gc.c src/init.c src/lib.c src/load.c src/macro.c + src/number.c src/pair.c src/port.c src/proc.c src/read.c src/state.c + src/string.c src/symbol.c src/system.c src/time.c src/var.c src/vector.c + src/vm.c src/write.c ${PROJECT_SOURCE_DIR}/src/lex.yy.c) +target_link_libraries(picrin m xfile) diff --git a/src/scan.l b/src/scan.l index 8c4cd5c5..055aff98 100644 --- a/src/scan.l +++ b/src/scan.l @@ -29,7 +29,6 @@ %option noyywrap %option extra-type="struct parser_control *" -%option header-file="lex.yy.h" %option never-interactive /* comment */ diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt new file mode 100644 index 00000000..97619e93 --- /dev/null +++ b/tools/CMakeLists.txt @@ -0,0 +1,3 @@ +add_executable(repl tools/main.c) +set_target_properties(repl PROPERTIES OUTPUT_NAME picrin) +target_link_libraries(repl picrin readline) diff --git a/tools/main.c b/tools/main.c index a522915e..a50f2cf6 100644 --- a/tools/main.c +++ b/tools/main.c @@ -5,7 +5,7 @@ #include #include #include -#include +#include #include "picrin.h" #include "picrin/pair.h"