diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..cd9330e --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,112 @@ +# ############################################################################## +# Description: CMakeLists.txt +# +# This file, 'CMakeLists.txt', implements build system rules for BB-GPIO project +# +# Copyright (C) 2021 Jakub Fišer +# +# This program is free software; you can redistribute it and/or modify it under +# the terms of the GNU Lesser General Public License as published by the Free +# Software Foundation; either version 2.1 of the License, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +# details. +# +# You should have received a copy of the GNU Lesser General Public License along +# with this library; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# ############################################################################## +# ~~~ + +cmake_minimum_required(VERSION 3.22) + +set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE) +set(CMAKE_EXPORT_LINK_COMMANDS TRUE) +set(CMAKE_DISABLE_SOURCE_CHANGES TRUE) +set(CMAKE_DISABLE_IN_SOURCE_BUILD TRUE) + +project( + BB-GPIO + VERSION 1.0.0 + DESCRIPTION "GPIO driver for Beaglebone Black SBC" + HOMEPAGE_URL "https://github.com/PocketNC/bb_gpio" + LANGUAGES C) + +if(CMAKE_TOOLCHAIN_FILE) + cmake_path(IS_RELATIVE CMAKE_TOOLCHAIN_FILE _toolchain_file_is_relative) + if(_toolchain_file_is_relative) + file(REAL_PATH "${CMAKE_TOOLCHAIN_FILE}" _toolchain_path BASE_DIRECTORY + "${CMAKE_BINARY_DIR}" EXPAND_TILDE) + if(NOT EXISTS "${_toolchain_path}") + message( + FATAL_ERROR "Specified Toolchain file ${_toolchain_path} doesn't exist!" + ) + endif() + set(CMAKE_TOOLCHAIN_FILE "${_toolchain_path}") + message( + WARNING + "CMAKE_TOOLCHAIN_FILE set to ${CMAKE_TOOLCHAIN_FILE} to resolve the relative path issue. Please, avoid using relative paths!" + ) + unset(_toolchain_path) + endif() + unset(_toolchain_file_is_relative) +endif() + +find_package( + Machinekit-HAL + COMPONENTS Managed-Runtime Managed-HAL + REQUIRED) + +include(GNUInstallDirs) +include(CPackComponent) +include(CPack) +include(FindPkgConfig) + +set(MACHINEKIT_HAL_PACKAGE_PREFIX_PATH "machinekit/hal") +set(MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY + "${CMAKE_INSTALL_LIBDIR}/${MACHINEKIT_HAL_PACKAGE_PREFIX_PATH}/module/managed" +) + +set(CMAKE_C_STANDARD 11) + +set(CMAKE_C_FLAGS_DEBUG "-g -O0") +set(CMAKE_CXX_FLAGS_DEBUG "-g -O0") +set(CMAKE_C_FLAGS_RELEASE "-O0") +set(CMAKE_CXX_FLAGS_RELEASE "-O0") +set(CMAKE_C_FLAGS_RELWITHDEBINFO "-g -O0") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O0") + +message(STATUS "Value of CMAKE_CXX_FLAGS: ${CMAKE_CXX_FLAGS}") +message(STATUS "Value of CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") +message(STATUS "Value of CMAKE_EXE_LINKER_FLAGS: ${CMAKE_EXE_LINKER_FLAGS}") + +pkg_check_modules(LIBGPIOD "libgpiod" REQUIRED IMPORTED_TARGET) + +add_library(bb_gpio MODULE) +target_sources(bb_gpio PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/bb_gpio.c" + "${CMAKE_CURRENT_SOURCE_DIR}/bb_gpio.h") + +target_link_libraries( + bb_gpio PRIVATE Machinekit::HAL::managed_hal Machinekit::HAL::managed_runtime + PkgConfig::LIBGPIOD) + +export_rtapi_symbols(TARGET bb_gpio) + +set_target_properties( + bb_gpio + PROPERTIES OUTPUT_NAME "bb_gpio" + PREFIX "mod" + LIBRARY_OUTPUT_DIRECTORY + "${MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY}") + +install(TARGETS bb_gpio + LIBRARY DESTINATION "${MACHINEKIT_HAL_MANAGED_MODULE_DIRECTORY}" + COMPONENT BB_GPIO_Managed_Module_Drivers) + +cpack_add_component(BB_GPIO_Managed_Module_Drivers GROUP BB_GPIO_Managed_Module) + +cpack_add_component_group(BB_GPIO_Managed_Module) diff --git a/bb_gpio.c b/bb_gpio.c index edd9a25..6e7a10d 100644 --- a/bb_gpio.c +++ b/bb_gpio.c @@ -10,11 +10,11 @@ * ********************************************************************/ -#include "rtapi.h" /* RTAPI realtime OS API */ -#include "rtapi_app.h" /* RTAPI realtime module decls */ -#include "rtapi_errno.h" /* EINVAL etc */ -#include "hal.h" /* HAL public API decls */ -#include "hal_priv.h" +#include "runtime/rtapi.h" /* RTAPI realtime OS API */ +#include "runtime/rtapi_app.h" /* RTAPI realtime module decls */ +#include "runtime/rtapi_errno.h" /* EINVAL etc */ +#include "hal/hal.h" /* HAL public API decls */ +#include "hal/hal_priv.h" #include "bb_gpio.h" #include @@ -22,6 +22,7 @@ #include #include #include +#include MODULE_AUTHOR("John Allwine"); MODULE_DESCRIPTION("Driver for GPIO pins on Beaglebone Boards using /dev/mem"); diff --git a/debian/changelog b/debian/changelog new file mode 100644 index 0000000..cd55b56 --- /dev/null +++ b/debian/changelog @@ -0,0 +1,7 @@ +bb-gpio (1.0.0) bullseye; urgency=low + + * Update to use the new Machinekit-HAL packaging scheme + * Add simple Debian packaging + * Add a CMake based buildsystem + + -- Jakub Fišer Sat, 22 Jan 2020 10:00:00 +0200 diff --git a/debian/control b/debian/control new file mode 100644 index 0000000..a445f76 --- /dev/null +++ b/debian/control @@ -0,0 +1,25 @@ +Source: bb-gpio +Section: misc +Priority: optional +Maintainer: MachinekitBot +Build-Depends: + dh-cmake, + dh-cmake-compat (= 1), + dh-sequence-cpack, + debhelper-compat (= 12), + debhelper (>= 10), + libmachinekit-hal-dev, + libgpiod-dev +Standards-Version: 4.5.1 +Homepage: https://github.com/PocketNC/bb_gpio + + +Package: modbb-gpio +Architecture: any +Multi-Arch: same +Depends: + ${shlibs:Depends}, + ${misc:Depends}, + machinekit-hal +Description: BeagleBone Black GPIO Driver for Machinekit-HAL + Managed HAL driver module for BeagleBone Black GPIO diff --git a/debian/modbb-gpio.cpack-component-groups b/debian/modbb-gpio.cpack-component-groups new file mode 100644 index 0000000..e67eba5 --- /dev/null +++ b/debian/modbb-gpio.cpack-component-groups @@ -0,0 +1 @@ +BB_GPIO_Managed_Module diff --git a/debian/rules b/debian/rules new file mode 100755 index 0000000..e27b122 --- /dev/null +++ b/debian/rules @@ -0,0 +1,51 @@ +#!/usr/bin/make -f + +# #################################################################### +# Description: rules +# +# This file, 'rules', implements build targets for Debian +# style packaging +# +# Copyright (C) 2021 Jakub Fišer +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# +# ##################################################################### + +# Turn OFF the Link-Time Optimization (LTO) during compilation as it clashes with the +# current version of linker script turning symbols of HAL modules local (defined +# in 'MachinekitHALSymbolVisibilityFunction.cmake' CMake file) +DEB_CFLAGS_MAINT_STRIP :=-flto=auto -ffat-lto-objects +DEB_CXXFLAGS_MAINT_STRIP :=-flto=auto -ffat-lto-objects +DEB_LDFLAGS_MAINT_STRIP :=-flto=auto + +# Set the main optimization value for all parts to O0 +DEB_CFLAGS_MAINT_STRIP +=-O2 +DEB_CXXFLAGS_MAINT_STRIP +=-O2 +DEB_CFLAGS_MAINT_APPEND :=-O0 +DEB_CXXFLAGS_MAINT_APPEND :=-O0 + +# Do not warn on potential reproducible build datetime mismatch +DEB_CPPFLAGS_MAINT_STRIP :=-Wdate-time + +export DEB_CFLAGS_MAINT_STRIP +export DEB_CXXFLAGS_MAINT_STRIP +export DEB_LDFLAGS_MAINT_STRIP +export DEB_CFLAGS_MAINT_APPEND +export DEB_CXXFLAGS_MAINT_APPEND +export DEB_CPPFLAGS_MAINT_STRIP + +%: + dh $@ --buildsystem=cmake