Commit fa5571d6 by Maarten L. Hekkelman

new standard layout

parent 6aca42d1
......@@ -29,20 +29,18 @@ firstTarget: all
CXX = @CXX@
CXXFLAGS = @CXXFLAGS@ @CPPFLAGS@ @BOOST_CPPFLAGS@ @PTHREAD_CFLAGS@
LDFLAGS = @LDFLAGS@ @BOOST_LDFLAGS@ @PTHREAD_CFLAGS@
LIBS = -lcif++ \
LIBS = @LIBS@ \
@BOOST_IOSTREAMS_LIB@ \
@BOOST_THREAD_LIB@ \
@BOOST_REGEX_LIB@ \
@BOOST_PROGRAM_OPTIONS_LIB@ \
@BOOST_DATE_TIME_LIB@ \
-lboost_timer -lboost_chrono \
-Wl,-Bstatic -lstdc++ -Wl,-Bdynamic \
@LIBS@
@BOOST_DATE_TIME_LIB@
prefix = @prefix@
exec_prefix = @exec_prefix@
libdir = @libdir@
includedir = @includedir@
bindir = @bindir@
datarootdir = @datarootdir@
datadir = @datadir@
ifneq "$(CHECK_CONFIG)" ""
GNUmakefile: config.status GNUmakefile.in
$(SHELL) ./config.status
......@@ -53,24 +51,18 @@ config.status: configure
configure: configure.ac
autoconf
endif
# main build variables
CXXFLAGS += -Wall -Wno-multichar
PACKAGES +=
ifneq ($(PACKAGES),)
CXXFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --cflags $(PACKAGES))
LDFLAGS += $(shell PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) pkg-config --libs $(PACKAGES) )
endif
DATADIR = $(datadir)/@PACKAGE_NAME@
LDFLAGS += -static-libgcc
DEFINES += DATADIR='"$(DATADIR)"'
# Use the DEBUG flag to build debug versions of the code
DEBUG = @DEBUG@
VERSION = @PACKAGE_VERSION@
DEFINES += VERSION='"$(VERSION)"'
ifeq "$(DEBUG)" "1"
DEFINES += DEBUG
CXXFLAGS += -g -O0
......@@ -81,13 +73,9 @@ DEFINES += NDEBUG
endif
MRC = @MRC@
USE_RSRC = @USE_RSRC@
CIFPP_RSRC = @CIFPP_RSRC@
ifneq "$(MRC)" ""
DEFINES += USE_RSRC
endif
# targets
VPATH += src:test
......@@ -102,24 +90,55 @@ endif
$(OBJDIR):
mkdir -p $(OBJDIR)
APPLICATION = @PACKAGE_NAME@
$(OBJDIR)/%.o: %.cpp | $(OBJDIR)
@ echo ">>" $<
@ $(CXX) -MD -c -o $@ $< $(CFLAGS) $(CXXFLAGS)
OBJECTS = $(APPLICATION:%=$(OBJDIR)/%.o)
COMMON_OBJECTS = pr-main.o
ifneq "$(MRC)" ""
OBJECTS += $(APPLICATION:%=$(OBJDIR)/%_rsrc.o)
$(OBJDIR)/pr-main.o: src/revision.hpp
$(OBJDIR)/$(APPLICATION)_rsrc.o: $(wildcard $(CIFPP_RSRC)/dictionaries/*) rsrc/version.txt
$(MRC) -o $@ $(CIFPP_RSRC)/dictionaries rsrc/version.txt
ifneq "$(USE_RSRC)" "0"
COMMON_RSRC = @CIFPP_RSRC@/dictionaries
endif
-include $(OBJECTS:%.o=%.d)
# The program rules
$(OBJECTS:.o=.d):
# disabled for now: centrifuge map-maker
PROGRAMS = dssp
$(OBJDIR)/%.o: %.cpp | $(OBJDIR) GNUmakefile
@ echo ">>" $<
@ $(CXX) -MD -c -o $@ $< $(CFLAGS) $(CXXFLAGS)
define PROGRAM_template =
$(1)_OBJECTS += $(1).o $(COMMON_OBJECTS)
ifneq "$(USE_RSRC)" "0"
$(1)_OBJECTS += $(1).o $(1)_rsrc.o
$$(OBJDIR)/$(1)_rsrc.o: $$($(1)_RSRC) $$(COMMON_RSRC)
$(MRC) -o $$@ $$^
endif
$(1): $$($(1)_OBJECTS:%=$(OBJDIR)/%)
endef
$(foreach program,$(PROGRAMS),$(eval $(call PROGRAM_template,$(program))))
$(PROGRAMS):
@ echo '->' $@
@ $(CXX) -o $@ $^ $(CXXFLAGS) $(LDFLAGS) $(LIBS)
OBJECTS = $(sort $(foreach program,$(PROGRAMS),$($(program)_OBJECTS)))
$(OBJDIR)/%.d: $(OBJDIR)/%.o
-include $(OBJECTS:%.o=$(OBJDIR)/%.d)
.PHONY: clean all
clean:
rm -rf $(PROGRAMS) $(OBJDIR)/* $(REVISION_FILE)
all: $(PROGRAMS)
REVISION = $(shell git log --pretty=format:%h --max-count=1)
REVISION_FILE = version-info-$(REVISION).txt
......@@ -129,31 +148,27 @@ $(REVISION_FILE): $(OBJDIR) src
git describe --match=build --dirty > $@
git log --pretty=medium --date=iso8601 -1 >> $@
src/revision.hpp: $(REVISION_FILE)
echo 'const char kRevision[] = R"(' > $@
cat $? >> $@
echo ')";' >> $@
rsrc:
@ mkdir -p $@
rsrc/version.txt: $(REVISION_FILE) | rsrc
cp $? $@
all: $(APPLICATION)
.PHONY: all
$(APPLICATION): %: $(OBJECTS)
@ echo '->' $@
@ $(CXX) -o $@ $^ $(LDFLAGS) $(LIBS)
.PHONY: clean
clean:
rm -rf $(OBJDIR)/* $(APPLICATION)
.PHONY: distclean
distclean: clean
rm -f config.status config.cache config.log configure.lineno config.status.lineno
rm -f GNUmakefile
.PHONY: install
install: $(PROGRAMS)
for p in $(PROGRAMS); do install -D $$p $(bindir)/$$p; done
for d in mmcif_ddl.dic mmcif_pdbx.dic; do \
install -D -m644 $(CIFPP_RSRC)/dictionaries/$$d $(DATADIR)/dictionaries/$$d; \
done
.PHONY: FORCE
FORCE:
.PHONY: test
test:
echo $(wildcard $(CIFPP_RSRC)/dictionaries/*)
@ echo $(OBJECTS)
AC_PREREQ([2.69])
AC_INIT([dssp], 4.0, [m.hekkelman@nki.nl])
dnl Switch to a C++ compiler, and check if it works.
AC_LANG(C++)
AX_CXX_COMPILE_STDCXX_17([noext])
AX_CHECK_COMPILE_FLAG([-fstandalone-debug],
[
CXXFLAGS="$CXXFLAGS -fstandalone-debug"
] , , [-Werror])
AX_CHECK_COMPILE_FLAG([-fstandalone-debug], [ CXXFLAGS="$CXXFLAGS -fstandalone-debug" ], , [-Werror])
AC_CONFIG_SRCDIR([src/dssp.cpp])
AC_CONFIG_AUX_DIR(config)
dnl AC_CONFIG_MACRO_DIR([config/m4])
AC_CONFIG_MACRO_DIR([config/m4])
AC_CONFIG_HEADERS([src/config.hpp])
AC_PREFIX_DEFAULT(/usr/local)
AC_PROG_INSTALL
AC_ARG_VAR([DEBUG], [Build a debug version of the application])
AX_PTHREAD
AC_PATH_PROG([PKG_CONFIG], [pkg-config])
AC_ARG_VAR([DEBUG], [Build a debug version of the application])
AC_ARG_VAR([MRC], [Specify a location for the mrc executable])
......@@ -29,24 +29,20 @@ if test "x$MRC" = "x"; then
fi
if test "x$MRC" = "x"; then
AC_MSG_ERROR([mrc not found, the application will be built without resources])
AC_MSG_WARN([The mrc application was not found, not using resources.])
fi
AX_PTHREAD
AC_ARG_ENABLE(
resources,
[AS_HELP_STRING([--disable-resources], [Do not use mrc to store data in resources])])
AC_ARG_WITH([cif++],
AS_HELP_STRING([--with-cif++=@<:@location@:>@],
[Use the cif++ library as specified.]),
[
CPPFLAGS="$CPPFLAGS -I ${withval}/include"
CXXFLAGS="$CXXFLAGS -I ${withval}/include"
LDFLAGS="$LDFLAGS -L${withval}/.libs"
AC_SUBST([CIFPP_RSRC], [${withval}/rsrc])
])
USE_RSRC=0
AS_IF([test "x$enable_resources" != "xno"], [
USE_RSRC=1
])
AC_SUBST([USE_RSRC], [$USE_RSRC])
AX_CHECK_LIBRARY([LIBCIFPP], [cif++/Config.hpp], [cif++],
[],
[AC_MSG_ERROR([libcif++ not found - cannot continue])])
AC_DEFINE_UNQUOTED([USE_RSRC], [$USE_RSRC], [Use mrc to store resources])
AC_CHECK_HEADER([filesystem], [], [AC_MSG_ERROR([The file <filesystem> is missing, perhaps you should install a more recent libstdc++ implementation.])])
......@@ -71,11 +67,25 @@ AC_TRY_LINK(
AX_BOOST_BASE([1.65.1], [], [AC_MSG_ERROR([Could not find a recent version of boost])])
AX_BOOST_IOSTREAMS
AX_BOOST_THREAD
AX_BOOST_REGEX
AX_BOOST_PROGRAM_OPTIONS
AX_BOOST_DATE_TIME
AC_ARG_WITH([cif++],
AS_HELP_STRING([--with-cif++=@<:@location@:>@],
[Use the cif++ library as specified.]),
[
CPPFLAGS="$CPPFLAGS -I ${withval}/include"
CXXFLAGS="$CXXFLAGS -I ${withval}/include"
LDFLAGS="$LDFLAGS -L${withval}/.libs"
LIBS="$LIBS -lcif++"
AC_SUBST([CIFPP_RSRC], [${withval}/rsrc])
AC_SUBST([CIFPP_LIB], [${withval}/.libs/libcif++.la])
])
AX_CHECK_LIBRARY([LIBCIFPP], [cif++/Config.hpp], [cif++],
[],
[AC_MSG_ERROR([libcif++ not found - cannot continue])])
AX_CHECK_LIBRARY([LIBZ], [zlib.h], [z],
[ LIBS="$LIBS -lz" ],
[AC_MSG_ERROR([libz not found - compressed files not supported])])
......@@ -83,12 +93,5 @@ AX_CHECK_LIBRARY([LIBBZ2], [bzlib.h], [bz2],
[ LIBS="$LIBS -lbz2"],
[AC_MSG_ERROR([libbz2 not found - compressed files not supported])])
AC_SEARCH_LIBS([dladdr1], [dl],
[
AC_DEFINE([HAVE_DLADDR], 1, [Define if the system has dladdr])
], [], [])
AC_SUBST([HAVE_DLADDR])
dnl Process Makefile.in to create Makefile
AC_OUTPUT([GNUmakefile])
......@@ -24,9 +24,12 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dssp.hpp"
#include <exception>
#include <iostream>
#include <fstream>
#include <filesystem>
#include <boost/format.hpp>
#include <boost/date_time/gregorian/formatters.hpp>
......@@ -36,9 +39,6 @@
#include <cif++/Secondary.hpp>
#include <cif++/CifUtils.hpp>
#include <cif++/Cif2PDB.hpp>
#include <cif++/FixDMC.hpp>
#include <zeep/streambuf.hpp>
#include <boost/program_options.hpp>
#include <boost/iostreams/filter/gzip.hpp>
......@@ -49,78 +49,7 @@ namespace fs = std::filesystem;
namespace io = boost::iostreams;
namespace po = boost::program_options;
// --------------------------------------------------------------------
// recursively print exception whats:
void print_what (const std::exception& e)
{
std::cerr << e.what() << std::endl;
try
{
std::rethrow_if_nested(e);
}
catch (const std::exception& nested)
{
std::cerr << " >> ";
print_what(nested);
}
}
// --------------------------------------------------------------------
namespace {
std::string gVersionNr, gVersionDate, VERSION_STRING;
}
void load_version_info()
{
const std::regex
rxVersionNr(R"(build-(\d+)-g[0-9a-f]{7}(-dirty)?)"),
rxVersionDate(R"(Date: +(\d{4}-\d{2}-\d{2}).*)");
auto version = cif::rsrc_loader::load("version.txt");
if (not version)
VERSION_STRING = "unknown version, version resource is missing";
else
{
zeep::char_streambuf buffer(version.data(), version.size());
std::istream is(&buffer);
std::string line;
while (getline(is, line))
{
std::smatch m;
if (std::regex_match(line, m, rxVersionNr))
{
gVersionNr = m[1];
if (m[2].matched)
gVersionNr += '*';
continue;
}
if (regex_match(line, m, rxVersionDate))
{
gVersionDate = m[1];
continue;
}
}
if (not VERSION_STRING.empty())
VERSION_STRING += "\n";
VERSION_STRING += gVersionNr + " " + gVersionDate;
}
}
std::string get_version_nr()
{
return gVersionNr;
}
std::string get_version_date()
{
return gVersionDate;
}
extern std::string VERSION_STRING;
// --------------------------------------------------------------------
......@@ -465,7 +394,7 @@ void annotateDSSP(mmcif::Structure& structure, const mmcif::DSSP& dssp, std::ost
}
}
db.add_software("dssp " VERSION, "other", get_version_nr(), get_version_date());
db.add_software("dssp " PACKAGE_VERSION, "other", get_version_nr(), get_version_date());
db.write(os);
......@@ -677,7 +606,7 @@ void annotateDSSP(mmcif::Structure& structure, const mmcif::DSSP& dssp, std::ost
// --------------------------------------------------------------------
int d_main(int argc, const char* argv[])
int pr_main(int argc, char* argv[])
{
using namespace std::literals;
......@@ -726,7 +655,7 @@ int d_main(int argc, const char* argv[])
if (vm.count("version"))
{
std::cout << argv[0] << ' ' << VERSION " version " << VERSION_STRING << std::endl;
std::cout << argv[0] << ' ' << PACKAGE_VERSION " version " << VERSION_STRING << std::endl;
exit(0);
}
......@@ -831,32 +760,3 @@ int d_main(int argc, const char* argv[])
return 0;
}
// --------------------------------------------------------------------
int main(int argc, const char* argv[])
{
int result = 0;
try
{
cif::rsrc_loader::init({
#if USE_RSRC
{ cif::rsrc_loader_type::mrsrc, "", { gResourceIndex, gResourceData, gResourceName } },
#endif
{ cif::rsrc_loader_type::file, "." }
});
load_version_info();
result = d_main(argc, argv);
}
catch (const std::exception& ex)
{
print_what(ex);
exit(1);
}
return result;
}
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#pragma once
#include <string>
#include "config.hpp"
extern std::string VERSION_STRING;
std::string get_version_nr();
std::string get_version_date();
/* include/cif++/Config.hpp. Generated from Config.hpp.in by configure. */
/*-
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2020 NKI/AVL, Netherlands Cancer Institute
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "dssp.hpp"
#include <sys/time.h>
#include <sys/resource.h>
#include <stdexcept>
#include <iostream>
#include <iomanip>
#include <chrono>
#include <cmath>
#include <regex>
#include "cif++/Cif++.hpp"
#include "cif++/CifUtils.hpp"
std::string VERSION_STRING;
int pr_main(int argc, char* argv[]);
// --------------------------------------------------------------------
std::ostream& operator<<(std::ostream& os, const struct timeval& t)
{
uint64_t s = t.tv_sec;
if (s > 24 * 60 * 60)
{
uint32_t days = s / (24 * 60 * 60);
os << days << "d ";
s %= 24 * 60 * 60;
}
if (s > 60 * 60)
{
uint32_t hours = s / (60 * 60);
os << hours << "h ";
s %= 60 * 60;
}
if (s > 60)
{
uint32_t minutes = s / 60;
os << minutes << "m ";
s %= 60;
}
double ss = s + 1e-6 * t.tv_usec;
os << std::fixed << std::setprecision(1) << ss << 's';
return os;
}
std::ostream& operator<<(std::ostream& os, const std::chrono::duration<double>& t)
{
uint64_t s = static_cast<uint64_t>(std::trunc(t.count()));
if (s > 24 * 60 * 60)
{
uint32_t days = s / (24 * 60 * 60);
os << days << "d ";
s %= 24 * 60 * 60;
}
if (s > 60 * 60)
{
uint32_t hours = s / (60 * 60);
os << hours << "h ";
s %= 60 * 60;
}
if (s > 60)
{
uint32_t minutes = s / 60;
os << minutes << "m ";
s %= 60;
}
double ss = s + 1e-6 * (t.count() - s);
os << std::fixed << std::setprecision(1) << ss << 's';
return os;
}
class RUsage
{
public:
~RUsage()
{
if (cif::VERBOSE)
{
struct rusage u;
auto end = std::chrono::system_clock::now();
std::chrono::duration<double> diff = end - start;
if (getrusage(RUSAGE_SELF, &u) == 0)
std::cerr << "CPU usage: "
<< u.ru_utime << " user, "
<< u.ru_stime << " system, "
<< diff << " wall" << std::endl;
else
perror("Failed to get rusage");
}
}
std::chrono::time_point<std::chrono::system_clock> start = std::chrono::system_clock::now();
};
// --------------------------------------------------------------------
namespace {
std::string gVersionNr, gVersionDate;
}
void load_version_info()
{
const std::regex
rxVersionNr(R"(build-(\d+)-g[0-9a-f]{7}(-dirty)?)"),
rxVersionDate(R"(Date: +(\d{4}-\d{2}-\d{2}).*)");
#include "revision.hpp"
struct membuf : public std::streambuf
{
membuf(char* data, size_t length) { this->setg(data, data, data + length); }
} buffer(const_cast<char*>(kRevision), sizeof(kRevision));
std::istream is(&buffer);
std::string line;
while (getline(is, line))
{
std::smatch m;
if (std::regex_match(line, m, rxVersionNr))
{
gVersionNr = m[1];
if (m[2].matched)
gVersionNr += '*';
continue;
}
if (std::regex_match(line, m, rxVersionDate))
{
gVersionDate = m[1];
continue;
}
}
if (not VERSION_STRING.empty())
VERSION_STRING += "\n";
VERSION_STRING += gVersionNr + " " + gVersionDate;
}
std::string get_version_nr()
{
return gVersionNr;
}
std::string get_version_date()
{
return gVersionDate;
}
// --------------------------------------------------------------------
// recursively print exception whats:
void print_what (const std::exception& e)
{
std::cerr << e.what() << std::endl;
try
{
std::rethrow_if_nested(e);
}
catch (const std::exception& nested)
{
std::cerr << " >> ";
print_what(nested);
}
}
int main(int argc, char* argv[])
{
int result = -1;
RUsage r;
try
{
cif::rsrc_loader::init({
{ cif::rsrc_loader_type::file, "." },
#if defined DATADIR
{ cif::rsrc_loader_type::file, DATADIR },
#endif
#if USE_RSRC
{ cif::rsrc_loader_type::mrsrc, "", { gResourceIndex, gResourceData, gResourceName } }
#endif
});
load_version_info();
result = pr_main(argc, argv);
}
catch (std::exception& ex)
{
print_what(ex);
exit(1);
}
return result;
}
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