Builds shared library now.

This commit is contained in:
rexy712 2019-09-01 20:14:02 -07:00
parent 577af3c040
commit cc0206ce2c
9 changed files with 195 additions and 41 deletions

6
.gitignore vendored
View File

@ -7,5 +7,7 @@ data
testout testout
audio audio
video video
result*.json doc/syncres/*
dissection_result*.txt lib*.so
lib*.a
matrix-send

View File

@ -1,3 +1,21 @@
/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RJP_ITERATOR_HPP #ifndef RJP_ITERATOR_HPP
#define RJP_ITERATOR_HPP #define RJP_ITERATOR_HPP
@ -25,10 +43,7 @@ namespace raii{
constexpr bool operator!=(const rjp_object_iterator& e)const{ constexpr bool operator!=(const rjp_object_iterator& e)const{
return m_value != e.m_value; return m_value != e.m_value;
} }
rjp_object_iterator& operator++(void){ rjp_object_iterator& operator++(void);
m_value = rjp_next_member(m_value);
return *this;
}
constexpr RJP_value* operator*(void){ constexpr RJP_value* operator*(void){
return m_value; return m_value;
} }
@ -62,10 +77,7 @@ namespace raii{
constexpr bool operator!=(const rjp_array_iterator& e)const{ constexpr bool operator!=(const rjp_array_iterator& e)const{
return m_value != e.m_value; return m_value != e.m_value;
} }
rjp_array_iterator& operator++(void){ rjp_array_iterator& operator++(void);
m_value = rjp_next_element(m_value);
return *this;
}
constexpr RJP_value* operator*(void){ constexpr RJP_value* operator*(void){
return m_value; return m_value;
} }

View File

@ -29,8 +29,10 @@ namespace raii{
{ {
template<class T> template<class T>
void operator()(T* ptr){ void operator()(T* ptr){
rjp_free_value(ptr); internal_free_value(ptr);
} }
private:
void internal_free_value(RJP_value*);
}; };
} }

View File

@ -31,18 +31,9 @@ namespace raii{
class rjp_allocator class rjp_allocator
{ {
public: public:
static void free(void* data){ static void free(void* data);
rjp_free(data); static void* allocate(size_t size);
} static void* copy(const void* data, size_t len);
static void* allocate(size_t size){
return rjp_alloc(size);
}
static void* copy(const void* data, size_t len){
char* tmp = reinterpret_cast<char*>(allocate(len));
memcpy(tmp, data, len-1);
tmp[len-1] = 0;
return tmp;
}
}; };
} }
@ -69,7 +60,6 @@ namespace raii{
} }
}; };
rjp_string rjp_string_from_key(RJP_value* val); rjp_string rjp_string_from_key(RJP_value* val);
} }
#endif #endif

View File

@ -14,20 +14,36 @@
#Copyright 2018-2019 rexy712 #Copyright 2018-2019 rexy712
SOURCE_DIRS:=src src/raii src/matrix ifeq ($(OS),Windows_NT)
WINDOWS=1
endif
SOURCE_DIRS:=src/raii src/matrix
OBJDIR:=obj OBJDIR:=obj
DEPDIR:=$(OBJDIR)/dep DEPDIR:=$(OBJDIR)/dep
INCLUDE_DIRS:=include INCLUDE_DIRS:=include
EXT:=cpp EXT:=cpp
MAIN_EXECUTABLE:=tester MAIN_LIBRARY:=librmatrix.so
CXX:=g++ CXXFLAGS:=-g -std=c++17 -Wall -pedantic -Wextra -fPIC
CXXFLAGS:=-g -std=c++17 -Wall -pedantic -Wextra
ifneq ($(WINDOWS),1)
CXX:=g++
AR:=ar
RANLIB:=ranlib
LDFLAGS:=-shared
LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
STRIP:=strip
else
CXX:=x86_64-w64-mingw32-g++
AR:=x86_64-w64-mingw32-ar
RANLIB:=x86_64-w64-mingw32-ranlib
LDFLAGS:=
LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus
STRIP:=x86_64-w64-mingw32-strip
endif
all: CXXFLAGS+=-O0 all: CXXFLAGS+=-O0
release: CXXFLAGS+=-O2 release: CXXFLAGS+=-O2
LDFLAGS=
LDLIBS:=-lcurl -lrjp -lavformat -lavcodec -lavutil -lswresample -lswscale -lfreeimageplus -lpthread
STRIP:=strip
memchk:LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls memchk:LDFLAGS+=-fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
memchk:CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls memchk:CXXFLAGS+=-O0 -fsanitize=address -fno-omit-frame-pointer -fno-optimize-sibling-calls
@ -50,16 +66,21 @@ INTERNAL_CXXFLAGS=-c $(foreach dir,$(INCLUDE_DIRS),-I"$(dir)") -MMD -MP -MF"$(DE
SOURCES:=$(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext)))) SOURCES:=$(foreach source,$(SOURCE_DIRS),$(foreach ext,$(EXT),$(wildcard $(source)/*.$(ext))))
OBJECTS:=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(SOURCES))))) OBJECTS:=$(addprefix $(OBJDIR)/,$(subst \,.,$(subst /,.,$(addsuffix .o,$(SOURCES)))))
all: $(MAIN_EXECUTABLE) all: $(MAIN_LIBRARY)
memchk: $(MAIN_EXECUTABLE) .PHONY: memchk
memchk: all
$(MAIN_EXECUTABLE): $(OBJECTS)
$(CXX) $(LDFLAGS) $^ -o "$(basename $@)" $(LDLIBS)
.PHONY: release .PHONY: release
release: $(OBJECTS) release: all
$(CXX) $(LDFLAGS) $^ -o "$(basename $(MAIN_EXECUTABLE))" $(LDLIBS) .PHONY: utils
$(STRIP) --strip-all "$(MAIN_EXECUTABLE)" utils: matrix-send
tester: $(MAIN_LIBRARY) $(OBJDIR)/src.test.cpp.o
$(CXX) -L. -o "$@" $(OBJDIR)/src.test.cpp.o -lrmatrix -lpthread
matrix-send: $(MAIN_LIBRARY) $(OBJDIR)/util.matrix-send.cpp.o
$(CXX) -L. -o "$@" $(OBJDIR)/util.matrix-send.cpp.o -lrmatrix
$(MAIN_LIBRARY): $(OBJECTS)
$(CXX) -o "$@" $^ $(CXXFLAGS) $(LDFLAGS) $(LDLIBS)
define GENERATE_OBJECTS define GENERATE_OBJECTS
@ -69,6 +90,8 @@ $$(OBJDIR)/$(subst \,.,$(subst /,.,$(1))).%.o: $(1)/%
endef endef
$(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir)))) $(foreach dir,$(SOURCE_DIRS),$(eval $(call GENERATE_OBJECTS,$(dir))))
$(eval $(call GENERATE_OBJECTS,util))
$(eval $(call GENERATE_OBJECTS,src))
$(OBJECTS): | $(OBJDIR) $(DEPDIR) $(OBJECTS): | $(OBJDIR) $(DEPDIR)
$(OBJDIR): $(OBJDIR):
@ -80,7 +103,11 @@ $(DEPDIR):
clean: clean:
$(call rmdir,"$(DEPDIR)") $(call rmdir,"$(DEPDIR)")
$(call rmdir,"$(OBJDIR)") $(call rmdir,"$(OBJDIR)")
$(call rm,"$(MAIN_EXECUTABLE)") $(call rm,"$(MAIN_LIBRARY)")
.PHONY: utilsclean
fullclean: clean
$(call rm,"matrix-send")
$(call rm,"tester")
-include $(wildcard $(DEPDIR)/*.d) -include $(wildcard $(DEPDIR)/*.d)

32
src/raii/rjp_iterator.cpp Normal file
View File

@ -0,0 +1,32 @@
/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "raii/rjp_iterator.hpp"
namespace raii{
rjp_object_iterator& rjp_object_iterator::operator++(void){
m_value = rjp_next_member(m_value);
return *this;
}
rjp_array_iterator& rjp_array_iterator::operator++(void){
m_value = rjp_next_element(m_value);
return *this;
}
}

25
src/raii/rjp_ptr.cpp Normal file
View File

@ -0,0 +1,25 @@
/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "raii/rjp_ptr.hpp"
namespace raii::detail{
void rjp_tree_deleter::internal_free_value(RJP_value* v){
rjp_free_value(v);
}
}

View File

@ -19,6 +19,20 @@
#include "raii/rjp_string.hpp" #include "raii/rjp_string.hpp"
namespace raii{ namespace raii{
namespace detail{
void rjp_allocator::free(void* data){
rjp_free(data);
}
void* rjp_allocator::allocate(size_t size){
return rjp_alloc(size);
}
void* rjp_allocator::copy(const void* data, size_t len){
char* tmp = reinterpret_cast<char*>(allocate(len));
memcpy(tmp, data, len-1);
tmp[len-1] = 0;
return tmp;
}
}
rjp_string rjp_string_from_key(RJP_value* val){ rjp_string rjp_string_from_key(RJP_value* val){
char* key = rjp_member_name(val); char* key = rjp_member_name(val);
size_t len = rjp_member_name_length(val); size_t len = rjp_member_name_length(val);

50
util/matrix-send.cpp Normal file
View File

@ -0,0 +1,50 @@
/**
This file is a part of r0nk, atlas_moon, and rexy's matrix client
Copyright (C) 2019 rexy712
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "matrix/matrix.hpp"
#include "raii/static_string.hpp"
#include <cstdlib> //exit
[[noreturn]] void usage(int status){
printf("Usage: matrix-send STRING\n");
printf("\tSends message to designated room as the designated user\n");
exit(status);
}
int main(int argc, char** argv){
const char* username = "username";
const char* password = "password";
const char* useragent = "rexy712s test bot";
const char* homeserver = "matrix.org";
const char* roomid = "!roomid:matrix.org";
matrix::auth_data auth{username, password, homeserver, useragent};
if(argc < 2)
usage(1);
matrix::session ses(auth);
if(!ses.valid()){
fprintf(stderr, "Failed to init matrix session!\n");
return 1;
}
auto client = ses.spawn_client();
auto room = client.spawn_room(raii::static_string(roomid));
room.send_message(raii::static_string(argv[1]));
}