From e30529d62922a61b4c9f59501c12a8c2880b1dc9 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 01:52:41 +0900 Subject: [PATCH 01/18] Add experimental cmake support --- .gitignore | 5 ++--- CMakeLists.txt | 15 +++++++++++++++ src/CMakeLists.txt | 10 ++++++++++ tools/CMakeLists.txt | 3 +++ 4 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 src/CMakeLists.txt create mode 100644 tools/CMakeLists.txt diff --git a/.gitignore b/.gitignore index 51f1d410..4013f2fc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,8 @@ bin/* +lib/* +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/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..fda3f8ae --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8) + +project(picrin) + +set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) +set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) + +# external libraries +add_library(xfile SHARED extlib/xfile/xfile.c) + +# build picrin +include_directories(include extlib) +link_directories(${PROJECT_SOURCE_DIR}/lib) +include(src/CMakeLists.txt) +include(tools/CMakeLists.txt) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..03910910 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,10 @@ +find_package(FLEX REQUIRED) +execute_process(COMMAND flex scan.l WORKING_DIRECTORY src) + +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/lex.yy.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) +target_link_libraries(picrin m xfile) 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) From dc7a7be22b4f5c6582c76a640f0ac6ab5134306e Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 02:26:08 +0900 Subject: [PATCH 02/18] add c99 flag in CMakeLists.txt --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index fda3f8ae..ed4dec1e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,7 @@ project(picrin) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) +set(CMAKE_C_FLAGS "-std=c99") # external libraries add_library(xfile SHARED extlib/xfile/xfile.c) From 249f2e40df8d26750625cc51f0bf39978831c107 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 02:39:50 +0900 Subject: [PATCH 03/18] copy piclib to build dir --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ed4dec1e..37c50724 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,3 +14,6 @@ include_directories(include extlib) link_directories(${PROJECT_SOURCE_DIR}/lib) include(src/CMakeLists.txt) include(tools/CMakeLists.txt) + +# copy runtime files +file(COPY piclib DESTINATION .) From 87d9adb0e48d9ca940abcc29ba78c6b75e8e3316 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 02:40:04 +0900 Subject: [PATCH 04/18] add make run target --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 37c50724..2c4dfd86 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,3 +17,6 @@ include(tools/CMakeLists.txt) # copy runtime files file(COPY piclib DESTINATION .) + +# $ make run +add_custom_target(run bin/picrin DEPENDS repl) From 02abde090f62727dfdbff265560e124ee30e1166 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:07:16 +0900 Subject: [PATCH 05/18] execute submodule update before doing anything --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2c4dfd86..44d8a65e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,12 @@ 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 "-std=c99") @@ -11,7 +17,6 @@ add_library(xfile SHARED extlib/xfile/xfile.c) # build picrin include_directories(include extlib) -link_directories(${PROJECT_SOURCE_DIR}/lib) include(src/CMakeLists.txt) include(tools/CMakeLists.txt) From a6ce873b6152755a72ad3618b78a324463ea5a4c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:23:36 +0900 Subject: [PATCH 06/18] add additional make targets --- CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 44d8a65e..1ed59c29 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,6 +22,16 @@ 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}) From 4a8bacd12c2e932e8246b7763c77bfc005dc9cdd Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:29:23 +0900 Subject: [PATCH 07/18] enable debug flag in debug build mode --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ed59c29..ba507c2d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,6 +11,7 @@ execute_process( set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) set(CMAKE_C_FLAGS "-std=c99") +set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=1") # external libraries add_library(xfile SHARED extlib/xfile/xfile.c) From 0805d421f55163af6b6bfaf6944854b68b1dbabf Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:32:59 +0900 Subject: [PATCH 08/18] enable -Wall and -Wextra --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ba507c2d..4090ea75 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ execute_process( set(CMAKE_RUNTIME_OUTPUT_DIRECTORY bin) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY lib) -set(CMAKE_C_FLAGS "-std=c99") +set(CMAKE_C_FLAGS "-Wall -Wextra -std=c99") set(CMAKE_C_FLAGS_DEBUG "-DDEBUG=1") # external libraries From 5441cf75f92f61e1f972d6cd4c3fa11a01eeaf5c Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:54:27 +0900 Subject: [PATCH 09/18] remove old Make stuff --- Makefile | 48 ------------------------------------------------ bin/.gitkeep | 0 lib/.gitkeep | 0 3 files changed, 48 deletions(-) delete mode 100644 Makefile delete mode 100644 bin/.gitkeep delete mode 100644 lib/.gitkeep 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/bin/.gitkeep b/bin/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/.gitkeep b/lib/.gitkeep deleted file mode 100644 index e69de29b..00000000 From 3bba2f1811a0777365bac61ecfa3178288482aea Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:54:37 +0900 Subject: [PATCH 10/18] update build instruction --- README.md | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) 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 From c6728b3cd86dc21e8d3f4b22f9bcdd2e23f30dc0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:56:52 +0900 Subject: [PATCH 11/18] update travis config --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8d0bd1c2..cbc452d9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,5 +3,5 @@ compiler: - gcc - clang script: - - make && make no-act - - make debug && make no-act + - cd build && cmake .. && make && make no-act + - cd build && cmake -DCMAKE_BULD_TYPE=Debug .. && make && make no-act From 110b9edf3e4f74fc271af3941620bbc8764b8175 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:58:56 +0900 Subject: [PATCH 12/18] add build dir --- build/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 build/.gitkeep diff --git a/build/.gitkeep b/build/.gitkeep new file mode 100644 index 00000000..e69de29b From eb7fe03155901431ef62d989bd98b6c65fe6fa58 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 12:59:12 +0900 Subject: [PATCH 13/18] update gitignore --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 4013f2fc..a2b1c37c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,3 @@ -bin/* -lib/* build/* src/lex.yy.c src/lex.yy.h From d77035a53706ac3502164c788f06080369e49578 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 13:21:26 +0900 Subject: [PATCH 14/18] fix flex problem --- src/CMakeLists.txt | 6 +++--- src/scan.l | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 03910910..34bc1a93 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,10 @@ find_package(FLEX REQUIRED) -execute_process(COMMAND flex scan.l WORKING_DIRECTORY src) +flex_target(scan src/scan.l 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/lex.yy.c src/lib.c src/load.c src/macro.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) + 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 */ From e4d4c51e786a3935bbc2584ce42bf37e6c5d85bf Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 13:24:12 +0900 Subject: [PATCH 15/18] use absolute path for flex output --- src/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 34bc1a93..e80d7cc3 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ find_package(FLEX REQUIRED) -flex_target(scan src/scan.l src/lex.yy.c COMPILE_FLAGS --header-file="src/lex.yy.h") +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 From 5475344bed71fd5aeddc80777723b8f5c321e0e5 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 13:32:56 +0900 Subject: [PATCH 16/18] avoid double cd in travis --- .travis.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cbc452d9..2d745f73 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,8 @@ language: c compiler: - gcc - clang +before_script: + - cd build script: - - cd build && cmake .. && make && make no-act - - cd build && cmake -DCMAKE_BULD_TYPE=Debug .. && make && make no-act + - cmake .. && make && make no-act + - cmake -DCMAKE_BULD_TYPE=Debug .. && make && make no-act From 40b6635a2f2ad7f581ebec86f9e59b000db0c2f0 Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 13:33:12 +0900 Subject: [PATCH 17/18] explicitly include getopt.h --- tools/main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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" From bc544de6aa441014c19f52125d3c1a5906e8931a Mon Sep 17 00:00:00 2001 From: Yuichi Nishiwaki Date: Sun, 2 Mar 2014 13:34:46 +0900 Subject: [PATCH 18/18] fix typo in travis.yml --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 2d745f73..b101d255 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,4 +6,4 @@ before_script: - cd build script: - cmake .. && make && make no-act - - cmake -DCMAKE_BULD_TYPE=Debug .. && make && make no-act + - cmake -DCMAKE_BUILD_TYPE=Debug .. && make && make no-act