Skip to content

Commit

Permalink
Define default script path in /opt/pihole/libs and always build READL…
Browse files Browse the repository at this point in the history
…INE support if static libraries are available on the system

Signed-off-by: DL6ER <dl6er@dl6er.de>
  • Loading branch information
DL6ER committed Nov 18, 2020
1 parent 6e40238 commit 80a9ce8
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 367 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ version: 2
no_output_timeout: 30m
command: |
BRANCH=$([ -z "$CIRCLE_TAG" ] && echo "$CIRCLE_BRANCH" || echo "master")
bash .circleci/build-CI.sh "-DSTATIC=${STATIC} -DLUA_READLINE=true" "${BRANCH}" "${CIRCLE_TAG}" "${CIRCLE_JOB}"
bash .circleci/build-CI.sh "-DSTATIC=${STATIC}" "${BRANCH}" "${CIRCLE_TAG}" "${CIRCLE_JOB}"
- run:
name: "Binary checks"
command: bash test/arch_test.sh
Expand Down
12 changes: 8 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,16 @@ if(LUA_DL STREQUAL "true")
target_link_libraries(pihole-FTL ${LIBDL})
endif()

if(LUA_READLINE STREQUAL "true")
find_library(LIBREADLINE libreadline${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBHISTORY libhistory${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBTERMCAP libtermcap${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBREADLINE libreadline${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBHISTORY libhistory${CMAKE_STATIC_LIBRARY_SUFFIX})
find_library(LIBTERMCAP libtermcap${CMAKE_STATIC_LIBRARY_SUFFIX})
if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP)
message(STATUS "Building FTL with readline support: YES")
target_compile_definitions(FTL PRIVATE LUA_USE_READLINE)
target_compile_definitions(pihole-FTL PRIVATE LUA_USE_READLINE)
target_link_libraries(pihole-FTL ${LIBREADLINE} ${LIBHISTORY} ${LIBTERMCAP})
else()
message(STATUS "Building FTL with readline support: NO")
endif()

if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
Expand Down
12 changes: 7 additions & 5 deletions src/args.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,26 +280,28 @@ void parse_args(int argc, char* argv[])
{
history_file = word.we_wordv[0];
const int ret_r = read_history(history_file);
if(debug)
printf("FTL hint: Reading history: %s = %i (%s)\n", history_file, ret_r, ret_r == 0 ? "success" : strerror(ret_r));
if(dnsmasq_debug)
printf("Reading history: %s = %i (%s)\n", history_file, ret_r, ret_r == 0 ? "success" : strerror(ret_r));

// The history file may not exist, try to create an empty one in this case
if(ret_r == ENOENT)
{
printf("FTL hint: Creating new history: %s\n", history_file);
printf("Creating new history: %s\n", history_file);
FILE *history = fopen(history_file, "w");
if(history != NULL)
fclose(history);
}
}
#else
printf("No readline!\n");
#endif
const int ret = lua_main(argc - i, &argv[i]);
#if defined(LUA_USE_READLINE)
if(history_file != NULL)
{
const int ret_w = write_history(history_file);
if(debug)
printf("FTL hint: Writing history: %s = %i (%s)\n", history_file, ret_w, ret_w == 0 ? "success" : strerror(ret_w));
if(dnsmasq_debug)
printf("Writing history: %s = %i (%s)\n", history_file, ret_w, ret_w == 0 ? "success" : strerror(ret_w));
wordfree(&word);
}
#endif
Expand Down
10 changes: 7 additions & 3 deletions src/lua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,18 @@ add_library(lua OBJECT ${sources})
# (partially obsoleted) standard C functions
target_compile_definitions(lua PRIVATE LUA_USE_POSIX)

# Set the default path that Lua uses to look for Lua libraries.
target_compile_definitions(lua PRIVATE LUA_PATH_DEFAULT="/opt/pihole/libs/?.lua")

if(LUA_DL STREQUAL "true")
target_compile_definitions(lua PRIVATE LUA_USE_DLOPEN)
endif()

if(LUA_READLINE STREQUAL "true")
if(LIBREADLINE AND LIBHISTORY AND LIBTERMCAP)
message(STATUS "Embedded LUA will use readline for history: YES")
target_compile_definitions(lua PRIVATE LUA_USE_READLINE)
else()
message(STATUS "Embedded LUA will use readline for history: NO")
endif()

target_include_directories(lua PRIVATE ${PROJECT_SOURCE_DIR}/src ${PROJECT_SOURCE_DIR}/src/lua)

add_subdirectory(libs)
6 changes: 3 additions & 3 deletions src/lua/ftl_lua.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
*
* This file is copyright under the latest version of the EUPL.
* Please see LICENSE file for your rights under this license. */
#ifndef LUA_H
#define LUA_H
#ifndef FTL_LUA_H
#define FTL_LUA_H

#include "lua.h"

Expand All @@ -21,4 +21,4 @@ extern int dolibrary (lua_State *L, const char *name);

void ftl_lua_init(lua_State *L);

#endif //LUA_H
#endif //FTL_LUA_H
11 changes: 0 additions & 11 deletions src/lua/libs/CMakeLists.txt

This file was deleted.

Loading

0 comments on commit 80a9ce8

Please sign in to comment.