build: update for standalone pkgconfig deployment
This commit is contained in:
parent
817eb50efc
commit
379e652e83
23
Makefile.am
23
Makefile.am
@ -4,10 +4,14 @@
|
||||
ACLOCAL_AMFLAGS = -I m4
|
||||
|
||||
AM_CXXFLAGS = $(BOOST_CPPFLAGS) $(ZLIB_CFLAGS)
|
||||
AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
###############################################################################
|
||||
## Source definitions
|
||||
|
||||
pkgincludedir = $(includedir)/cruft/util
|
||||
pkglibdir = $(libdir)/cruft
|
||||
|
||||
UTIL_FILES = \
|
||||
adapter.hpp \
|
||||
adapter.cpp \
|
||||
@ -147,9 +151,6 @@ UTIL_FILES = \
|
||||
hash/sha2.hpp \
|
||||
hash/wang.hpp \
|
||||
hash/wang.ipp \
|
||||
image/buffer.cpp \
|
||||
image/buffer.hpp \
|
||||
image/buffer.ipp \
|
||||
introspection.cpp \
|
||||
introspection.hpp \
|
||||
io.cpp \
|
||||
@ -350,6 +351,7 @@ UTIL_FILES += \
|
||||
win32/registry.cpp
|
||||
endif
|
||||
|
||||
|
||||
###############################################################################
|
||||
## Local build rules
|
||||
CLEANFILES = json.cpp version.cpp ip.cpp uri.cpp
|
||||
@ -362,15 +364,17 @@ SUFFIXES = .cpp .cpp.rl
|
||||
|
||||
###############################################################################
|
||||
## Library definition
|
||||
lib_LIBRARIES = libutil.a
|
||||
libutil_a_SOURCES = $(UTIL_FILES)
|
||||
libutil_a_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
lib_LIBRARIES = libcruft-util.a
|
||||
libcruft_util_a_SOURCES = $(UTIL_FILES)
|
||||
libcruft_util_a_CXXFLAGS = $(AM_CXXFLAGS)
|
||||
|
||||
nobase_pkginclude_HEADERS = $(filter %.hpp %.ipp, $(UTIL_FILES))
|
||||
pkgconfigdir = $(libdir)/pkgconfig
|
||||
pkgconfig_DATA = libcruft-util.pc
|
||||
|
||||
###############################################################################
|
||||
## Utility programs
|
||||
|
||||
AM_DEFAULT_SOURCE_EXT = .cpp
|
||||
|
||||
AM_LDFLAGS = $(BOOST_LDFLAGS) -lrt
|
||||
|
||||
bin_PROGRAMS = \
|
||||
@ -382,7 +386,7 @@ bin_PROGRAMS = \
|
||||
|
||||
noinst_PROGRAMS = tools/scratch
|
||||
|
||||
LDADD = $(top_builddir)/libutil.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(ZLIB_LIBS)
|
||||
LDADD = $(top_builddir)/libcruft-util.a $(BOOST_FILESYSTEM_LIB) $(BOOST_SYSTEM_LIB) $(ZLIB_LIBS)
|
||||
|
||||
|
||||
##-----------------------------------------------------------------------------
|
||||
@ -418,7 +422,6 @@ TEST_BIN = \
|
||||
test/hmac \
|
||||
test/hotp \
|
||||
test/hton \
|
||||
test/image \
|
||||
test/introspection \
|
||||
test/ip \
|
||||
test/json_types \
|
||||
|
@ -29,6 +29,7 @@ AM_SILENT_RULES([yes])
|
||||
|
||||
AC_CONFIG_HEADERS([config.h])
|
||||
|
||||
AX_CHECK_GNU_MAKE
|
||||
|
||||
###############################################################################
|
||||
## Architecture features
|
||||
@ -60,6 +61,13 @@ AS_IF([test "x$ac_cv_search_clock_gettime" == "x-*"], [
|
||||
AX_APPEND_LINK_FLAGS([$ac_cv_search_clock_gettime], [], [-Werror])
|
||||
])
|
||||
|
||||
## Use dynamic loader if present (for util::library)
|
||||
AS_IF(
|
||||
[test "x${host_os}" != "xmingw32"],
|
||||
[AC_SEARCH_LIBS([dlopen], [dl])]
|
||||
)
|
||||
|
||||
|
||||
###############################################################################
|
||||
## Debug features
|
||||
|
||||
@ -111,6 +119,7 @@ AX_APPEND_FLAG([-include config.h])
|
||||
AC_CONFIG_FILES([
|
||||
Doxyfile
|
||||
Makefile
|
||||
libcruft-util.pc
|
||||
])
|
||||
AC_CONFIG_FILES([test/json-parse], [chmod a+x test/json-parse])
|
||||
AC_CONFIG_FILES([test/json-schema], [chmod a+x test/json-schema])
|
||||
|
211
image/buffer.cpp
211
image/buffer.cpp
@ -1,211 +0,0 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#include "./buffer.hpp"
|
||||
|
||||
#include "../debug.hpp"
|
||||
|
||||
using util::image::buffer;
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
buffer<C,T>::buffer (util::extentu<2> _size):
|
||||
m_size (_size),
|
||||
m_stride (C, C * _size.w),
|
||||
m_data (std::make_unique<T[]> (_size.area () * C))
|
||||
{ ; }
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
template <typename U>
|
||||
buffer<C,U>
|
||||
buffer<C,T>::alloc (void) const
|
||||
{
|
||||
return buffer<C,U> (m_size);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <typename T, typename U>
|
||||
static U
|
||||
rescale (T v)
|
||||
{
|
||||
return v * sizeof (U) / sizeof (T);
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
template <typename U>
|
||||
util::image::buffer<C,U>
|
||||
util::image::buffer<C,T>::clone (void) const
|
||||
{
|
||||
auto out = alloc<U> ();
|
||||
|
||||
auto func = renormalise<T,U>;
|
||||
std::transform (begin (), end (), out.begin (), func);
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t C, typename T>
|
||||
const T&
|
||||
buffer<C,T>::operator[] (point<2,size_t> p) const
|
||||
{
|
||||
CHECK (util::all (p < extent ()));
|
||||
|
||||
return begin ()[offset (p)];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
T&
|
||||
buffer<C,T>::operator[] (point<2,size_t> p)
|
||||
{
|
||||
CHECK (util::all (p < extent ()));
|
||||
|
||||
return begin ()[offset (p)];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T&
|
||||
buffer<C,T>::operator[] (size_t idx) const
|
||||
{
|
||||
CHECK_LT (idx, size ());
|
||||
|
||||
return begin ()[idx];
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
T&
|
||||
buffer<C,T>::operator[] (size_t idx)
|
||||
{
|
||||
CHECK_LT (idx, size ());
|
||||
|
||||
return begin ()[idx];
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
template <size_t C, typename T>
|
||||
T*
|
||||
buffer<C,T>::data (void)
|
||||
{
|
||||
return begin ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
T*
|
||||
buffer<C,T>::begin (void)
|
||||
{
|
||||
return m_data.get ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
T*
|
||||
buffer<C,T>::end (void)
|
||||
{
|
||||
return begin () + m_size.back () * m_stride.back ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T*
|
||||
buffer<C,T>::begin (void) const
|
||||
{
|
||||
return cbegin ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T*
|
||||
buffer<C,T>::end (void) const
|
||||
{
|
||||
return cend ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T*
|
||||
buffer<C,T>::data (void) const
|
||||
{
|
||||
return begin ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T*
|
||||
buffer<C,T>::cbegin (void) const
|
||||
{
|
||||
return m_data.get ();
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
const T*
|
||||
buffer<C,T>::cend (void) const
|
||||
{
|
||||
return cbegin () + m_size.back () * m_stride.back ();
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define INSTANTIATE_C_T_U(C,T,U) \
|
||||
template util::image::buffer<C,U> util::image::buffer<C,T>::alloc (void) const; \
|
||||
template util::image::buffer<C,U> util::image::buffer<C,T>::clone (void) const; \
|
||||
template util::image::buffer<C,U> util::image::buffer<C,T>::cast (void) const;
|
||||
|
||||
#define INSTANTIATE_C_T(C,T) \
|
||||
template struct util::image::buffer<C,T>; \
|
||||
INSTANTIATE_C_T_U(C,T,uint8_t) \
|
||||
INSTANTIATE_C_T_U(C,T,uint16_t) \
|
||||
INSTANTIATE_C_T_U(C,T,uint32_t) \
|
||||
INSTANTIATE_C_T_U(C,T,uint64_t) \
|
||||
INSTANTIATE_C_T_U(C,T,float) \
|
||||
INSTANTIATE_C_T_U(C,T,double)
|
||||
|
||||
|
||||
#define INSTANTIATE_C(C) \
|
||||
INSTANTIATE_C_T(C,uint8_t) \
|
||||
INSTANTIATE_C_T(C,uint16_t) \
|
||||
INSTANTIATE_C_T(C,uint32_t) \
|
||||
INSTANTIATE_C_T(C,uint64_t) \
|
||||
INSTANTIATE_C_T(C,float) \
|
||||
INSTANTIATE_C_T(C,double)
|
||||
|
||||
INSTANTIATE_C(1)
|
||||
INSTANTIATE_C(2)
|
||||
INSTANTIATE_C(3)
|
||||
INSTANTIATE_C(4)
|
@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifndef __UTIL_IMAGE_BUFFER_HPP
|
||||
#define __UTIL_IMAGE_BUFFER_HPP
|
||||
|
||||
#include "../extent.hpp"
|
||||
#include "../point.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace util { namespace image {
|
||||
template <size_t C, typename T>
|
||||
struct buffer {
|
||||
typedef T value_type;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
buffer (util::extentu<2>);
|
||||
buffer (util::extentu<2>, std::unique_ptr<T[]> &&data);
|
||||
|
||||
buffer (const buffer&) = delete;
|
||||
buffer (buffer &&) = default;
|
||||
buffer& operator= (const buffer&) = default;
|
||||
buffer& operator= (buffer&&) = default;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
/// allocate and return a buffer of the same dimensions. contents are undefined.
|
||||
template <typename U = T> buffer<C,U> alloc (void) const;
|
||||
|
||||
/// allocate and return a buffer with the same contents
|
||||
template <typename U = T> buffer<C,U> clone (void) const;
|
||||
template <typename U> buffer<C,U> cast (void) const { return clone<U> (); }
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
constexpr extent2u extent (void) const;
|
||||
constexpr vector2u stride (void) const;
|
||||
constexpr size_t size (void) const; // elements allocated
|
||||
|
||||
constexpr bool is_packed (void) const;
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
constexpr size_t offset (point<2,size_t>) const;
|
||||
|
||||
const T& operator[] (point<2,size_t>) const;
|
||||
T& operator[] (point<2,size_t>);
|
||||
|
||||
const T& operator[] (size_t) const;
|
||||
T& operator[] (size_t);
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
T* begin (void);
|
||||
T* end (void);
|
||||
T* data (void);
|
||||
|
||||
const T* begin (void) const;
|
||||
const T* end (void) const;
|
||||
const T* data (void) const;
|
||||
|
||||
const T* cbegin (void) const;
|
||||
const T* cend (void) const;
|
||||
|
||||
private:
|
||||
util::extent2u m_size;
|
||||
util::vector2u m_stride;
|
||||
std::unique_ptr<T[]> m_data;
|
||||
};
|
||||
} }
|
||||
|
||||
#include "./buffer.ipp"
|
||||
|
||||
#endif
|
@ -1,66 +0,0 @@
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Copyright 2011-2015 Danny Robson <danny@nerdcruft.net>
|
||||
*/
|
||||
|
||||
#ifdef __UTIL_IMAGE_BUFFER_IPP
|
||||
#error
|
||||
#endif
|
||||
#define __UTIL_IMAGE_BUFFER_IPP
|
||||
|
||||
namespace util { namespace image {
|
||||
//-------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
constexpr extent2u
|
||||
buffer<C,T>::extent (void) const
|
||||
{
|
||||
return m_size;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
constexpr vector2u
|
||||
buffer<C,T>::stride (void) const
|
||||
{
|
||||
return m_stride;
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
constexpr size_t
|
||||
buffer<C,T>::offset (point<2,size_t> p) const
|
||||
{
|
||||
return dot (stride (), p);
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
constexpr size_t
|
||||
buffer<C,T>::size (void) const
|
||||
{
|
||||
return extent ().back () * stride ().back ();
|
||||
}
|
||||
|
||||
|
||||
//-------------------------------------------------------------------------
|
||||
template <size_t C, typename T>
|
||||
constexpr bool
|
||||
buffer<C,T>::is_packed (void) const
|
||||
{
|
||||
return stride ().back () * extent ().back () == size ();
|
||||
}
|
||||
} }
|
11
libcruft-util.pc.in
Normal file
11
libcruft-util.pc.in
Normal file
@ -0,0 +1,11 @@
|
||||
prefix=@prefix@
|
||||
exec_prefix=@exec_prefix@
|
||||
libdir=@libdir@
|
||||
includedir=@includedir@
|
||||
|
||||
Name: libcruft-util
|
||||
Description: A simple utility library in C++
|
||||
URL: http://nerdcruft.net/
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lcruft-util @BOOST_LDFLAGS@ @BOOST_FILESYSTEM_LIB@ @BOOST_SYSTEM_LIB@ -lrt
|
||||
Cflags: -I${includedir}/cruft @BOOST_CPPFLAGS@
|
@ -1,33 +0,0 @@
|
||||
#include "image/buffer.hpp"
|
||||
#include "tap.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
util::TAP::logger tap;
|
||||
|
||||
constexpr size_t W = 64;
|
||||
constexpr size_t H = 128;
|
||||
util::image::buffer<1,uint16_t> img ({W, H});
|
||||
|
||||
if (!img.is_packed ())
|
||||
tap.skip ("linear position probe requires packed image allocation");
|
||||
else {
|
||||
// write out sequential values at each pixel, row-major
|
||||
size_t i = 0;
|
||||
for (size_t y = 0; y < H; ++y)
|
||||
for (size_t x = 0; x < W; ++x)
|
||||
img[{x,y}] = i++;
|
||||
|
||||
// check pixel values are sequential in row-major order
|
||||
bool success = true;
|
||||
for (size_t j = 0; j < i; ++j)
|
||||
success = success && img[j] == j;
|
||||
|
||||
tap.expect (success, "linear position probe");
|
||||
}
|
||||
|
||||
return tap.status ();
|
||||
}
|
Loading…
Reference in New Issue
Block a user