Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
e614bf1939 | |||
bb7eb2d0d1 | |||
fa40a3e6d2 | |||
4168c83958 | |||
ea280a39b4 | |||
823fcecc03 | |||
e7ca9d9036 | |||
e543baff47 | |||
b636a25e94 | |||
07e05034fc |
@ -25,5 +25,7 @@ install:
|
||||
- sudo dpkg -i pkg-config_0.29.1-0ubuntu2_amd64.deb
|
||||
|
||||
script:
|
||||
- ./build.sh
|
||||
- make check
|
||||
- mkdir build; cd build
|
||||
- cmake .. -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr
|
||||
- make
|
||||
- make test
|
||||
|
73
CMakeLists.txt
Normal file
73
CMakeLists.txt
Normal file
@ -0,0 +1,73 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
|
||||
|
||||
INCLUDE(CheckFunctionExists)
|
||||
|
||||
FIND_PACKAGE(PkgConfig)
|
||||
FIND_PACKAGE(BISON)
|
||||
FIND_PACKAGE(FLEX)
|
||||
|
||||
PKG_CHECK_MODULES(CMOCKA REQUIRED cmocka)
|
||||
|
||||
ENABLE_TESTING()
|
||||
|
||||
SET(VERSION "0.4")
|
||||
SET(TARGET "dice")
|
||||
|
||||
SET(SOURCES
|
||||
"lib/diceexpr.c"
|
||||
"lib/dice.c"
|
||||
)
|
||||
|
||||
SET(HEADERS
|
||||
"lib/dice.h"
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/lib
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
# Yacc/BISON/Flex stuff
|
||||
BISON_TARGET(DICE_PARSER
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/lib/dice_parse.y"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/dice_parse.c"
|
||||
COMPILE_FLAGS "-d"
|
||||
)
|
||||
FLEX_TARGET(DICE_LEXER
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/lib/dice_lexer.l"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/dice_lexer.c"
|
||||
COMPILE_FLAGS "-P dp"
|
||||
)
|
||||
|
||||
ADD_DEFINITIONS("-Wall")
|
||||
|
||||
CHECK_FUNCTION_EXISTS("arc4random_uniform" HAVE_ARC4RANDOM_UNIFORM)
|
||||
IF (HAVE_ARC4RANDOM_UNIFORM)
|
||||
ADD_DEFINITIONS("-DHAVE_ARC4RANDOM_UNIFORM")
|
||||
ELSE()
|
||||
PKG_CHECK_MODULES(BSD REQUIRED libbsd)
|
||||
INCLUDE_DIRECTORIES(${BSD_INCLUDE_DIRS})
|
||||
# used in pkg-config IN file
|
||||
SET(REQUIRES "libbsd")
|
||||
ENDIF()
|
||||
|
||||
# pkg-config file
|
||||
CONFIGURE_FILE("${CMAKE_CURRENT_SOURCE_DIR}/libdice.pc.in"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/libdice.pc"
|
||||
)
|
||||
|
||||
ADD_LIBRARY(${TARGET} SHARED
|
||||
${SOURCES} ${HEADERS}
|
||||
${BISON_DICE_PARSER_OUTPUTS}
|
||||
${FLEX_DICE_LEXER_OUTPUTS}
|
||||
)
|
||||
|
||||
IF (NOT HAVE_ARC4RANDOM_UNIFORM)
|
||||
TARGET_LINK_LIBRARIES(${TARGET} ${BSD_LIBRARIES} m)
|
||||
ENDIF()
|
||||
|
||||
INSTALL(TARGETS ${TARGET} DESTINATION lib)
|
||||
INSTALL(FILES ${HEADERS} DESTINATION include)
|
||||
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libdice.pc
|
||||
DESTINATION share/pkgconfig)
|
||||
|
||||
ADD_SUBDIRECTORY(tests)
|
@ -0,0 +1,3 @@
|
||||
2019-08-19 Florian Stinglmayr <fstinglmayr@gmail.com>
|
||||
* build switch to cmake
|
||||
* release version 0.4
|
19
Makefile.am
19
Makefile.am
@ -1,19 +0,0 @@
|
||||
AM_YFLAGS = -d
|
||||
BUILT_SOURCES = lib/dice_parse.h
|
||||
|
||||
lib_LTLIBRARIES = libdice.la
|
||||
libdice_la_SOURCES = lib/dice_lexer.l \
|
||||
lib/dice_parse.y \
|
||||
lib/dice.h \
|
||||
lib/dice.c \
|
||||
lib/diceexpr.c
|
||||
|
||||
include_HEADERS = lib/dice.h
|
||||
|
||||
AM_CFLAGS = -Ilib
|
||||
|
||||
libdice_la_LIBADD = ${BSD_LIBS}
|
||||
|
||||
pkgconfig_DATA = libdice.pc
|
||||
|
||||
SUBDIRS = . tests
|
@ -28,12 +28,15 @@ supports variable amount, variable sides and fudge dice at the moment:
|
||||
* bison
|
||||
* flex
|
||||
* cmocka >= 1.0.1
|
||||
* cmake
|
||||
|
||||
To build ``libdice`` run:
|
||||
|
||||
```shell
|
||||
$ ./configure --prefix="/usr"
|
||||
$ mkdir build; cd build
|
||||
$ cmake .. -DCMAKE_INSTALL_PREFIX=/usr
|
||||
$ make
|
||||
$ make test
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
|
14
autogen.sh
14
autogen.sh
@ -1,14 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
PATH=$PATH:/usr/local/bin
|
||||
|
||||
aclocal $AC_SEARCH_OPTS
|
||||
autoconf
|
||||
autoreconf --install
|
||||
autoheader
|
||||
automake --copy --add-missing
|
10
build.sh
10
build.sh
@ -1,10 +0,0 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
cd "$(dirname "$0")"
|
||||
|
||||
./autogen.sh
|
||||
./configure "$@"
|
||||
make
|
28
configure.ac
28
configure.ac
@ -1,28 +0,0 @@
|
||||
AC_PREREQ([2.69])
|
||||
AC_INIT([libdice], [0.1], [florian@n0la.org])
|
||||
AM_INIT_AUTOMAKE([subdir-objects])
|
||||
LT_INIT()
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
AC_PROG_CC
|
||||
|
||||
AC_PROG_LEX
|
||||
AC_PROG_YACC
|
||||
|
||||
PKG_CHECK_MODULES([CMOCKA], [cmocka >= 1.0.1])
|
||||
|
||||
AC_CHECK_HEADER_STDBOOL()
|
||||
|
||||
AC_CHECK_FUNCS([arc4random_uniform],,
|
||||
[PKG_CHECK_MODULES([BSD], [libbsd])])
|
||||
|
||||
AC_CONFIG_FILES([Makefile tests/Makefile])
|
||||
|
||||
AC_SEARCH_LIBS([cos], [m], [], [
|
||||
AC_MSG_ERROR([unable to find the cos() function])
|
||||
])
|
||||
|
||||
PKG_INSTALLDIR
|
||||
AC_CONFIG_FILES([libdice.pc])
|
||||
|
||||
AC_OUTPUT
|
26
lib/dice.c
26
lib/dice.c
@ -24,18 +24,16 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_ARC4RANDOM_UNIFORM
|
||||
#include <bsd/stdlib.h>
|
||||
#endif
|
||||
|
||||
extern int yylex_init_extra(void *extra, void **state);
|
||||
extern int yylex_destroy(void *state);
|
||||
extern void yylex(void *state);
|
||||
extern void yy_switch_to_buffer(void *buffer, void *scanner);
|
||||
extern void *yy_scan_string(char const *s, void *scanner);
|
||||
extern void yy_delete_buffer(void *b, void *scanner);
|
||||
extern int dplex_init_extra(void *extra, void **state);
|
||||
extern int dplex_destroy(void *state);
|
||||
extern void dplex(void *state);
|
||||
extern void dp_switch_to_buffer(void *buffer, void *scanner);
|
||||
extern void *dp_scan_string(char const *s, void *scanner);
|
||||
extern void dp_delete_buffer(void *b, void *scanner);
|
||||
|
||||
struct dice_
|
||||
{
|
||||
@ -115,14 +113,14 @@ bool dice_parse(dice_t d, char const *s)
|
||||
return false;
|
||||
}
|
||||
|
||||
yylex_init_extra(d, &scanner);
|
||||
buffer = yy_scan_string(s, scanner);
|
||||
yy_switch_to_buffer(buffer, scanner);
|
||||
dplex_init_extra(d, &scanner);
|
||||
buffer = dp_scan_string(s, scanner);
|
||||
dp_switch_to_buffer(buffer, scanner);
|
||||
|
||||
ret = yyparse(scanner, d);
|
||||
ret = dpparse(scanner, d);
|
||||
|
||||
yy_delete_buffer(buffer, scanner);
|
||||
yylex_destroy(scanner);
|
||||
dp_delete_buffer(buffer, scanner);
|
||||
dplex_destroy(scanner);
|
||||
|
||||
if (ret) {
|
||||
return false;
|
||||
|
@ -2,6 +2,7 @@
|
||||
%option reentrant
|
||||
|
||||
%{
|
||||
#define YYSTYPE DPSTYPE
|
||||
#include "dice.h"
|
||||
#include "dice_parse.h"
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
%define api.pure full
|
||||
%define api.prefix {dp}
|
||||
|
||||
%parse-param {void *scanner} {dice_t dice}
|
||||
%lex-param {void *scanner}
|
||||
@ -6,14 +7,14 @@
|
||||
%{
|
||||
#include "dice.h"
|
||||
|
||||
extern int yylex(void *lval, void *scanner);
|
||||
extern int dplex(void *lval, void *scanner);
|
||||
|
||||
void yyerror(void *scanner, dice_t dice, char const *err)
|
||||
void dperror(void *scanner, dice_t dice, char const *err)
|
||||
{
|
||||
dice_set(dice, DICEOPTION_ERROR, err);
|
||||
}
|
||||
|
||||
int yywrap(void)
|
||||
int dpwrap(void)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,12 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
prefix=@CMAKE_INSTALL_PREFIX@
|
||||
libdir=lib
|
||||
includedir=include
|
||||
|
||||
Name: libdice
|
||||
Description: dice rolling and math expression library
|
||||
Version: 0.1
|
||||
Requires:
|
||||
Version: @VERSION@
|
||||
Requires: @REQUIRES@
|
||||
Conflicts:
|
||||
Cflags: -I${includedir}
|
||||
Libs: -L${libdir} -ldice
|
||||
|
20
tests/CMakeLists.txt
Normal file
20
tests/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 3.2)
|
||||
|
||||
SET(TESTS
|
||||
"test_dice_evaluate"
|
||||
"test_dice_fudge"
|
||||
"test_dice_parse"
|
||||
"test_dice_simple_roll"
|
||||
"test_expr_parse"
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES(
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../lib/"
|
||||
${CMOCKA_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
FOREACH(TEST ${TESTS})
|
||||
ADD_EXECUTABLE(${TEST} ${TEST}.c)
|
||||
TARGET_LINK_LIBRARIES(${TEST} dice ${CMOCKA_LIBRARIES})
|
||||
ADD_TEST(NAME "${TEST}" COMMAND ${TEST})
|
||||
ENDFOREACH()
|
@ -1,10 +0,0 @@
|
||||
check_PROGRAMS = test_dice_simple_roll \
|
||||
test_dice_parse \
|
||||
test_dice_evaluate \
|
||||
test_dice_fudge \
|
||||
test_expr_parse
|
||||
|
||||
AM_CFLAGS = -I../lib ${CMOCKA_CFLAGS}
|
||||
AM_LDFLAGS = ${CMOCKA_LIBS} ../libdice.la
|
||||
|
||||
TESTS = $(check_PROGRAMS)
|
Loading…
x
Reference in New Issue
Block a user