Commit 8b1d3647 authored by Lucas Russo's avatar Lucas Russo

src/libs/libllio/*: librarize LLIO to improve modularity/reuse

This does not use the zproject project
available in https://github.com/zeromq/zproject,
but matches more closely its structure.

Also, we can now use the LLIO layer in standalone
applications, such as for accessing a PCIe device
independently of the DEVIO export system.
parent 2e2accad
# Set your cross compile prefix with CROSS_COMPILE variable
CROSS_COMPILE ?=
CMDSEP = ;
CC ?= $(CROSS_COMPILE)gcc
AR ?= $(CROSS_COMPILE)ar
LD ?= $(CROSS_COMPILE)ld
OBJDUMP ?= $(CROSS_COMPILE)objdump
OBJCOPY ?= $(CROSS_COMPILE)objcopy
SIZE ?= $(CROSS_COMPILE)size
MAKE ?= make
PWD = $(shell pwd)
LIBNAME_RAW = llio
LIBNAME = lib$(LIBNAME_RAW)
# Special variable for version.h script only
LIBNAME_FILES = ll_io
# Config variables suitable for creating shared libraries
LIB_VER = $(shell ./version.sh $(LIBNAME_FILES))
LIB_VER_MAJOR = $(shell echo $(LIB_VER)| cut -d'.' -f1)
LIB_VER_MINOR = $(shell echo $(LIB_VER)| cut -d'.' -f2)
LIB_VER_REVESION = $(shell echo $(LIB_VER)| cut -d'.' -f3)
PREFIX ?= /usr/local
export PREFIX
# General C/CPP flags
CFLAGS_USR = -std=gnu99 -O2 -fPIC
# We expect tghese variables to be appended to the possible
# command-line options
override CPPFLAGS +=
override CXXFLAGS +=
# To enable this option, use: make ERRHAND_DBG=y
ifneq ($(ERRHAND_DBG),)
CFLAGS_DEBUG += -DERRHAND_DBG=$(ERRHAND_DBG)
endif
# To enable this option use: make ERRHAND_MIN_LEVEL=DBG_MIN_TRACE
ifneq ($(ERRHAND_MIN_LEVEL),)
CFLAGS_DEBUG += -DERRHAND_MIN_LEVEL=$(ERRHAND_MIN_LEVEL)
endif
# To enable this option use: make ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | \
# DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
#
# You can also OR the available subsytems to enable debug messages in just the
# those subsytems. See file errhand_opts.h for more information
ifneq ($(ERRHAND_SUBSYS_ON),)
CFLAGS_DEBUG += -DERRHAND_SUBSYS_ON=$(ERRHAND_SUBSYS_ON)
endif
# Debug flags -D<flasg_name>=<value>
CFLAGS_DEBUG += -g
# Specific platform Flags
CFLAGS_PLATFORM = -Wall -Wextra -Werror
LDFLAGS_PLATFORM =
# Libraries
LIBS =
# General library flags -L<libdir>
LFLAGS =
# Source directory
SRC_DIR = src
# Include directory
INCLUDE_DIR = include
# Include directories
INCLUDE_DIRS = -Iinclude -I/usr/local/include
# Merge all flags. We expect tghese variables to be appended to the possible
# command-line options
override CFLAGS += $(CFLAGS_USR) $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG) $(CPPFLAGS) $(CXXFLAGS)
override LDFLAGS += $(LFLAGS) $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBNAME)
.SECONDEXPANSION:
include $(SRC_DIR)/ops/ops.mk
# Library objects
$(LIBNAME)_OBJS_LIB = $(SRC_DIR)/ll_io_core.o $(SRC_DIR)/ll_io_dev_info.o $(SRC_DIR)/ll_io_endpoint.o \
$(SRC_DIR)/ll_io_err.o $(SRC_DIR)/ll_io_utils.o $(ll_io_ops_OBJS)
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBNAME)_OBJS = $(common_OBJS) $($(LIBNAME)_OBJS_LIB)
$(LIBNAME)_CODE_HEADERS = \
$(INCLUDE_DIR)/ll_io_classes.h \
$(INCLUDE_DIR)/ll_io_prelude.h \
$(INCLUDE_DIR)/ll_io.h \
$(INCLUDE_DIR)/ll_io_core.h \
$(INCLUDE_DIR)/ll_io_err.h \
$(INCLUDE_DIR)/ll_io_dev_info.h \
$(INCLUDE_DIR)/ll_io_utils.h \
$(INCLUDE_DIR)/ll_io_endpoint.h \
$(INCLUDE_DIR)/ll_io_pcie.h \
$(INCLUDE_DIR)/ll_io_eth_utils.h \
$(INCLUDE_DIR)/ll_io_eth.h \
$(INCLUDE_DIR)/hw/pcie_regs.h
$(LIBNAME)_HEADERS = $($(LIBNAME)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBNAME)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
LIB_SHARED_SUFFIX = .so
# Generate suitable names for libraries
TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
TARGET_SHARED = $(addsuffix $(LIB_SHARED_SUFFIX), $(OUT))
TARGET_SHARED_VER = $(addsuffix $(LIB_SHARED_SUFFIX).$(LIB_VER), $(OUT))
.PHONY: all clean mrproper install uninstall
# Avoid deletion of intermediate files, such as objects
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC) $(TARGET_SHARED_VER)
# Compile static library
%.a: $$($$*_OBJS)
$(AR) rcs $@ $^
# Compile dynamic library
%.so.$(LIB_VER): $$($$*_OBJS) $(OBJ_REVISION)
$(CC) $(LDFLAGS) -shared -fPIC -Wl,-soname,$@ -o $@ $^
# Pull in dependency info for *existing* .o files and don't complain if the
# corresponding .d file is not found
-include $(OBJS_all:.o=.d)
# Compile with position-independent objects.
# Autodependencies generatation by Scott McPeak, November 2001,
# from article "Autodependencies with GNU make"
%.o: %.c
$(CC) $(CFLAGS) $(INCLUDE_DIRS) -c $*.c -o $@
# create the dependency files "target: pre-requisites"
${CC} -MM $(CFLAGS) $(INCLUDE_DIRS) $*.c > $*.d
# Workaround to make objects in different folders have
# the correct target path. e.g., "dir/bar.o: dir/bar.c dir/foo.h"
# instead of "bar.o: dir/bar.c dir/foo.h"
@mv -f $*.d $*.d.tmp
@sed -e 's|.*:|$*.o:|' < $*.d.tmp > $*.d
# All prereqs listed will also become command-less,
# prereq-less targets. In this way, the prereq file will be
# treated as changed and the target will be rebuilt
# sed: strip the target (everything before colon)
# sed: remove any continuation backslashes
# fmt -1: list words one per line
# sed: strip leading spaces
# sed: add trailing colons
@sed -e 's/.*://' -e 's/\\$$//' < $*.d.tmp | fmt -1 | \
sed -e 's/^ *//' -e 's/$$/:/' >> $*.d
@rm -f $*.d.tmp
install:
$(foreach lib,$(TARGET_SHARED_VER),install -m 755 $(lib) $(PREFIX)/lib $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(PREFIX)/lib/$(lib) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),ln -sf $(lib).$(LIB_VER) $(PREFIX)/lib/$(lib).$(LIB_VER_MAJOR) $(CMDSEP))
$(foreach lib,$(TARGET_STATIC),install -m 755 $(lib) $(PREFIX)/lib $(CMDSEP))
$(foreach header,$($(LIBNAME)_HEADERS),install -m 755 $(header) $(PREFIX)/include $(CMDSEP))
uninstall:
$(foreach lib,$(TARGET_SHARED),rm -f $(PREFIX)/lib/$(lib).$(LIB_VER) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),rm -f $(PREFIX)/lib/$(lib) $(CMDSEP))
$(foreach lib,$(TARGET_SHARED),rm -f $(PREFIX)/lib/$(lib).$(LIB_VER_MAJOR) $(CMDSEP))
$(foreach lib,$(TARGET_STATIC),rm -f $(PREFIX)/lib/$(lib) $(CMDSEP))
$(foreach header,$(notdir $($(LIBNAME)_HEADERS)),rm -f \
$(PREFIX)/include/$(header) $(CMDSEP))
clean:
rm -f $(OBJS_all) $(OBJS_all:.o=.d)
mrproper: clean
rm -f *.a *.so.$(LIB_VER)
Project Dependencies:
liberrhand
Foreign Dependencies:
libPciDriver
#!/usr/bin/env bash
#######################################
# All of our Makefile options
#######################################
EXTRA_FLAGS=$1
#Select if we want to compile with debug mode on. Options are: y(es) or n(o)
ERRHAND_DBG=y
# Select the minimum debug verbosity. See liberrhand file errhand_opts.h for more info.
ERRHAND_MIN_LEVEL=DBG_LVL_INFO
# Select the subsytems which will have the debug on. See liberrhand file errhand_opts.h for more info.
ERRHAND_SUBSYS_ON='"(DBG_DEV_MNGR | DBG_DEV_IO | DBG_SM_IO | DBG_LIB_CLIENT | DBG_SM_PR | DBG_SM_CH | DBG_LL_IO | DBG_HAL_UTILS)"'
# Select the FMC ADC board type. Options are: passive or active
COMMAND_LIBBPMCLIENT="\
make \
${EXTRA_FLAGS} \
BOARD=${BOARD} \
ERRHAND_DBG=${ERRHAND_DBG} \
ERRHAND_MIN_LEVEL=${ERRHAND_MIN_LEVEL} \
ERRHAND_SUBSYS_ON='"${ERRHAND_SUBSYS_ON}"' && \
sudo make install"
COMMAND_ARRAY=(
"${COMMAND_LIBBPMCLIENT}"
)
for i in "${COMMAND_ARRAY[@]}"
do
echo "Executing: " $i
eval $i
# Check return value
rc=$?
if [[ $rc != 0 ]]; then
exit $rc
fi
done
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_H_
#define _LL_IO_H_
#include "ll_io_classes.h"
#endif
/*
* Copyright (C) 2014 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_CLASSES_H_
#define _LL_IO_CLASSES_H_
/* Set up environment for the application */
#include "ll_io_prelude.h"
/* External dependencies */
#include <convc.h>
#include <czmq.h>
/* BPM version macros for compile-time API detection */
#define LL_IO_VERSION_MAJOR 0
#define LL_IO_VERSION_MINOR 1
#define LL_IO_VERSION_PATCH 0
#define LL_IO_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
#define LL_IO_VERSION \
LL_IO_MAKE_VERSION(LL_IO_VERSION_MAJOR, LL_IO_VERSION_MINOR, \
LL_IO_VERSION_PATCH)
#if defined (__WINDOWS__)
# if defined LIBLL_IO_STATIC
# define LL_IO_EXPORT
# elif defined LIBLL_IO_EXPORTS
# define LL_IO_EXPORT __declspec(dllexport)
# else
# define LL_IO_EXPORT __declspec(dllimport)
# endif
#else
# define LL_IO_EXPORT
#endif
/* Opaque class structures to allow forward references */
/* Public API classes */
/* Opaque llio_dev_info_t structure */
typedef struct _llio_dev_info_t llio_dev_info_t;
/* Opaque llio_endpoint_t structure */
typedef struct _llio_endpoint_t llio_endpoint_t;
/* Opaque llio_t structure */
typedef struct _llio_t llio_t;
/* LL_IO */
#include "ll_io_err.h"
#include "ll_io_utils.h"
#include "ll_io_dev_info.h"
#include "ll_io_endpoint.h"
#include "ll_io_core.h"
/* LL_IO operations */
#include "ll_io_pcie.h"
#include "ll_io_eth_utils.h"
#include "ll_io_eth.h"
#endif
......@@ -5,8 +5,8 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_H_
#define _LL_IO_H_
#ifndef _LL_IO_CORE_H_
#define _LL_IO_CORE_H_
#ifdef __cplusplus
extern "C" {
......
......@@ -26,6 +26,8 @@ enum _llio_err_e {
LLIO_ERR_END /* End of enum marker */
};
typedef enum _llio_err_e llio_err_e;
/* Convert enumeration type to string */
const char * llio_err_str (llio_err_e err);
......
......@@ -20,6 +20,8 @@ enum _llio_eth_type_e {
END_ETH_SOCK = CONVC_TYPE_END
};
typedef enum _llio_eth_type_e llio_eth_type_e;
#define TCP_ETH_SOCK_STR "tcp"
#define UDP_ETH_SOCK_STR "udp"
#define INVALID_ETH_SOCK_STR "invalid"
......
/*
* Copyright (C) 2015 LNLS (www.lnls.br)
* Author: Lucas Russo <lucas.russo@lnls.br>
*
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _LL_IO_PRELUDE_H_
#define _LL_IO_PRELUDE_H_
/* External dependencies */
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#endif
......@@ -22,6 +22,8 @@ enum _llio_type_e {
END_DEV = CONVC_TYPE_END
};
typedef enum _llio_type_e llio_type_e;
#define GENERIC_DEV_STR "generic"
#define PCIE_DEV_STR "pcie"
#define ETH_DEV_STR "eth"
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -8,7 +8,7 @@
/* Error definitions and output stringification based on the work available
* at the libsllp project repository: https://github.com/brunoseivam/libsllp */
#include "bpm_server.h"
#include "ll_io.h"
static const char *llio_err [LLIO_ERR_END] =
{
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,7 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "bpm_server.h"
#include "ll_io.h"
/* PCIe specifics */
#include <pciDriver/lib/pciDriver.h>
......
ll_io_ops_DIR = $(SRC_DIR)/ll_io/ops
ll_io_ops_DIR = $(SRC_DIR)/ops
ll_io_ops_OBJS = $(ll_io_ops_DIR)/ll_io_pcie.o \
$(ll_io_ops_DIR)/ll_io_eth.o \
......
#!/usr/bin/env sh
#
# This script extracts the version from the project header file
#
# This script is based on CZMQ version.sh script located at:
# https://github.com/zeromq/czmq/blob/master/version.sh
project=$1
appendix="_classes"
if [ ! -f include/$project$appendix.h ]; then
echo "version.sh: error: could not open file include/$project$appendix.h" 1>&2
exit 1
fi
MAJOR=`egrep '^#define .*_VERSION_MAJOR +[0-9]+$' include/$project$appendix.h`
MINOR=`egrep '^#define .*_VERSION_MINOR +[0-9]+$' include/$project$appendix.h`
PATCH=`egrep '^#define .*_VERSION_PATCH +[0-9]+$' include/$project$appendix.h`
if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then
echo "version.sh: error: could not extract version from include/$project$appendix.h" 1>&2
exit 1
fi
MAJOR=`echo $MAJOR | awk '{ print $3 }'`
MINOR=`echo $MINOR | awk '{ print $3 }'`
PATCH=`echo $PATCH | awk '{ print $3 }'`
echo $MAJOR.$MINOR.$PATCH | tr -d '\n'
include $(SRC_DIR)/ll_io/ops/ops.mk
ll_io_DIR = $(SRC_DIR)/ll_io
ll_io_utils_OBJS = $(ll_io_DIR)/ll_io_utils.o
# Here we call <output_name>_core_OBJS as we need to add
# more objects to this target. This is done in the hal.mk
# makefile
ll_io_OBJS = $(ll_io_DIR)/ll_io.o \
$(ll_io_DIR)/ll_io_endpoint.o \
$(ll_io_DIR)/ll_io_dev_info.o \
$(ll_io_DIR)/ll_io_err.o \
$(ll_io_utils_OBJS) \
$(ll_io_ops_OBJS)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment