summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CMakeLists.txt24
-rw-r--r--NEWS.md2
-rw-r--r--flake.nix16
-rw-r--r--src/CMakeLists.txt8
-rw-r--r--src/main.cc11
-rw-r--r--src/system.hh.in1
-rw-r--r--src/utils.h3
7 files changed, 48 insertions, 17 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 712aa714..ab17cedd 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,12 +19,10 @@ set(Ledger_TEST_TIMEZONE "America/Chicago")
enable_testing()
-add_definitions(
- -std=c++11
- -DBOOST_FILESYSTEM_NO_DEPRECATED
-)
+add_compile_definitions(BOOST_FILESYSTEM_NO_DEPRECATED)
+add_compile_options(-std=c++11)
if (CYGWIN)
- add_definitions(-U__STRICT_ANSI__)
+ add_compile_options(-U__STRICT_ANSI__)
endif()
########################################################################
@@ -189,14 +187,18 @@ include_directories(${CMAKE_INCLUDE_PATH})
macro(find_opt_library_and_header _header_var _header _lib_var _lib _have_var)
if (${_have_var})
+ message("-- Looking for ${_header} in ${_lib}")
find_path(${_header_var} ${_header})
if (NOT ${_header_var})
+ message("-- Looking for ${_header} in ${_lib} - not found")
set(${_have_var} 0)
else()
find_library(${_lib_var} ${_lib})
if (NOT ${_lib_var})
+ message("-- Looking for ${_header} in ${_lib} - not found")
set(${_have_var} 0)
else()
+ message("-- Looking for ${_header} in ${_lib} - found")
include_directories(SYSTEM "${${_header_var}}")
set(${_have_var} 1)
endif()
@@ -246,8 +248,13 @@ if (MPFR_PATH AND EXISTS "${MPFR_PATH}/mpfr.h")
endif()
-check_library_exists(edit readline "" HAVE_EDIT)
-find_opt_library_and_header(EDIT_PATH histedit.h EDIT_LIB edit HAVE_EDIT)
+check_library_exists(edit add_history "" HAVE_EDIT)
+find_opt_library_and_header(EDIT_PATH editline/readline.h EDIT_LIB edit HAVE_EDIT)
+if (NOT HAVE_EDIT)
+check_library_exists(readline add_history "" HAVE_READLINE)
+find_opt_library_and_header(READLINE_PATH readline/history.h READLINE_LIB readline HAVE_READLINE)
+endif (NOT HAVE_EDIT)
+
#find_package(Gettext) # Used for running tests
@@ -269,6 +276,9 @@ macro(add_ledger_library_dependencies _target)
if (HAVE_EDIT)
target_link_libraries(${_target} ${EDIT_LIB})
endif()
+ if (HAVE_READLINE)
+ target_link_libraries(${_target} ${READLINE_LIB})
+ endif()
if (HAVE_GETTEXT)
target_link_libraries(${_target} ${INTL_LIB})
endif()
diff --git a/NEWS.md b/NEWS.md
index 07cad014..a6f17ebf 100644
--- a/NEWS.md
+++ b/NEWS.md
@@ -11,6 +11,8 @@
- Fix related reports when using bucket transactions (ledger/ledger#2220)
+- Add support to build ledger with readline
+
## 3.3.2 (2023-03-30)
- Fix divide by zero (ledger/ledger#777, ledger/ledger#2207)
diff --git a/flake.nix b/flake.nix
index a992594b..de591136 100644
--- a/flake.nix
+++ b/flake.nix
@@ -6,6 +6,8 @@
outputs = { self, nixpkgs }: let
usePython = true;
gpgmeSupport = true;
+ useLibedit = true;
+ useReadline = false;
forAllSystems = f: nixpkgs.lib.genAttrs systems (system: f system);
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; });
systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
@@ -23,14 +25,24 @@
outputs = [ "out" "dev" ] ++ lib.optionals usePython [ "py" ];
buildInputs = [
- gmp mpfr libedit gnused
+ gmp mpfr gnused
+ ] ++ lib.optionals useLibedit [
+ libedit
+ ] ++ lib.optionals useReadline [
+ readline
] ++ lib.optionals gpgmeSupport [
gpgme
] ++ (if usePython
then [ python3 (boost.override { enablePython = true; python = python3; }) ]
else [ boost ]);
- nativeBuildInputs = [ cmake texinfo tzdata ];
+ nativeBuildInputs = [
+ cmake texinfo tzdata
+ ] ++ lib.optionals useLibedit [
+ libedit.dev
+ ] ++ lib.optionals useReadline [
+ readline.dev
+ ];
enableParallelBuilding = true;
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index f229d70c..4e0e23de 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -149,7 +149,7 @@ endif()
if (CMAKE_BUILD_TYPE STREQUAL "Debug")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang")
- add_definitions(
+ add_compile_options(
# -Weverything
# -Wno-disabled-macro-expansion
# -Wno-padded
@@ -223,7 +223,7 @@ if (CMAKE_BUILD_TYPE STREQUAL "Debug")
-Wno-deprecated
-Wno-strict-aliasing)
- add_definitions(${GXX_WARNING_FLAGS})
+ add_compile_options(${GXX_WARNING_FLAGS})
macro(ADD_PCH_RULE _header_filename _src_list _other_srcs)
set(_gch_filename "${_header_filename}.gch")
@@ -287,8 +287,10 @@ if (BUILD_LIBRARY)
INSTALL_NAME_DIR "${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}"
VERSION ${Ledger_VERSION_MAJOR}
SOVERSION ${Ledger_VERSION_MAJOR})
+ set_source_files_properties(
+ ${LEDGER_CLI_SOURCES} PROPERTIES COMPILE_FLAGS "-fPIC")
- add_executable(ledger main.cc global.cc)
+ add_executable(ledger ${LEDGER_CLI_SOURCES})
target_link_libraries(ledger libledger)
if (HAVE_GPGME)
target_link_libraries(ledger Gpgmepp)
diff --git a/src/main.cc b/src/main.cc
index 6b3e1eb3..fcd61f28 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -41,6 +41,9 @@
#if HAVE_EDIT
#include <editline/readline.h>
+#elif HAVE_READLINE
+#include <readline/readline.h>
+#include <readline/history.h>
#endif
using namespace ledger;
@@ -137,7 +140,7 @@ int main(int argc, char * argv[], char * envp[])
bool exit_loop = false;
-#if HAVE_EDIT
+#if HAVE_EDIT || HAVE_READLINE
rl_readline_name = const_cast<char *>("Ledger");
// TODO: rl_attempted_completion_function = ledger_completion;
@@ -158,7 +161,7 @@ int main(int argc, char * argv[], char * envp[])
add_history(expansion);
}
-#else // HAVE_EDIT
+#else // HAVE_EDIT || HAVE_READLINE
while (! std::cin.eof()) {
std::cout << global_scope->prompt_string();
@@ -167,7 +170,7 @@ int main(int argc, char * argv[], char * envp[])
char * p = skip_ws(line);
-#endif // HAVE_EDIT
+#endif // HAVE_EDIT || HAVE_READLINE
check_for_signal();
@@ -178,7 +181,7 @@ int main(int argc, char * argv[], char * envp[])
global_scope->execute_command_wrapper(split_arguments(p), true);
}
-#if HAVE_EDIT
+#if HAVE_EDIT || HAVE_READLINE
if (expansion)
std::free(expansion);
std::free(p);
diff --git a/src/system.hh.in b/src/system.hh.in
index 10086d23..05f28fc2 100644
--- a/src/system.hh.in
+++ b/src/system.hh.in
@@ -52,6 +52,7 @@
#cmakedefine01 HAVE_GETTEXT
#cmakedefine01 HAVE_EDIT
+#cmakedefine01 HAVE_READLINE
#cmakedefine01 HAVE_GETPWUID
#cmakedefine01 HAVE_GETPWNAM
#cmakedefine01 HAVE_IOCTL
diff --git a/src/utils.h b/src/utils.h
index a3fc9de5..c17c8fb1 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -44,6 +44,7 @@
#pragma once
#include <boost/uuid/detail/sha1.hpp>
+#include <ledger.hh>
#define TIMERS_ON 1
@@ -94,7 +95,7 @@ namespace ledger {
#else // !NO_ASSERTS
-#define assert(x)
+#define assert(x) ((void)(x))
#endif // !NO_ASSERTS