Commit de280f86 authored by Lucas Russo's avatar Lucas Russo

src/libs/libconvc/*: improve library structure to match zproject library

This does not use the zproject project
available in https://github.com/zeromq/zproject,
but matches more closely its structure.
parent 5af5c6f0
......@@ -13,10 +13,20 @@ MAKE ?= make
PWD = $(shell pwd)
LIBCONVC = libconvc
LIBNAME_RAW = convc
LIBNAME = lib$(LIBNAME_RAW)
# Config variables suitable for creating shared libraries
LIB_VER = $(shell ./version.sh $(LIBNAME_RAW))
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
CFLAGS_USR = -std=gnu99 -O2 -fPIC
# We expect tghese variables to be appended to the possible
# command-line options
override CPPFLAGS +=
......@@ -54,8 +64,13 @@ LIBS =
# General library flags -L<libdir>
LFLAGS =
# Source directory
SRC_DIR = src
# Include directory
INCLUDE_DIR = include
# Include directories
INCLUDE_DIRS = -I. -I../liberrhand
INCLUDE_DIRS = -Iinclude -I/usr/local/include
# Merge all flags. We expect tghese variables to be appended to the possible
# command-line options
......@@ -63,29 +78,37 @@ override CFLAGS += $(CFLAGS_USR) $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG) $(CPPFLAGS)
override LDFLAGS += $(LFLAGS) $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBCONVC)
OUT = $(LIBNAME)
.SECONDEXPANSION:
# Library objects
$(LIBCONVC)_OBJS_LIB = convc.o convc_err.o
$(LIBNAME)_OBJS_LIB = $(SRC_DIR)/convc_core.o $(SRC_DIR)/convc_err.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBCONVC)_OBJS = $(common_OBJS) $($(LIBCONVC)_OBJS_LIB)
$(LIBCONVC)_CODE_HEADERS =
$(LIBNAME)_OBJS = $(common_OBJS) $($(LIBNAME)_OBJS_LIB)
$(LIBNAME)_CODE_HEADERS = \
$(INCLUDE_DIR)/convc_classes.h \
$(INCLUDE_DIR)/convc_prelude.h \
$(INCLUDE_DIR)/convc.h \
$(INCLUDE_DIR)/convc_core.h \
$(INCLUDE_DIR)/convc_err.h
$(LIBCONVC)_HEADERS = $($(LIBCONVC)_OBJS_LIB:.o=.h) $($(LIBCONVC)_CODE_HEADERS)
$(LIBNAME)_HEADERS = $($(LIBNAME)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBCONVC)_OBJS)
OBJS_all = $(common_OBJS) $($(LIBNAME)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
LIB_SHARED_SUFFIX = .so
# Generate suitable names for static libraries
# 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
......@@ -93,12 +116,16 @@ TARGET_STATIC = $(addsuffix $(LIB_STATIC_SUFFIX), $(OUT))
.SECONDARY: $(OBJS_all)
# Makefile rules
all: $(TARGET_STATIC)
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)
......@@ -131,12 +158,23 @@ all: $(TARGET_STATIC)
@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
rm -f *.a *.so.$(LIB_VER)
......@@ -2,3 +2,4 @@ Project Dependencies:
liberrhand
Foreign Dependencies:
czmq
#!/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_CONVC="\
make \
${EXTRA_FLAGS} \
ERRHAND_DBG=${ERRHAND_DBG} \
ERRHAND_MIN_LEVEL=${ERRHAND_MIN_LEVEL} \
ERRHAND_SUBSYS_ON='"${ERRHAND_SUBSYS_ON}"' && \
sudo make install"
COMMAND_ARRAY=(
"${COMMAND_CONVC}"
)
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 _CONVC_H_
#define _CONVC_H_
#include "convc_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 _CONVC_CLASSES_H_
#define _CONVC_CLASSES_H_
/* Set up environment for the application */
#include "convc_prelude.h"
/* External dependencies */
#include <czmq.h>
#include <errhand.h>
/* version macros for compile-time API detection */
#define CONVC_VERSION_MAJOR 0
#define CONVC_VERSION_MINOR 1
#define CONVC_VERSION_PATCH 0
#define CONVC_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
#define CONVC_VERSION \
CONVC_MAKE_VERSION(CONVC_VERSION_MAJOR, CONVC_VERSION_MINOR, \
CONVC_VERSION_PATCH)
#if defined (__WINDOWS__)
# if defined LIBCONVC_STATIC
# define CONVC_EXPORT
# elif defined LIBCONVC_EXPORTS
# define CONVC_EXPORT __declspec(dllexport)
# else
# define CONVC_EXPORT __declspec(dllimport)
# endif
#else
# define CONVC_EXPORT
#endif
/* Opaque class structures to allow forward references */
/* Public API classes */
/* CONVC */
#include "convc_err.h"
#include "convc_core.h"
#endif
......@@ -5,11 +5,12 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _CONVC_H_
#define _CONVC_H_
#ifndef _CONVC_CORE_H_
#define _CONVC_CORE_H_
#include <inttypes.h>
#include "convc_err.h"
#ifdef __cplusplus
extern "C" {
#endif
#define CONVC_TYPE_END 0xFFFF
#define CONVC_TYPE_NAME_END ""
......@@ -30,4 +31,8 @@ char *convc_gen_type_to_str (int type, const convc_types_t *convc_types);
int convc_str_to_gen_type (const char *type_str,
const convc_types_t *convc_types);
#ifdef __cplusplus
}
#endif
#endif
......@@ -11,6 +11,10 @@
#ifndef _CONVC_ERR_H_
#define _CONVC_ERR_H_
#ifdef __cplusplus
extern "C" {
#endif
enum _convc_err_e
{
CONVC_SUCCESS = 0, /* No error */
......@@ -23,4 +27,8 @@ typedef enum _convc_err_e convc_err_e;
/* Convert enumeration type to string */
const char * convc_err_str (convc_err_e err);
#ifdef __cplusplus
}
#endif
#endif
/*
* 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 _CONVC_PRELUDE_H_
#define _CONVC_PRELUDE_H_
/* External dependencies */
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#endif
......@@ -5,14 +5,6 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <unistd.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <czmq.h>
#include "errhand.h"
#include "convc.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
......
......@@ -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 "convc_err.h"
#include "convc.h"
static const char *convc_err [CONVC_ERR_END] =
{
......
#!/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'
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