Skip to content

Commit

Permalink
Update libify to support IDF export with symlinks (#770)
Browse files Browse the repository at this point in the history
Adds two features to libify.sh:
- adds support for creating or updating an OpenMRNIDF repository. This means skipping arduino-specific stuff, like examples or OpenMRNLite.h, rpelacing the readme.md and library.properties files with a different one.
- Adds support for creating relative symlinks. This allows using OpenMRNIDF that links back to openmrn using relative symlinks -- these can be checked into git for example.
- Adds the few toplevel files for OpenMRNIDF like cmakefile

===

* Adds support for updating an openmrnidf repo instead of an android repo.

* Adds support for creating relative symlinks to openmrn source tree.

* Adds additional toplevel files that OpenMRNIDF needs.

* Fixes comments.
  • Loading branch information
balazsracz authored Feb 5, 2024
1 parent 157139e commit 7a842f3
Show file tree
Hide file tree
Showing 4 changed files with 122 additions and 12 deletions.
44 changes: 44 additions & 0 deletions arduino/idf/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
set(SOURCE_DIRS
src/dcc
src/executor
src/freertos_drivers/esp32
src/freertos_drivers/arduino
src/openlcb
src/os
src/utils
)

if(CONFIG_ENABLE_ARDUINO_DEPENDS)
list(APPEND SOURCE_DIRS src)
endif()

set(IDF_DEPS
app_update
bootloader_support
driver
esp_adc
esp_app_format
esp_system
esp_wifi
espcoredump
hal
heap
vfs
mdns)

idf_component_register(SRC_DIRS "${SOURCE_DIRS}"
INCLUDE_DIRS "src"
REQUIRES "${IDF_DEPS}")

###############################################################################
# Suppress compilation warnings in OpenMRN
###############################################################################

target_compile_options(${COMPONENT_LIB} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:-Wno-volatile>)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-type-limits)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-ignored-qualifiers)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-missing-field-initializers)
target_compile_options(${COMPONENT_LIB} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-class-memaccess>)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-implicit-fallthrough)
target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-error=nonnull)
target_compile_options(${COMPONENT_LIB} PRIVATE $<$<COMPILE_LANGUAGE:CXX>:-Wno-redundant-move>)
6 changes: 6 additions & 0 deletions arduino/idf/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# OpenMRN Component for ESP-IDF

This is an exported version of the OpenMRN library for usage as an ESP-IDF
component.

More information about OpenMRN can be found [here](https://github.com/bakerstu/openmrn).
11 changes: 11 additions & 0 deletions arduino/idf/library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
name=OpenMRNIDF
version=1.0.2
author=Stuart Baker, Mike Dunston, Balazs Racz
maintainer=Mike Dunston <[email protected]>, Balazs Racz <[email protected]>
includes=OpenMRNLite.h
sentence=Network protocol stack for model railroading: OpenLCB and LCC implementation.
paragraph=This library implements network protocols for model railroading. In the center is the OpenLCB protocol suite (Open Layout Control Bus), which has been adopted by the NMRA and referenced as LCC (Layout Command Control): a high-performance and highly extensible communications protocol suite for model railroad control. OpenMRN is one of the most extensible implementation of this protocol suite. The Lite version has been adapted to work with the programming model and drivers of the Arduino ecosystem. Currently supports esp32 and stm32 cores.
category=Communication
url=http://github.com/atanisoft/OpenMRNIDF
architectures=esp32
dot_a_linkage=true
73 changes: 61 additions & 12 deletions arduino/libify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@

function usage() {
echo
echo 'usage: libify.sh path/to/arduino/library/output path/to/openmrn [-f] [-l]'
echo 'usage: libify.sh path/to/arduino/library/output path/to/openmrn [-f] [-l] [-i] [-r]'
echo 'exports OpenMRN code as an arduino library.'
echo 'example: libify.sh ~/Arduino/libraries/OpenMRN .. -l'
echo 'example: libify.sh ~/Arduino/libraries/OpenMRNLite .. -l'
echo '(options must come after the path specification)'
echo '-f will erase the target library before exporting.'
echo '-l will create symlinks instead of copying files.'
echo '-i will create OpenMRNIDF repository instead of arduino.'
echo '-r will create relative symlinks. OpenMRNPath has to be a relative path from the library export directory back to openmrn, starting with ../'
exit 1
}

Expand All @@ -38,6 +40,7 @@ fi

TARGET_LIB_DIR=$($REALPATH $1 2>/dev/null)
OPENMRNPATH=$($REALPATH $2 2>/dev/null)
ORIGOMRNPATH="${2}"

if [[ -z ${TARGET_LIB_DIR} ]]; then
if [[ $1 ]]; then
Expand All @@ -61,6 +64,7 @@ fi

USE_LINK=
VERBOSE=
TARGET_IDF=

while [ "x$1" != "x" ] ; do
case $1 in
Expand All @@ -71,19 +75,58 @@ while [ "x$1" != "x" ] ; do
-l)
USE_LINK=-s
;;
-i)
TARGET_IDF=1
;;
-v)
VERBOSE=1
;;
-r)
USE_LINK=-s
export RELATIVE=1
OPENMRNPATH="${ORIGOMRNPATH}"
;;
esac
shift
done

