From 56583b3b1befdf9118a2595afa212636b17a7672 Mon Sep 17 00:00:00 2001 From: Jan200101 Date: Sun, 7 Nov 2021 17:12:19 +0100 Subject: basic bottles support --- .github/workflows/ci.yml | 2 +- CMakeLists.txt | 1 + cmake/FindLibyaml.cmake | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 18 +++++++++++++- src/bottles.c | 22 +++++++++++++++++ src/bottles.h | 11 +++++++++ src/defines.h | 2 ++ src/main.c | 6 +++++ src/mock/CMakeLists.txt | 1 + 9 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 cmake/FindLibyaml.cmake create mode 100644 src/bottles.c create mode 100644 src/bottles.h diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8a9b277..1aedcd4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ jobs: - name: Configure CMake working-directory: ${{runner.workspace}}/build - run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_WINE=ON -DENABLE_DXVK=ON -DENABLE_LUTRIS=ON -DBUILD_MOCK:BOOL=ON + run: cmake $GITHUB_WORKSPACE -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DCMAKE_INSTALL_PREFIX=/usr -DENABLE_WINE=ON -DENABLE_DXVK=ON -DENABLE_LUTRIS=ON -DENABLE_BOTTLES=ON -DBUILD_MOCK:BOOL=ON - name: Build working-directory: ${{runner.workspace}}/build diff --git a/CMakeLists.txt b/CMakeLists.txt index b93216b..88798ab 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,6 +13,7 @@ option(BUILD_MOCK "build polecat against mock libraries" OFF) option(ENABLE_WINE "enables wine support [Not on Windows]" ON) option(ENABLE_DXVK "enables dxvk support" ON) option(ENABLE_LUTRIS "enables lutris support" OFF) +option(ENABLE_BOTTLES "enables bottles support" ON) project(polecat VERSION 0.2.0 LANGUAGES C) diff --git a/cmake/FindLibyaml.cmake b/cmake/FindLibyaml.cmake new file mode 100644 index 0000000..09417a4 --- /dev/null +++ b/cmake/FindLibyaml.cmake @@ -0,0 +1,63 @@ +# +# LIBYAML_INCLUDE_DIRS +# LIBYAML_LIBRARIES +# LIBYAML_CFLAGS + +find_package(PkgConfig QUIET) +if (PKG_CONFIG_FOUND) + pkg_check_modules(_LIBYAML yaml-0.1) + + if (BUILD_STATIC AND NOT _LIBYAML_FOUND) + message(FATAL_ERROR "Cannot find static build information") + endif() +endif() + +if (_LIBYAML_FOUND) # we can rely on pkg-config + if (NOT BUILD_STATIC) + set(LIBYAML_LIBRARIES ${_LIBYAML_LIBRARIES}) + set(LIBYAML_INCLUDE_DIRS ${_LIBYAML_INCLUDE_DIRS}) + set(LIBYAML_CFLAGS ${_LIBYAML_CFLAGS_OTHER}) + else() + set(LIBYAML_LIBRARIES ${_LIBYAML_STATIC_LIBRARIES}) + set(LIBYAML_INCLUDE_DIRS ${_LIBYAML_STATIC_INCLUDE_DIRS}) + set(LIBYAML_CFLAGS ${_LIBYAML_STATIC_CFLAGS_OTHER}) + endif() +else() + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(_lib_suffix 64) + else() + set(_lib_suffix 32) + endif() + + find_path(LIBYAML_INC + NAMES yaml.h + HINTS + ENV libyamlPath${_lib_suffix} + ENV libyamlPath + ${_LIBYAML_INCLUDE_DIRS} + PATHS + /usr/include/) + + find_library(LIBYAML_LIB + NAMES ${_LIBYAML_LIBRARIES} libyaml + HINTS + ENV libyamlPath${_lib_suffix} + ENV libyamlPath + ${_LIBYAML_LIBRARY_DIRS} + ${_LIBYAML_STATIC_LIBRARY_DIRS} + PATHS + /usr/lib{_lib_suffix} /usr/local/lib{_lib_suffix} + /usr/lib /usr/local/lib) + + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(Libyaml DEFAULT_MSG LIBYAML_LIB LIBYAML_INC) + mark_as_advanced(LIBYAML_INC LIBYAML_LIB) + + if(LIBYAML_FOUND) + set(LIBYAML_INCLUDE_DIRS ${LIBYAML_INC}) + set(LIBYAML_LIBRARIES ${LIBYAML_LIB}) + if (BUILD_STATIC) + set(LIBYAML_LIBRARIES ${LIBYAML_LIBRARIES} ${_LIBYAML_STATIC_LIBRARIES}) + endif() + endif() +endif() \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index de3d40c..3e18a9f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,10 +1,12 @@ find_package(Libcurl REQUIRED) find_package(JsonC REQUIRED) +find_package(Libyaml REQUIRED) find_package(Libarchive REQUIRED) include_directories(${LIBCURL_INCLUDE_DIRS}) include_directories(${JSONC_INCLUDE_DIRS}) +include_directories(${LIBYAML_INCLUDE_DIRS}) include_directories(${LIBARCHIVE_INCLUDE_DIRS}) list(APPEND @@ -53,6 +55,18 @@ list(APPEND ) endif() +if(ENABLE_BOTTLES) +add_compile_definitions(BOTTLES_ENABLED) +add_library(bottles OBJECT + ${CMAKE_CURRENT_SOURCE_DIR}/bottles.c + ${CMAKE_CURRENT_SOURCE_DIR}/bottles.h +) + +list(APPEND + SOURCES + $ +) +endif() if (ENABLE_WINE AND NOT WIN32) add_compile_definitions(WINE_ENABLED) @@ -75,6 +89,7 @@ set(CFLAGS -Wno-unused-parameter -Wuninitialized ${LIBCURL_CFLAGS} ${JSONC_CFLAGS} + ${LIBYAML_CFLAGS} ${LIBARCHIVE_CFLAGS} ) @@ -90,10 +105,11 @@ add_executable(${CMAKE_PROJECT_NAME} ${SOURCES}) target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${LIBCURL_LIBRARIES}) target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${JSONC_LIBRARIES}) +target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${LIBYAML_LIBRARIES}) target_link_libraries(${CMAKE_PROJECT_NAME} LINK_PUBLIC ${LIBARCHIVE_LIBRARIES}) install(TARGETS ${CMAKE_PROJECT_NAME}) if(BUILD_MOCK) add_subdirectory(mock) -endif() \ No newline at end of file +endif() diff --git a/src/bottles.c b/src/bottles.c new file mode 100644 index 0000000..42d62a1 --- /dev/null +++ b/src/bottles.c @@ -0,0 +1,22 @@ + +#include "bottles.h" + +static const struct Command bottles_commands[] = { + { .name = "info", .func = bottles_info, .description = "show information about a bottles script" }, +}; + +static const struct Flag bottles_flags[] = { + { .name = "help", .variant = TWO, .returns = 1, .func = bottles_help, .description = "show this message"}, + { .name = "no-net", .variant = TWO, .returns = 0, .func = set_no_net, .description = "run commands without commitment"} +}; + + +COMMAND_GROUP_FUNC(bottles) + +COMMAND(bottles, info) +{ + return 0; +} + + +COMMAND_HELP(bottles, " bottles") diff --git a/src/bottles.h b/src/bottles.h new file mode 100644 index 0000000..53bca16 --- /dev/null +++ b/src/bottles.h @@ -0,0 +1,11 @@ +#ifndef BOTTLES_H +#define BOTTLES_H + +#include "command.h" + +COMMAND_GROUP(bottles); +COMMAND(bottles, info); +COMMAND(bottles, help); + + +#endif diff --git a/src/defines.h b/src/defines.h index eb9989f..7a2615b 100644 --- a/src/defines.h +++ b/src/defines.h @@ -12,6 +12,8 @@ #define LUTRIS_GAME_SEARCH_API LUTRIS_GAME_API "?search=%s" #define LUTRIS_GAME_INSTALLER_API LUTRIS_GAME_API "/%s/installers" +#define BOTTLES_API "https://raw.githubusercontent.com/bottlesdevs/programs/main" +#define BOTTLES_API_INDEX BOTTLES_API "/index" #ifndef NAME #warning "no name specified, setting it to \"polecat\"" diff --git a/src/main.c b/src/main.c index 67f99db..6fe6a1a 100644 --- a/src/main.c +++ b/src/main.c @@ -13,6 +13,9 @@ #ifdef LUTRIS_ENABLED #include "lutris.h" #endif +#ifdef BOTTLES_ENABLED +#include "bottles.h" +#endif #include "common.h" #include "config.h" @@ -32,6 +35,9 @@ static const struct Command main_commands[] = { #endif #ifdef LUTRIS_ENABLED { .name = "lutris", .func = lutris, .description = "run lutris instraller"}, +#endif +#ifdef BOTTLES_ENABLED + { .name = "bottles", .func = bottles, .description = "run bottles instraller"}, #endif { .name = "env", .func = main_env, .description = "show some information about polecat" }, }; diff --git a/src/mock/CMakeLists.txt b/src/mock/CMakeLists.txt index 1b23c63..81935e3 100644 --- a/src/mock/CMakeLists.txt +++ b/src/mock/CMakeLists.txt @@ -47,6 +47,7 @@ set(NAME ${CMAKE_PROJECT_NAME}_mock) add_executable(${NAME} ${SOURCES}) target_link_libraries(${NAME} LINK_PUBLIC ${JSONC_LIBRARIES}) +target_link_libraries(${NAME} LINK_PUBLIC ${LIBYAML_LIBRARIES}) target_link_libraries(${NAME} LINK_PUBLIC ${LIBARCHIVE_LIBRARIES}) target_link_libraries(${NAME} LINK_PUBLIC mock) -- cgit v1.2.3