Commit 5af5c6f0 authored by Lucas Russo's avatar Lucas Russo

src/libs/libhutils/*: 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 475508e9
......@@ -13,13 +13,14 @@ MAKE ?= make
PWD = $(shell pwd)
LIBHUTILS = libhutils
LIBNAME_RAW = hutils
LIBNAME = lib$(LIBNAME_RAW)
# Config variables suitable for creating shared libraries
LIB_VER_MAJOR = 1
LIB_VER_MINOR = 0
LIB_VER_REVISION = 0
LIB_VER = $(LIB_VER_MAJOR).$(LIB_VER_MINOR).$(LIB_VER_REVISION)
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
......@@ -63,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
......@@ -72,23 +78,31 @@ override CFLAGS += $(CFLAGS_USR) $(CFLAGS_PLATFORM) $(CFLAGS_DEBUG) $(CPPFLAGS)
override LDFLAGS += $(LFLAGS) $(LDFLAGS_PLATFORM)
# Output library names
OUT = $(LIBHUTILS)
OUT = $(LIBNAME)
.SECONDEXPANSION:
# Library objects
$(LIBHUTILS)_OBJS_LIB = hutils_utils.o hutils_math.o hutils_err.o
$(LIBNAME)_OBJS_LIB = $(SRC_DIR)/hutils_utils.o $(SRC_DIR)/hutils_math.o \
$(SRC_DIR)/hutils_err.o
# Objects common for this library
common_OBJS =
# Objects for each version of library
$(LIBHUTILS)_OBJS = $(common_OBJS) $($(LIBHUTILS)_OBJS_LIB)
$(LIBHUTILS)_CODE_HEADERS = hutils.h
$(LIBNAME)_OBJS = $(common_OBJS) $($(LIBNAME)_OBJS_LIB)
$(LIBNAME)_CODE_HEADERS = \
$(INCLUDE_DIR)/hutils_classes.h \
$(INCLUDE_DIR)/hutils_prelude.h \
$(INCLUDE_DIR)/hutils.h \
$(INCLUDE_DIR)/hutils_core.h \
$(INCLUDE_DIR)/hutils_err.h \
$(INCLUDE_DIR)/hutils_math.h \
$(INCLUDE_DIR)/hutils_utils.h
$(LIBHUTILS)_HEADERS = $($(LIBHUTILS)_OBJS_LIB:.o=.h) $($(LIBHUTILS)_CODE_HEADERS)
$(LIBNAME)_HEADERS = $($(LIBNAME)_CODE_HEADERS)
OBJS_all = $(common_OBJS) $($(LIBHUTILS)_OBJS)
OBJS_all = $(common_OBJS) $($(LIBNAME)_OBJS)
# Libraries suffixes
LIB_STATIC_SUFFIX = .a
......@@ -152,12 +166,15 @@ install:
$(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)
......
#!/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 _HUTILS_H_
#define _HUTILS_H_
#include "hutils_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 _HUTILS_CLASSES_H_
#define _HUTILS_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 HUTILS_VERSION_MAJOR 0
#define HUTILS_VERSION_MINOR 1
#define HUTILS_VERSION_PATCH 0
#define HUTILS_MAKE_VERSION(major, minor, patch) \
((major) * 10000 + (minor) * 100 + (patch))
#define HUTILS_VERSION \
HUTILS_MAKE_VERSION(HUTILS_VERSION_MAJOR, HUTILS_VERSION_MINOR, \
HUTILS_VERSION_PATCH)
#if defined (__WINDOWS__)
# if defined LIBHUTILS_STATIC
# define HUTILS_EXPORT
# elif defined LIBHUTILS_EXPORTS
# define HUTILS_EXPORT __declspec(dllexport)
# else
# define HUTILS_EXPORT __declspec(dllimport)
# endif
#else
# define HUTILS_EXPORT
#endif
/* Opaque class structures to allow forward references */
/* Public API classes */
/* HUTILS */
#include "hutils_err.h"
#include "hutils_core.h"
#include "hutils_math.h"
#include "hutils_utils.h"
#endif
......@@ -6,12 +6,8 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HUTILS_
#define _HUTILS_
#include "hutils_err.h"
#include "hutils_math.h"
#include "hutils_utils.h"
#ifndef _HUTILS_CORE_H_
#define _HUTILS_CORE_H_
#endif
......@@ -11,6 +11,10 @@
#ifndef _HUTILS_ERR_H_
#define _HUTILS_ERR_H_
#ifdef __cplusplus
extern "C" {
#endif
enum _hutils_err_e
{
HUTILS_SUCCESS = 0, /* No error */
......@@ -24,4 +28,8 @@ typedef enum _hutils_err_e hutils_err_e;
/* Convert enumeration type to string */
const char * hutils_err_str (hutils_err_e err);
#ifdef __cplusplus
}
#endif
#endif
......@@ -8,8 +8,9 @@
#ifndef _HUTILS_MATH_H_
#define _HUTILS_MATH_H_
#include <math.h>
#include <inttypes.h>
#ifdef __cplusplus
extern "C" {
#endif
#define POW_2_28 268435456.0
......@@ -25,4 +26,8 @@ uint64_t hutils_div_u64 (uint64_t dividend, uint32_t divisor);
uint64_t hutils_div64_u64 (uint64_t dividend, uint64_t divisor);
int64_t hutils_div64_s64 (int64_t dividend, int64_t divisor);
#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 _HUTILS_PRELUDE_H_
#define _HUTILS_PRELUDE_H_
/* External dependencies */
#include <inttypes.h>
#include <sys/types.h>
#include <stdbool.h>
#endif
......@@ -5,11 +5,12 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#ifndef _HUTILS_H_
#define _HUTILS_H_
#ifndef _HUTILS_UTILS_H_
#define _HUTILS_UTILS_H_
#include <inttypes.h>
#include <stddef.h>
#ifdef __cplusplus
extern "C" {
#endif
/******************* Configuration file property names ************************/
......@@ -105,4 +106,8 @@ int hutils_copy_str (char *dest, const char *src, size_t size);
* and store them in hash table in the form <property name / property value> */
hutils_err_e hutils_get_hints (zconfig_t *root_cfg, zhashx_t *hints_h);
#ifdef __cplusplus
}
#endif
#endif
......@@ -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 "hutils_err.h"
#include "hutils.h"
static const char *hutils_err [HUTILS_ERR_END] =
{
......
......@@ -5,8 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include "hutils_math.h"
#include <inttypes.h>
#include "hutils.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
......@@ -5,14 +5,7 @@
* Released according to the GNU LGPL, version 3 or any later version.
*/
#include <stdio.h>
#include <sys/wait.h> /* waitpid */
#include <errno.h> /* perror */
#include <czmq.h>
#include "hutils.h"
#include "hutils_err.h"
#include "errhand.h"
/* Undef ASSERT_ALLOC to avoid conflicting with other ASSERT_ALLOC */
#ifdef ASSERT_TEST
......
#!/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