# Creates a relative path to the toplevel of the directory.
# $1 is a directory path without trailing /, such as
# 'src/freertos_drivers/esp32"
# prints to stdout a relative path like "../../.." to get back to the toplevel
# from the given subdiretory.
function get_relative() {
if [ "x${RELATIVE}" == "x" ]; then
# print nothing
return
fi
if [ "x${1}" == "x." ] ; then
echo "./"
return
fi
SUB="$(echo $1 | sed s/[^/]//g)"
case ${SUB} in
"")
echo "../"
;;
"/")
echo "../../"
;;
"//")
echo "../../../"
;;
*)
echo UNKNOWN SUBTREE "'"${SUB}"'"
esac
}

# Arguments:
# $1 is the relative path in the library directory
# $2... is the relative path in openmrn tree with the filename
# Will create necessary directories internally.
function copy_file() {
REL_DIR=$1
REL_DIR="$1"
INVERSE_DIR="$(get_relative $1)"
shift
if [ "x$VERBOSE" != "x" ]; then
echo "Creating ${TARGET_LIB_DIR}/${REL_DIR}"
Expand All @@ -92,13 +135,13 @@ function copy_file() {
pushd ${TARGET_LIB_DIR}/${REL_DIR} >/dev/null
while [ "x$1" != "x" ] ; do
if [ "x$VERBOSE" != "x" ]; then
echo "${OPENMRNPATH}/${1} ==> ${TARGET_LIB_DIR}/${REL_DIR}"
echo "${INVERSE_DIR}${OPENMRNPATH}/${1} ==> ${TARGET_LIB_DIR}/${REL_DIR}"
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
cp -fa ${USE_LINK} ${OPENMRNPATH}/${1} .
cp -fa ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/${1} .
else
cp -fax ${USE_LINK} ${OPENMRNPATH}/${1} .
cp -fax ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/${1} .
fi

shift
Expand All @@ -118,22 +161,28 @@ function copy_dir() {
pushd ${TARGET_LIB_DIR}/$1 >/dev/null

if [ "x$VERBOSE" != "x" ]; then
echo "${OPENMRNPATH}/${2} ==> ${TARGET_LIB_DIR}/$1"
echo "${INVERSE_DIR}${OPENMRNPATH}/${2} ==> ${TARGET_LIB_DIR}/$1"
fi

if [[ "$OSTYPE" == "darwin"* ]]; then
cp -fa ${USE_LINK} ${OPENMRNPATH}/$2 .
cp -fa ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/$2 .
else
cp -faxr ${USE_LINK} ${OPENMRNPATH}/$2 .
cp -faxr ${USE_LINK} ${INVERSE_DIR}${OPENMRNPATH}/$2 .
fi

popd >/dev/null
}

copy_file . arduino/{library.json,library.properties,keywords.txt,README.md,LICENSE,CONTRIBUTING.md}
copy_dir . arduino/examples
if [ "x$TARGET_IDF" == "x" ]; then
copy_file . arduino/{library.json,library.properties,keywords.txt,README.md,LICENSE,CONTRIBUTING.md}
copy_dir . arduino/examples
copy_file src arduino/OpenMRNLite.{h,cpp}
else
copy_file . arduino/LICENSE arduino/idf/{CMakeLists.txt,README.md}
copy_file src arduino/idf/library.properties arduino/keywords.txt
fi

copy_file src arduino/OpenMRNLite.{h,cpp} arduino/CDIXMLGenerator.hxx \
copy_file src arduino/CDIXMLGenerator.hxx \
include/{can_frame.h,nmranet_config.h,openmrn_features.h,i2c.h,i2c-dev.h} \
include/freertos/{bootloader_hal.h,can_ioctl.h,endian.h,freertos_includes.h,stropts.h} \
include/freertos_select/ifaddrs.h
Expand Down

0 comments on commit 7a842f3

Please sign in to comment.