first commit
This commit is contained in:
commit
61d3c33769
80
Makefile
Normal file
80
Makefile
Normal file
@ -0,0 +1,80 @@
|
||||
LIBNAME := $(shell basename $$(pwd))
|
||||
MAJOR := 1
|
||||
MINOR := 0.0
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
LINKERNAME := $(LIBNAME).dylib
|
||||
SONAME := $(LIBNAME).$(MAJOR).dylib
|
||||
REALNAME := $(LINKERNAME)
|
||||
else
|
||||
LINKERNAME := $(LIBNAME).so
|
||||
SONAME := $(LINKERNAME).$(MAJOR)
|
||||
REALNAME := $(SONAME).$(MINOR)
|
||||
endif
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
DATADIR ?= $(PREFIX)/share
|
||||
MANDIR ?= $(DATADIR)/man
|
||||
|
||||
SRCS := $(wildcard *.cpp)
|
||||
OBJS := $(subst .cpp,.o,$(SRCS))
|
||||
DEPS := $(subst .cpp,.d,$(SRCS))
|
||||
HDRS := $(filter-out $(LIBNAME).hpp,$(wildcard *.hpp))
|
||||
|
||||
CXX ?= g++
|
||||
|
||||
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -fPIC
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -D DEBUG -O0
|
||||
else
|
||||
CXXFLAGS += -D NDEBUG -O3
|
||||
endif
|
||||
|
||||
LDLIBS :=
|
||||
|
||||
RM := /bin/rm -f
|
||||
INSTALL := /usr/bin/install -c
|
||||
|
||||
all: $(REALNAME)
|
||||
|
||||
$(REALNAME): $(OBJS) $(DEPS)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
$(CXX) -dynamiclib -o $(REALNAME) -current_version $(MAJOR) -compatibility_version $(MINOR) $(LDFLAGS) $(LDLIBS) $(OBJS)
|
||||
else
|
||||
$(CXX) -g -shared -Wl,-soname,$(SONAME) -o $(REALNAME) $(LDFLAGS) $(LDLIBS) $(OBJS)
|
||||
endif
|
||||
|
||||
%.o: %.cpp %.d Makefile
|
||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
||||
|
||||
-include *.d
|
||||
|
||||
%.d: ;
|
||||
|
||||
$(LIBNAME).hpp: $(HDRS)
|
||||
@echo updating $(LIBNAME).hpp
|
||||
@cp /dev/null $(LIBNAME).hpp
|
||||
@for h in $(HDRS); \
|
||||
do \
|
||||
cat $$h >> $(LIBNAME).hpp; \
|
||||
done
|
||||
|
||||
.PHONY: clean install
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(DEPS) $(REALNAME) $(LIBNAME).hpp
|
||||
|
||||
install: $(REALNAME) $(LIBNAME).hpp
|
||||
$(INSTALL) -m 644 $(REALNAME) $(LIBDIR)
|
||||
$(INSTALL) -m 644 $(LIBNAME).hpp $(INCLUDEDIR)
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
cd $(LIBDIR) && ln -sf $(REALNAME) $(SONAME)
|
||||
else
|
||||
ldconfig
|
||||
cd $(LIBDIR) && ln -sf $(SONAME) $(LINKERNAME)
|
||||
endif
|
28
fdostream.cpp
Normal file
28
fdostream.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
//
|
||||
// fdostream.cpp
|
||||
// libscio
|
||||
//
|
||||
// Created by Bob Polis at 2020-02-14
|
||||
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
||||
//
|
||||
|
||||
#include "fdostream.hpp"
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
std::streambuf::int_type sc::io::fdoutbuf::overflow(std::streambuf::int_type c) {
|
||||
if (c != EOF) {
|
||||
if (::write(_fd, &c, 1) != 1) {
|
||||
return EOF;
|
||||
}
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
std::streamsize sc::io::fdoutbuf::xsputn(const char* s, std::streamsize num) {
|
||||
return ::write(_fd, s, num);
|
||||
}
|
45
fdostream.hpp
Normal file
45
fdostream.hpp
Normal file
@ -0,0 +1,45 @@
|
||||
//
|
||||
// fdostream.hpp
|
||||
// libscio
|
||||
//
|
||||
// Created by Bob Polis at 2020-02-14
|
||||
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
||||
//
|
||||
|
||||
#ifndef _fdostream_H_
|
||||
#define _fdostream_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <streambuf>
|
||||
#include <cstdio>
|
||||
|
||||
namespace sc {
|
||||
|
||||
namespace io {
|
||||
|
||||
class fdoutbuf: public std::streambuf {
|
||||
public:
|
||||
fdoutbuf(int fd): _fd(fd) {}
|
||||
|
||||
private:
|
||||
int _fd;
|
||||
|
||||
int_type overflow(int_type c) override;
|
||||
std::streamsize xsputn(const char* s, std::streamsize num) override;
|
||||
};
|
||||
|
||||
class fdostream : public std::ostream {
|
||||
public:
|
||||
fdostream(int fd) : std::ostream(nullptr), _buf(fd) {
|
||||
rdbuf(&_buf);
|
||||
}
|
||||
|
||||
private:
|
||||
fdoutbuf _buf;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif // _fdostream_H_
|
45
sciotest/Makefile
Normal file
45
sciotest/Makefile
Normal file
@ -0,0 +1,45 @@
|
||||
BIN := $(shell basename $$(pwd))
|
||||
|
||||
SRCS := $(wildcard *.cpp)
|
||||
OBJS := $(subst .cpp,.o,$(SRCS))
|
||||
DEPS := $(subst .cpp,.d,$(SRCS))
|
||||
|
||||
CXX ?= g++
|
||||
PKG_CONFIG ?= pkg-config
|
||||
|
||||
PREFIX ?= /usr/local
|
||||
BINDIR ?= $(PREFIX)/bin
|
||||
DATADIR ?= $(PREFIX)/share
|
||||
MANDIR ?= $(DATADIR)/man
|
||||
|
||||
RM := /bin/rm -f
|
||||
INSTALL := /usr/bin/install -c
|
||||
|
||||
CXXFLAGS := $(CXXFLAGS) -Wshadow -Wall -Wpedantic -Wextra -g -fno-strict-aliasing -std=c++17 -pthread
|
||||
ifeq ($(DEBUG),1)
|
||||
CXXFLAGS += -D DEBUG -O0
|
||||
else
|
||||
CXXFLAGS += -D NDEBUG -O3
|
||||
endif
|
||||
|
||||
LDLIBS := -lm -lpthread -lcommon -lscio
|
||||
|
||||
all: $(BIN)
|
||||
|
||||
$(BIN): $(OBJS) $(DEPS)
|
||||
$(CXX) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $(BIN)
|
||||
|
||||
%.o: %.cpp %.d Makefile
|
||||
$(CXX) $(CXXFLAGS) -MMD -MP -MT $@ -MF $*.d -c $<
|
||||
|
||||
-include *.d
|
||||
|
||||
%.d: ;
|
||||
|
||||
.PHONY: clean install
|
||||
|
||||
clean:
|
||||
$(RM) $(OBJS) $(DEPS) $(BIN)
|
||||
|
||||
install: $(BIN)
|
||||
$(INSTALL) $(BIN) $(DESTDIR)$(BINDIR)
|
25
sciotest/main.cpp
Normal file
25
sciotest/main.cpp
Normal file
@ -0,0 +1,25 @@
|
||||
//
|
||||
// main.cpp
|
||||
// sciotest
|
||||
//
|
||||
// Created by Bob Polis at 2020-02-14
|
||||
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <cstdlib>
|
||||
#include <libcommon.hpp>
|
||||
#include <libscio.hpp>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(int /*argc*/, const char * argv[]) {
|
||||
try {
|
||||
sc::io::fdostream chan(1);
|
||||
chan << "hello, sciotest\n";
|
||||
} catch (const exception& ex) {
|
||||
cerr << su::basename(argv[0]) << ": " << ex.what() << '\n';
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user