diff options
author | yuta.256 <yuta.256@b7c3aa3b-274f-0410-ae0b-edc9d07c929d> | 2008-07-03 11:34:07 +0000 |
---|---|---|
committer | yuta.256 <yuta.256@b7c3aa3b-274f-0410-ae0b-edc9d07c929d> | 2008-07-03 11:34:07 +0000 |
commit | 0b0d08bc414f9152b0f7afac36b56b4b30e2679f (patch) | |
tree | e16f192f3e8cfab1a5443b6b62cbd4711fba965b | |
parent | 176b6c50446b4f7ae1e284ae2287f8b1c62811fd (diff) | |
download | libdivsufsort-0b0d08bc414f9152b0f7afac36b56b4b30e2679f.tar.gz |
The build system was changed to CMake. (http://www.cmake.org/)
-rw-r--r-- | CMakeLists.txt | 79 | ||||
-rw-r--r-- | CMakeModules/AppendCompilerFlags.cmake | 38 | ||||
-rw-r--r-- | CMakeModules/CheckFunctionKeywords.cmake | 15 | ||||
-rw-r--r-- | CMakeModules/cmake_uninstall.cmake.in | 36 | ||||
-rw-r--r-- | INSTALL | 54 | ||||
-rw-r--r-- | Makefile.am | 5 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | VERSION | 1 | ||||
-rw-r--r-- | configure.ac | 72 | ||||
-rw-r--r-- | examples/CMakeLists.txt | 11 | ||||
-rw-r--r-- | examples/Makefile.am | 6 | ||||
-rw-r--r-- | examples/sasearch.c | 6 | ||||
-rw-r--r-- | include/CMakeLists.txt | 101 | ||||
-rw-r--r-- | include/Makefile.am | 4 | ||||
-rw-r--r-- | include/config.h.cmake | 57 | ||||
-rw-r--r-- | include/divsufsort.h.cmake (renamed from include/divsufsort.h.in) | 56 | ||||
-rw-r--r-- | include/divsufsort_private.h (renamed from include/divsufsort_private.h.in) | 16 | ||||
-rw-r--r-- | lib/CMakeLists.txt | 14 | ||||
-rw-r--r-- | lib/Makefile.am | 9 | ||||
-rw-r--r-- | lib/divsufsort.c | 2 | ||||
-rw-r--r-- | lib/libdivsufsort.sym | 8 | ||||
-rw-r--r-- | lib/substringsort.c | 16 | ||||
-rw-r--r-- | lib/trsort.c | 10 |
23 files changed, 431 insertions, 187 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..142c4bc --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,79 @@ +### cmake file for building sais Package ### +cmake_minimum_required(VERSION 2.4.2) +set(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules") +include(AppendCompilerFlags) + +## SVN revision ## +set(SVN_REVISION "") +if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn") + execute_process(COMMAND svn info --xml + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + OUTPUT_VARIABLE SVN_INFO ERROR_QUIET) + if(SVN_INFO) + string(REGEX MATCH "<entry[^>]+" SVN_REVISION "${SVN_INFO}") + string(REGEX REPLACE "^.*revision=\"([0-9]+)\".*$" "\\1" SVN_REVISION "${SVN_REVISION}") + endif(SVN_INFO) +endif(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/.svn") + +## Project information ## +project(libdivsufsort C) +file(READ "${CMAKE_CURRENT_SOURCE_DIR}/VERSION" PROJECT_VERSION_FULL) +string(REGEX REPLACE "[\n\r]" "" PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}") +string(REGEX REPLACE "^([0-9]+)\\.[0-9]+\\.[0-9]+$" "\\1" PROJECT_VERSION_MAJOR "${PROJECT_VERSION_FULL}") +string(REGEX REPLACE "^[0-9]+\\.([0-9]+)\\.[0-9]+$" "\\1" PROJECT_VERSION_MINOR "${PROJECT_VERSION_FULL}") +string(REGEX REPLACE "^[0-9]+\\.[0-9]+\\.([0-9]+)$" "\\1" PROJECT_VERSION_PATCH "${PROJECT_VERSION_FULL}") +set(PROJECT_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") +math(EXPR LIBRARY_VERSION_MAJOR "1 + ${PROJECT_VERSION_MAJOR}") +set(LIBRARY_VERSION_MINOR "${PROJECT_VERSION_MINOR}") +set(LIBRARY_VERSION_PATCH "${PROJECT_VERSION_PATCH}") +set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}") +set(LIBRARY_VERSION_FULL "${LIBRARY_VERSION}.${LIBRARY_VERSION_PATCH}") +if(SVN_REVISION) + set(PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}-svn-r${SVN_REVISION}") +endif(SVN_REVISION) + +## Project options ## +option(BUILD_SHARED_LIBS "Set to OFF to build static libraries" ON) +option(BUILD_EXAMPLES "Build examples" ON) + +## Build type ## +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "Release") +elseif(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_VERBOSE_MAKEFILE ON) +endif(NOT CMAKE_BUILD_TYPE) + +## Compiler options ## +if(MSVC) + append_c_compiler_flags("/W4" "VC" CMAKE_C_FLAGS) + append_c_compiler_flags("/Oi;/Ot;/Ox;/Oy" "VC" CMAKE_C_FLAGS_RELEASE) +elseif(BORLAND) + append_c_compiler_flags("-w" "BCC" CMAKE_C_FLAGS) + append_c_compiler_flags("-Oi;-Og;-Os;-Ov;-Ox" "BCC" CMAKE_C_FLAGS_RELEASE) +else(MSVC) + if(CMAKE_COMPILER_IS_GNUCC) + append_c_compiler_flags("-Wall" "GCC" CMAKE_C_FLAGS) + append_c_compiler_flags("-fomit-frame-pointer" "GCC" CMAKE_C_FLAGS_RELEASE) + else(CMAKE_COMPILER_IS_GNUCC) + append_c_compiler_flags("-Wall" "UNKNOWN" CMAKE_C_FLAGS) + append_c_compiler_flags("-fomit-frame-pointer" "UNKNOWN" CMAKE_C_FLAGS_RELEASE) + endif(CMAKE_COMPILER_IS_GNUCC) +endif(MSVC) + +## Add definitions ## +add_definitions(-DHAVE_CONFIG_H=1 -D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS) + +## Add subdirectories ## +add_subdirectory(include) +add_subdirectory(lib) +if(BUILD_EXAMPLES) + add_subdirectory(examples) +endif(BUILD_EXAMPLES) + +## Add 'uninstall' target ## +CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake" + IMMEDIATE @ONLY) +ADD_CUSTOM_TARGET(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/CMakeModules/cmake_uninstall.cmake") diff --git a/CMakeModules/AppendCompilerFlags.cmake b/CMakeModules/AppendCompilerFlags.cmake new file mode 100644 index 0000000..58d3f99 --- /dev/null +++ b/CMakeModules/AppendCompilerFlags.cmake @@ -0,0 +1,38 @@ +include(CheckCSourceCompiles) +include(CheckCXXSourceCompiles) + +macro(append_c_compiler_flags _flags _name _result) + set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}") + string(TOUPPER "${cname}" cname) + foreach(flag ${_flags}) + string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}") + string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}") + string(TOUPPER "${flagname}" flagname) + set(have_flag "HAVE_${cname}_${flagname}") + set(CMAKE_REQUIRED_FLAGS "${flag}") + check_c_source_compiles("int main() { return 0; }" ${have_flag}) + if(${have_flag}) + set(${_result} "${${_result}} ${flag}") + endif(${have_flag}) + endforeach(flag) + set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS}) +endmacro(append_c_compiler_flags) + +macro(append_cxx_compiler_flags _flags _name _result) + set(SAFE_CMAKE_REQUIRED_FLAGS ${CMAKE_REQUIRED_FLAGS}) + string(REGEX REPLACE "[-+/ ]" "_" cname "${_name}") + string(TOUPPER "${cname}" cname) + foreach(flag ${_flags}) + string(REGEX REPLACE "^[-+/ ]+(.*)[-+/ ]*$" "\\1" flagname "${flag}") + string(REGEX REPLACE "[-+/ ]" "_" flagname "${flagname}") + string(TOUPPER "${flagname}" flagname) + set(have_flag "HAVE_${cname}_${flagname}") + set(CMAKE_REQUIRED_FLAGS "${flag}") + check_cxx_source_compiles("int main() { return 0; }" ${have_flag}) + if(${have_flag}) + set(${_result} "${${_result}} ${flag}") + endif(${have_flag}) + endforeach(flag) + set(CMAKE_REQUIRED_FLAGS ${SAFE_CMAKE_REQUIRED_FLAGS}) +endmacro(append_cxx_compiler_flags) diff --git a/CMakeModules/CheckFunctionKeywords.cmake b/CMakeModules/CheckFunctionKeywords.cmake new file mode 100644 index 0000000..44601fd --- /dev/null +++ b/CMakeModules/CheckFunctionKeywords.cmake @@ -0,0 +1,15 @@ +include(CheckCSourceCompiles) + +macro(check_function_keywords _wordlist) + set(${_result} "") + foreach(flag ${_wordlist}) + string(REGEX REPLACE "[-+/ ()]" "_" flagname "${flag}") + string(TOUPPER "${flagname}" flagname) + set(have_flag "HAVE_${flagname}") + check_c_source_compiles("${flag} void func(); void func() { } int main() { func(); return 0; }" ${have_flag}) + if(${have_flag} AND NOT ${_result}) + set(${_result} "${flag}") +# break() + endif(${have_flag} AND NOT ${_result}) + endforeach(flag) +endmacro(check_function_keywords) diff --git a/CMakeModules/cmake_uninstall.cmake.in b/CMakeModules/cmake_uninstall.cmake.in new file mode 100644 index 0000000..8366a83 --- /dev/null +++ b/CMakeModules/cmake_uninstall.cmake.in @@ -0,0 +1,36 @@ +IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +ENDIF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + +FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +STRING(REGEX REPLACE "\n" ";" files "${files}") + +SET(NUM 0) +FOREACH(file ${files}) + IF(EXISTS "$ENV{DESTDIR}${file}") + MESSAGE(STATUS "Looking for \"$ENV{DESTDIR}${file}\" - found") + SET(UNINSTALL_CHECK_${NUM} 1) + ELSE(EXISTS "$ENV{DESTDIR}${file}") + MESSAGE(STATUS "Looking for \"$ENV{DESTDIR}${file}\" - not found") + SET(UNINSTALL_CHECK_${NUM} 0) + ENDIF(EXISTS "$ENV{DESTDIR}${file}") + MATH(EXPR NUM "1 + ${NUM}") +ENDFOREACH(file) + +SET(NUM 0) +FOREACH(file ${files}) + IF(${UNINSTALL_CHECK_${NUM}}) + MESSAGE(STATUS "Uninstalling \"$ENV{DESTDIR}${file}\"") + EXEC_PROGRAM( + "@CMAKE_COMMAND@" ARGS "-E remove \"$ENV{DESTDIR}${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + IF(NOT "${rm_retval}" STREQUAL 0) + MESSAGE(FATAL_ERROR "Problem when removing \"$ENV{DESTDIR}${file}\"") + ENDIF(NOT "${rm_retval}" STREQUAL 0) + ENDIF(${UNINSTALL_CHECK_${NUM}}) + MATH(EXPR NUM "1 + ${NUM}") +ENDFOREACH(file) + +FILE(REMOVE "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") @@ -1,51 +1,31 @@ -- INSTALL for libdivsufsort -Compilation and Installation: ------------------------------ - The `configure' shell script attempts to guess correct values for -various system-dependent variables used during compilation. It uses -those values to create a `Makefile' in each directory in the -libdivsufsort source tree. Finally, it creates a shell script -`config.status' that you can run in the future to recreate the -current configuration, and a file `config.log' containing compiler -output (useful mainly for debugging `configure'). +Requirements: +============= - The file `configure.ac' is used to create `configure' by a program -called `autoconf'. You only need `configure.ac' if you want to change -it or regenerate `configure' using a newer version of `autoconf'. + * CMake version 2.4.2 or newer (http://www.cmake.org/) + * A C compiler + * Make -The simplest way to compile this package is: - 1. `cd' to the directory containing the package's source code and type - `./configure' to configure the package for your system. If you're - using `csh' on an old version of System V, you might need to type - `sh ./configure' instead to prevent `csh' from trying to execute - `configure' itself. +Compilation and Installation (with Unix Makefiles): +=================================================== - Running `configure' takes awhile. While running, it prints some - messages telling which features it is checking for. + 1. Create a 'build' directory in the package source directory. - 2. Type `make' to compile the package. + $ cd libdivsufsort-?.?.? + $ mkdir build + $ cd build - 3. Type `make install' to install the library and header files. + 2. Configure the package for your system. - 4. You can remove the program binaries and object files from the - source code directory by typing `make clean'. To also remove the - files that `configure' created (so you can compile the package for - a different kind of computer), type `make distclean'. + $ cmake -DCMAKE_BUILD_TYPE="Release" -DCMAKE_INSTALL_PREFIX="/usr/local" .. + 3. Compile the package. -Compilers and Options: ----------------------- + $ make - Some systems require unusual options for compilation or linking -that the `configure' script does not know about. You can give -`configure' initial values for configuration parameters by setting -variables in the command line or in the environment. Here -is an example: + 4. Install the library and header files. - ./configure CC=c89 CFLAGS=-O2 LIBS=-lposix - -Run `./configure --help' for details on some of the pertinent -environment variables. + # make install diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 99af5e2..0000000 --- a/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ -# Makefile.am for libdivsufsort - -SUBDIRS = include lib examples - -EXTRA_DIST = ChangeLog.old @@ -10,7 +10,7 @@ algorithm. For input size n, this algorithm runs in O(n log n) worst-case (and average) time using only 5n bytes of memory. The latest version of libdivsufsort is available at: - http://homepage3.nifty.com/wpage/software/libdivsufsort.html + http://libdivsufsort.googlecode.com/ License: @@ -0,0 +1 @@ +2.0.0 diff --git a/configure.ac b/configure.ac deleted file mode 100644 index cc85027..0000000 --- a/configure.ac +++ /dev/null @@ -1,72 +0,0 @@ -# configure.ac for libdivsufsort - -AC_PREREQ(2.59) - -AC_INIT([libdivsufsort], [1.2.3], [yuta.256@gmail.com]) -AC_CONFIG_SRCDIR([include/divsufsort.h.in]) -AC_CONFIG_HEADER([include/config.h]) -AC_CONFIG_AUX_DIR([config]) -AM_INIT_AUTOMAKE([-Wall -Werror foreign 1.9 no-define dist-bzip2]) - -# Library code modified: REVISION++ -# Interfaces changed/added/removed: CURRENT++ REVISION=0 -# Interfaces added: AGE++ -# Interfaces removed: AGE=0 -AC_SUBST(LT_CURRENT, 3) -AC_SUBST(LT_REVISION, 2) -AC_SUBST(LT_AGE, 1) - -# Checks for programs. -AC_PROG_CC -AC_PROG_INSTALL -AC_PROG_MAKE_SET - -# Check for host type. -AC_CANONICAL_HOST - -# Checks for compiler output filename suffixes. -AC_OBJEXT -AC_EXEEXT - -# Check for build configuration. -AM_DISABLE_STATIC -AC_LIBTOOL_WIN32_DLL -AC_PROG_LIBTOOL -case "$host_os" in - cygwin*) - AC_ARG_ENABLE(cygwin, AC_HELP_STRING([--disable-cygwin], [Don't use the CygWin libraries])) - if test "$enable_cygwin" != "no"; then - A_CFLAGS='' - else - A_CFLAGS='-mno-cygwin' - fi - LT_NOUNDEF='-no-undefined' - ;; - *) LT_NOUNDEF='' A_CFLAGS='' ;; -esac -AC_SUBST([LT_NOUNDEF]) -AC_SUBST([A_CFLAGS]) - -# Checks for libraries. - -# Checks for header files. -AC_HEADER_STDC -AC_CHECK_HEADERS([inttypes.h memory.h stddef.h stdint.h stdlib.h string.h strings.h]) -AC_CHECK_HEADER([inttypes.h], [AC_SUBST([_HAVE_INTTYPES_H_], [1])], [AC_SUBST([_HAVE_INTTYPES_H_], [0])]) -AC_CHECK_HEADER([stdint.h], [AC_SUBST([_HAVE_STDINT_H_], [1])], [AC_SUBST([_HAVE_STDINT_H_], [0])]) - -# Checks for typedefs, structures, and compiler characteristics. -AC_C_CONST -AC_C_INLINE - -# Checks for library functions. -AC_FUNC_MALLOC -AC_FUNC_STAT - -AC_CONFIG_FILES([Makefile - include/Makefile - include/divsufsort.h - include/divsufsort_private.h - lib/Makefile - examples/Makefile]) -AC_OUTPUT diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt new file mode 100644 index 0000000..e801c81 --- /dev/null +++ b/examples/CMakeLists.txt @@ -0,0 +1,11 @@ +## Add definitions ## +add_definitions(-D_LARGEFILE_SOURCE -D_LARGE_FILES -D_FILE_OFFSET_BITS=64) + +## Targets ## +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_BINARY_DIR}/../include") +link_directories("${CMAKE_CURRENT_BINARY_DIR}/../lib") +foreach(src suftest mksary sasearch bwt unbwt) + add_executable(${src} ${src}.c) + target_link_libraries(${src} divsufsort) +endforeach(src) diff --git a/examples/Makefile.am b/examples/Makefile.am deleted file mode 100644 index f098500..0000000 --- a/examples/Makefile.am +++ /dev/null @@ -1,6 +0,0 @@ -# Makefile.am for libdivsufsort - -noinst_PROGRAMS = suftest mksary sasearch bwt unbwt -LDADD = $(top_builddir)/lib/libdivsufsort.la - -AM_CFLAGS = @A_CFLAGS@ diff --git a/examples/sasearch.c b/examples/sasearch.c index 63a3932..bf8f7cc 100644 --- a/examples/sasearch.c +++ b/examples/sasearch.c @@ -230,6 +230,8 @@ int main(int argc, const char *argv[]) { int i; searchoption_t option; + sauchar_t *P; + saidx_t Psize; if(argc <= 1) { _print_usage(argv[0], EXIT_SUCCESS); } @@ -293,8 +295,8 @@ main(int argc, const char *argv[]) { if(i == argc) { return 0; } - sauchar_t *P = (sauchar_t *)argv[i]; - saidx_t Psize = (saidx_t)strlen(argv[i]); + P = (sauchar_t *)argv[i]; + Psize = (saidx_t)strlen(argv[i]); if(option.flags & SA_HEX_MODE) { sauchar_t *newP = malloc(Psize / 2 * sizeof(sauchar_t)); diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt new file mode 100644 index 0000000..3a4f2af --- /dev/null +++ b/include/CMakeLists.txt @@ -0,0 +1,101 @@ +include(CheckIncludeFiles) +include(CheckIncludeFile) +include(CheckSymbolExists) +include(CheckTypeSize) +include(CheckFunctionKeywords) + +## Checks for header files ## +check_include_file("inttypes.h" HAVE_INTTYPES_H) +check_include_file("memory.h" HAVE_MEMORY_H) +check_include_file("stddef.h" HAVE_STDDEF_H) +check_include_file("stdint.h" HAVE_STDINT_H) +check_include_file("stdlib.h" HAVE_STDLIB_H) +check_include_file("string.h" HAVE_STRING_H) +check_include_file("strings.h" HAVE_STRINGS_H) +check_include_file("sys/types.h" HAVE_SYS_TYPES_H) +check_include_file("sys/stat.h" HAVE_SYS_STAT_H) +if(HAVE_INTTYPES_H) + set(INCFILE "#include <inttypes.h>") +elseif(HAVE_STDINT_H) + set(INCFILE "#include <stdint.h>") +else(HAVE_INTTYPES_H) + set(INCFILE "") +endif(HAVE_INTTYPES_H) + +## create configuration files from .cmake file ## + +## generate config.h ## +check_function_keywords("inline;__inline;__inline__;__declspec(dllexport);__declspec(dllimport)") +if(HAVE_INLINE) + set(INLINE "inline") +elseif(HAVE___INLINE) + set(INLINE "__inline") +elseif(HAVE___INLINE__) + set(INLINE "__inline__") +else(HAVE_INLINE) + set(INLINE "") +endif(HAVE_INLINE) +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake" "${CMAKE_CURRENT_BINARY_DIR}/config.h") + +## Checks for types ## +# sauchar_t (8bit) +check_type_size("uint8_t" UINT8_T) +if(HAVE_UINT8_T) + set(SAUCHAR_TYPE "uint8_t") +else(HAVE_UINT8_T) + check_type_size("unsigned char" SIZEOF_UNSIGNED_CHAR) + if(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1") + set(SAUCHAR_TYPE "unsigned char") + else(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1") + message(FATAL_ERROR "Cannot find unsigned 8-bit integer type") + endif(${SIZEOF_UNSIGNED_CHAR} STREQUAL "1") +endif(HAVE_UINT8_T) +# saint_t (32bit) +check_type_size("int32_t" INT32_T) +if(HAVE_INT32_T) + set(SAINT32_TYPE "int32_t") + check_symbol_exists("PRId32" "inttypes.h" HAVE_PRID32) + if(HAVE_PRID32) + set(SAINT32_PRId "PRId32") + else(HAVE_PRID32) + set(SAINT32_PRId "\"d\"") + endif(HAVE_PRID32) +else(HAVE_INT32_T) + check_type_size("int" SIZEOF_INT) + check_type_size("long" SIZEOF_LONG) + check_type_size("short" SIZEOF_SHORT) + check_type_size("__int32" SIZEOF___INT32) + if(${SIZEOF_INT} STREQUAL "4") + set(SAINT32_TYPE "int") + set(SAINT32_PRId "\"d\"") + elseif(${SIZEOF_LONG} STREQUAL "4") + set(SAINT32_TYPE "long") + set(SAINT32_PRId "\"ld\"") + elseif(${SIZEOF_SHORT} STREQUAL "4") + set(SAINT32_TYPE "short") + set(SAINT32_PRId "\"d\"") + elseif(${SIZEOF___INT32} STREQUAL "4") + set(SAINT32_TYPE "__int32") + set(SAINT32_PRId "\"d\"") + else(${SIZEOF_INT} STREQUAL "4") + message(FATAL_ERROR "Cannot find 32-bit integer type") + endif(${SIZEOF_INT} STREQUAL "4") +endif(HAVE_INT32_T) + +## generate divsufsort.h ## +set(DIVSUFSORT_IMPORT "") +set(DIVSUFSORT_EXPORT "") +if(BUILD_SHARED_LIBS) + if(HAVE___DECLSPEC_DLLIMPORT_) + set(DIVSUFSORT_IMPORT "__declspec(dllimport)") + endif(HAVE___DECLSPEC_DLLIMPORT_) + if(HAVE___DECLSPEC_DLLEXPORT_) + set(DIVSUFSORT_EXPORT "__declspec(dllexport)") + endif(HAVE___DECLSPEC_DLLEXPORT_) +endif(BUILD_SHARED_LIBS) +set(SAINDEX_TYPE "${SAINT32_TYPE}") +set(SAINDEX_PRId "${SAINT32_PRId}") +set(SAINT_PRId "${SAINT32_PRId}") +configure_file("${CMAKE_CURRENT_SOURCE_DIR}/divsufsort.h.cmake" + "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" @ONLY) +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/divsufsort.h" DESTINATION include) diff --git a/include/Makefile.am b/include/Makefile.am deleted file mode 100644 index 3bd3b45..0000000 --- a/include/Makefile.am +++ /dev/null @@ -1,4 +0,0 @@ -# Makefile.am for libdivsufsort - -nodist_include_HEADERS = divsufsort.h -EXTRA_DIST = divsufsort_private.h.in divsufsort.h.in diff --git a/include/config.h.cmake b/include/config.h.cmake new file mode 100644 index 0000000..a2223da --- /dev/null +++ b/include/config.h.cmake @@ -0,0 +1,57 @@ +/* + * config.h for libdivsufsort + * Copyright (c) 2003-2008 Yuta Mori All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, + * copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following + * conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES + * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT + * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, + * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + * OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef _CONFIG_H +#define _CONFIG_H 1 + +#ifdef __cplusplus +extern "C" { +#endif /* __cplusplus */ + +/** Define to the version of this package. **/ +#cmakedefine PROJECT_VERSION_FULL "${PROJECT_VERSION_FULL}" + +/** Define to 1 if you have the header files. **/ +#cmakedefine HAVE_INTTYPES_H 1 +#cmakedefine HAVE_STDDEF_H 1 +#cmakedefine HAVE_STDINT_H 1 +#cmakedefine HAVE_STDLIB_H 1 +#cmakedefine HAVE_STRING_H 1 +#cmakedefine HAVE_STRINGS_H 1 +#cmakedefine HAVE_MEMORY_H 1 +#cmakedefine HAVE_SYS_TYPES_H 1 + +/** for inline **/ +#ifndef INLINE +# define INLINE @INLINE@ +#endif + + +#ifdef __cplusplus +} /* extern "C" */ +#endif /* __cplusplus */ + +#endif /* _CONFIG_H */ diff --git a/include/divsufsort.h.in b/include/divsufsort.h.cmake index 742880c..73feefe 100644 --- a/include/divsufsort.h.in +++ b/include/divsufsort.h.cmake @@ -24,36 +24,42 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _DIVSUFSORT_H_ -#define _DIVSUFSORT_H_ +#ifndef _DIVSUFSORT_H +#define _DIVSUFSORT_H 1 #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#if @_HAVE_INTTYPES_H_@ /* _HAVE_INTTYPES_H_ */ -# include <inttypes.h> -#else -# if @_HAVE_STDINT_H_@ /* _HAVE_STDINT_H_ */ -# include <stdint.h> -# else - -#ifndef _UINT8_T -#define _UINT8_T -typedef unsigned char uint8_t; -#endif /* _UINT8_T */ -#ifndef _INT32_T -#define _INT32_T -typedef int int32_t; -#endif /* _INT32_T */ +@INCFILE@ +#ifndef DIVSUFSORT_API +# ifdef DIVSUFSORT_BUILD_DLL +# define DIVSUFSORT_API @DIVSUFSORT_EXPORT@ +# else +# define DIVSUFSORT_API @DIVSUFSORT_IMPORT@ # endif #endif /*- Datatypes -*/ -typedef int32_t saint_t; -typedef int32_t saidx_t; -typedef uint8_t sauchar_t; +#ifndef SAUCHAR_T +#define SAUCHAR_T +typedef @SAUCHAR_TYPE@ sauchar_t; +#endif /* SAUCHAR_T */ +#ifndef SAINT_T +#define SAINT_T +typedef @SAINT32_TYPE@ saint_t; +#endif /* SAINT_T */ +#ifndef SAIDX_T +#define SAIDX_T +typedef @SAINDEX_TYPE@ saidx_t; +#endif /* SAIDX_T */ +#ifndef PRIdSAINT_T +#define PRIdSAINT_T @SAINT_PRId@ +#endif /* PRIdSAINT_T */ +#ifndef PRIdSAIDX_T +#define PRIdSAIDX_T @SAINDEX_PRId@ +#endif /* PRIdSAIDX_T */ /*- Prototypes -*/ @@ -65,6 +71,7 @@ typedef uint8_t sauchar_t; * @param n The length of the given string. * @return 0 if no error occurred, -1 or -2 otherwise. */ +DIVSUFSORT_API saint_t divsufsort(const sauchar_t *T, saidx_t *SA, saidx_t n); @@ -76,6 +83,7 @@ divsufsort(const sauchar_t *T, saidx_t *SA, saidx_t n); * @param n The length of the given string. * @return The primary index if no error occurred, -1 or -2 otherwise. */ +DIVSUFSORT_API saidx_t divbwt(const sauchar_t *T, sauchar_t *U, saidx_t *A, saidx_t n); @@ -83,17 +91,20 @@ divbwt(const sauchar_t *T, sauchar_t *U, saidx_t *A, saidx_t n); * Returns the version of the divsufsort library. * @return The version number string. */ +DIVSUFSORT_API const char * divsufsort_version(void); /* Burrows-Wheeler transform. */ +DIVSUFSORT_API saint_t bw_transform(const sauchar_t *T, sauchar_t *U, saidx_t *SA /* can NULL */, saidx_t n, saidx_t *idx); /* Inverse Burrows-Wheeler transform. */ +DIVSUFSORT_API saint_t inverse_bw_transform(const sauchar_t *T, sauchar_t *U, saidx_t *A /* can NULL */, @@ -107,11 +118,13 @@ inverse_bw_transform(const sauchar_t *T, sauchar_t *U, * @param verbose The verbose mode. * @return 0 if no error occurred. */ +DIVSUFSORT_API saint_t sufcheck(const sauchar_t *T, const saidx_t *SA, saidx_t n, saint_t verbose); /* Search for the pattern P in the string T. */ +DIVSUFSORT_API saidx_t sa_search(const sauchar_t *T, saidx_t Tsize, const sauchar_t *P, saidx_t Psize, @@ -119,6 +132,7 @@ sa_search(const sauchar_t *T, saidx_t Tsize, saidx_t *left); /* Search for the character c in the string T. */ +DIVSUFSORT_API saidx_t sa_simplesearch(const sauchar_t *T, saidx_t Tsize, const saidx_t *SA, saidx_t SAsize, @@ -129,4 +143,4 @@ sa_simplesearch(const sauchar_t *T, saidx_t Tsize, } /* extern "C" */ #endif /* __cplusplus */ -#endif /* _DIVSUFSORT_H_ */ +#endif /* _DIVSUFSORT_H */ diff --git a/include/divsufsort_private.h.in b/include/divsufsort_private.h index f0d5e02..538e2c0 100644 --- a/include/divsufsort_private.h.in +++ b/include/divsufsort_private.h @@ -24,31 +24,31 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef _DIVSUFSORT_PRIVATE_H_ -#define _DIVSUFSORT_PRIVATE_H_ +#ifndef _DIVSUFSORT_PRIVATE_H +#define _DIVSUFSORT_PRIVATE_H 1 #ifdef __cplusplus extern "C" { #endif /* __cplusplus */ -#ifdef HAVE_CONFIG_H +#if HAVE_CONFIG_H # include "config.h" #endif #include <assert.h> #include <stdio.h> #if STDC_HEADERS # include <stdlib.h> -# include <stddef.h> +# include <string.h> #else # if HAVE_STDLIB_H # include <stdlib.h> # endif -#endif -#if HAVE_STRING_H -# if !STDC_HEADERS && HAVE_MEMORY_H +# if HAVE_MEMORY_H # include <memory.h> # endif -# include <string.h> +#endif +#if HAVE_STDDEF_H +# include <stddef.h> #endif #if HAVE_STRINGS_H # include <strings.h> diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100644 index 0000000..e8c5295 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,14 @@ +include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include" + "${CMAKE_CURRENT_BINARY_DIR}/../include") + +## libdivsufsort ## +add_library(divsufsort divsufsort.c substringsort.c trsort.c utils.c) +install(TARGETS divsufsort + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib) +set_target_properties(divsufsort PROPERTIES + VERSION "${LIBRARY_VERSION_FULL}" + SOVERSION "${LIBRARY_VERSION_MAJOR}" + DEFINE_SYMBOL DIVSUFSORT_BUILD_DLL + RUNTIME_OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/../examples") diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index cf34c43..0000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,9 +0,0 @@ -# Makefile.am for libdivsufsort - -lib_LTLIBRARIES = libdivsufsort.la -libdivsufsort_la_SOURCES = divsufsort.c substringsort.c trsort.c utils.c -libdivsufsort_la_LDFLAGS = -version-info @LT_CURRENT@:@LT_REVISION@:@LT_AGE@ @LT_NOUNDEF@ -export-symbols libdivsufsort.sym - -AM_CFLAGS = @A_CFLAGS@ - -EXTRA_DIST = libdivsufsort.sym diff --git a/lib/divsufsort.c b/lib/divsufsort.c index 8615246..ac14ea3 100644 --- a/lib/divsufsort.c +++ b/lib/divsufsort.c @@ -358,5 +358,5 @@ divbwt(const sauchar_t *T, sauchar_t *U, saidx_t *A, saidx_t n) { const char * divsufsort_version(void) { - return PACKAGE_VERSION; + return PROJECT_VERSION_FULL; } diff --git a/lib/libdivsufsort.sym b/lib/libdivsufsort.sym deleted file mode 100644 index 2dcda95..0000000 --- a/lib/libdivsufsort.sym +++ /dev/null @@ -1,8 +0,0 @@ -divsufsort -divbwt -divsufsort_version -bw_transform -inverse_bw_transform -sufcheck -sa_search -sa_simplesearch diff --git a/lib/substringsort.c b/lib/substringsort.c index e628f94..d97ebb0 100644 --- a/lib/substringsort.c +++ b/lib/substringsort.c @@ -30,7 +30,7 @@ /*- Private Functions -*/ /* Compares two suffixes. */ -static inline +static INLINE saint_t _compare(const sauchar_t *T, const saidx_t *p1, const saidx_t *p2, @@ -75,7 +75,7 @@ _insertionsort(const sauchar_t *T, const saidx_t *PA, /*---------------------------------------------------------------------------*/ -static inline +static INLINE void _fixdown(const sauchar_t *Td, const saidx_t *PA, saidx_t *SA, saidx_t i, saidx_t size) { @@ -123,7 +123,7 @@ _heapsort(const sauchar_t *Td, const saidx_t *PA, saidx_t *SA, saidx_t size) { /*---------------------------------------------------------------------------*/ /* Returns the median of three elements. */ -static inline +static INLINE saidx_t * _median3(const sauchar_t *Td, const saidx_t *PA, saidx_t *v1, saidx_t *v2, saidx_t *v3) { @@ -137,7 +137,7 @@ _median3(const sauchar_t *Td, const saidx_t *PA, } /* Returns the median of five elements. */ -static inline +static INLINE saidx_t * _median5(const sauchar_t *Td, const saidx_t *PA, saidx_t *v1, saidx_t *v2, saidx_t *v3, saidx_t *v4, saidx_t *v5) { @@ -152,7 +152,7 @@ _median5(const sauchar_t *Td, const saidx_t *PA, } /* Returns the pivot element. */ -static inline +static INLINE saidx_t * _pivot(const sauchar_t *Td, const saidx_t *PA, saidx_t *first, saidx_t *last) { saidx_t *middle; @@ -181,7 +181,7 @@ _pivot(const sauchar_t *Td, const saidx_t *PA, saidx_t *first, saidx_t *last) { /*---------------------------------------------------------------------------*/ -static inline +static INLINE saidx_t _lg(saidx_t n) { static const int log2table[256]= { @@ -212,7 +212,7 @@ static const int log2table[256]= { } /* Binary partition for substrings. */ -static inline +static INLINE saidx_t * _substring_partition(const saidx_t *PA, saidx_t *first, saidx_t *last, saidx_t depth) { @@ -366,7 +366,7 @@ _multikey_introsort(const sauchar_t *T, const saidx_t *PA, /*---------------------------------------------------------------------------*/ /* Block swapping */ -static inline +static INLINE void _block_swap(saidx_t *first1, saidx_t *first2, saidx_t size) { saidx_t *a, *b; diff --git a/lib/trsort.c b/lib/trsort.c index 9e5670e..6f646f1 100644 --- a/lib/trsort.c +++ b/lib/trsort.c @@ -29,7 +29,7 @@ /*- Private Functions -*/ -static inline +static INLINE void _fixdown(const saidx_t *ISAd, saidx_t *SA, saidx_t i, saidx_t size) { saidx_t j, k; @@ -93,7 +93,7 @@ _insertionsort(const saidx_t *ISAd, saidx_t *first, saidx_t *last) { } } -static inline +static INLINE saidx_t _lg(saidx_t n) { static const int log2table[256]= { @@ -126,7 +126,7 @@ static const int log2table[256]= { /*---------------------------------------------------------------------------*/ /* Returns the median of three elements. */ -static inline +static INLINE saidx_t * _median3(const saidx_t *ISAd, saidx_t *v1, saidx_t *v2, saidx_t *v3) { saidx_t *t; @@ -139,7 +139,7 @@ _median3(const saidx_t *ISAd, saidx_t *v1, saidx_t *v2, saidx_t *v3) { } /* Returns the median of five elements. */ -static inline +static INLINE saidx_t * _median5(const saidx_t *ISAd, saidx_t *v1, saidx_t *v2, saidx_t *v3, saidx_t *v4, saidx_t *v5) { @@ -154,7 +154,7 @@ _median5(const saidx_t *ISAd, } /* Returns the pivot element. */ -static inline +static INLINE saidx_t * _pivot(const saidx_t *ISAd, saidx_t *first, saidx_t *last) { saidx_t *middle; |