From cf52e8e9ddd6db35980ef00aeb82396a17fafec5 Mon Sep 17 00:00:00 2001 From: GP Orcullo Date: Sat, 26 Mar 2022 06:16:33 +0000 Subject: [PATCH 1/2] Add support for Alpine Linux --- CMakeLists.txt | 4 +++ background_installer.sh | 26 ++++++++++++++++++- runtime/core/lib/iec_std_lib.h | 5 ++++ .../asio/include/asio/detail/socket_types.hpp | 6 ++++- 4 files changed, 39 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9ebf5cc..db6a21f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -65,6 +65,7 @@ option(OPLC_ST_TO_C "Build target to convert ST to C" OFF) option(OPLC_MAIN_PROGRAM "Only compile the ST file" OFF) option(OPLC_BUILD_TESTS "Build automated tests" OFF) +option(OPLC_MUSL "Support for musl libc" OFF) # Flag to build all dependencies and source if(OPLC_ALL) @@ -172,6 +173,9 @@ endif() if(OPLC_DNP3_OUTSTATION) message("Build and install OpenDNP3 enabled") add_definitions(-DOPLC_DNP3_OUTSTATION) + if(OPLC_MUSL) + add_definitions(-DOPLC_MUSL) + endif() add_subdirectory(utils/dnp3_src) include_directories(utils/dnp3_src/cpp/libs/include) endif() diff --git a/background_installer.sh b/background_installer.sh index c5a2d6a..55ea9ab 100755 --- a/background_installer.sh +++ b/background_installer.sh @@ -7,6 +7,7 @@ if [ $# -eq 0 ]; then echo "Usage: ./install.sh [platform] where [platform] can be" echo " win Install OpenPLC on Windows over Cygwin" echo " linux Install OpenPLC on a Debian-based Linux distribution" + echo " alpine Install OpenPLC on an Alpine-based Linux distribution" echo " docker Install OpenPLC in a Docker container" echo " rpi Install OpenPLC on a Raspberry Pi" echo " neuron Install OpenPLC on a UniPi Neuron PLC" @@ -37,6 +38,13 @@ function linux_install_deps { sqlite3 cmake git } +function alpine_install_deps { + $1 apk add --no-cache autoconf automake bison cmake flex g++ make \ + libtool linux-headers pkgconf python3 py3-flask \ + py3-flask-login py3-pip py3-pyserial sqlite + $1 pip3 install pymodbus +} + function install_py_deps { $1 pip3 install -r requirements.txt } @@ -52,12 +60,13 @@ function OPLC_background_service { $1 systemctl enable openplc.service } +# arg1: additional CMAKE args function cmake_build_and_test { echo "" echo "Building the application" mkdir build cd build - cmake .. -DOPLC_ALL=ON + cmake .. -DOPLC_ALL=ON $1 make echo "Executing platform tests" @@ -126,6 +135,21 @@ elif [ "$1" == "linux" ]; then cd ../scripts ./change_hardware_layer.sh blank_linux +elif [ "$1" == "alpine" ]; then + echo "Installing OpenPLC on Alpine Linux" + alpine_install_deps sudo + + cmake_build_and_test -DOPLC_MUSL=ON + + if [ $? -ne 0 ]; then + echo "Compilation finished with errors!" + exit 1 + fi + echo "Compilation finished successfully!" + + cd ../scripts + ./change_hardware_layer.sh blank_linux + elif [ "$1" == "docker" ]; then echo "Installing OpenPLC on Linux inside Docker" diff --git a/runtime/core/lib/iec_std_lib.h b/runtime/core/lib/iec_std_lib.h index bd29e96..1949ea8 100644 --- a/runtime/core/lib/iec_std_lib.h +++ b/runtime/core/lib/iec_std_lib.h @@ -44,6 +44,11 @@ #include #include +#ifdef OPLC_MUSL +#define __NEED_time_t +#include +#endif + #ifdef DEBUG_IEC #define DBG(...) printf(__VA_ARGS__); #define DBG_TYPE(TYPENAME, name) __print_##TYPENAME(name); diff --git a/utils/dnp3_src/deps/asio/asio/include/asio/detail/socket_types.hpp b/utils/dnp3_src/deps/asio/asio/include/asio/detail/socket_types.hpp index 3114c08..655973f 100644 --- a/utils/dnp3_src/deps/asio/asio/include/asio/detail/socket_types.hpp +++ b/utils/dnp3_src/deps/asio/asio/include/asio/detail/socket_types.hpp @@ -58,7 +58,11 @@ #else # include # if !defined(__SYMBIAN32__) -# include +# if defined(OPLC_MUSL) +# include +# else +# include +# endif # endif # include # include From 1e3dbebe01458e88d84bf07221bf410e3ed22379 Mon Sep 17 00:00:00 2001 From: GP Orcullo Date: Sun, 27 Mar 2022 02:14:43 +0000 Subject: [PATCH 2/2] add alpine to compile_program.sh --- background_installer.sh | 1 + scripts/compile_program.sh | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/background_installer.sh b/background_installer.sh index 55ea9ab..3756868 100755 --- a/background_installer.sh +++ b/background_installer.sh @@ -147,6 +147,7 @@ elif [ "$1" == "alpine" ]; then fi echo "Compilation finished successfully!" + touch ../etc/alpine cd ../scripts ./change_hardware_layer.sh blank_linux diff --git a/scripts/compile_program.sh b/scripts/compile_program.sh index f1cb67f..68cd9d6 100755 --- a/scripts/compile_program.sh +++ b/scripts/compile_program.sh @@ -13,7 +13,11 @@ echo "" if [ "$OPENPLC_PLATFORM" = "linux" ]; then cd ../build - cmake .. -Dprogram_name=$1 + x=OFF + if [ -e ../etc/alpine ]; then + x=ON + fi + cmake .. -Dprogram_name=$1 -DOPLC_MUSL=$x cmake --build . if [ $? -ne 0 ]; then echo "Compilation finished with errors!"