improved build
This commit is contained in:
parent
636a007f62
commit
3e85dce2c7
17
Makefile
17
Makefile
|
@ -3,12 +3,24 @@ CFLAGS = -Wall -pedantic-errors -std=c++17 -g #-O2
|
||||||
SRCDIR = src/main/cpp/src/
|
SRCDIR = src/main/cpp/src/
|
||||||
BUILDDIR = target/
|
BUILDDIR = target/
|
||||||
INCDIR = src/main/cpp/inc/
|
INCDIR = src/main/cpp/inc/
|
||||||
|
INSTALLDIR = /usr/lib/
|
||||||
LDFLAGS = -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -I$(INCDIR) -Iinc/ #-ldl
|
LDFLAGS = -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -I$(INCDIR) -Iinc/ #-ldl
|
||||||
NAME = libplugin.so
|
NAME = libplugin.so
|
||||||
|
|
||||||
SRCFILES = $(wildcard $(SRCDIR)*.cpp)
|
SRCFILES = $(wildcard $(SRCDIR)*.cpp)
|
||||||
OBJFILES = $(patsubst $(SRCDIR)%, $(BUILDDIR)%, $(patsubst %.cpp,%.so,$(SRCFILES)))
|
OBJFILES = $(patsubst $(SRCDIR)%, $(BUILDDIR)%, $(patsubst %.cpp,%.so,$(SRCFILES)))
|
||||||
|
|
||||||
|
plugins: $(INSTALLDIR)$(NAME)
|
||||||
|
bash testplugins/compile.sh
|
||||||
|
|
||||||
|
installplugins: plugins
|
||||||
|
bash testplugins/install.sh
|
||||||
|
|
||||||
|
install: $(INSTALLDIR)$(NAME)
|
||||||
|
|
||||||
|
$(INSTALLDIR)$(NAME): $(BUILDDIR)$(NAME)
|
||||||
|
cp $(BUILDDIR)$(NAME) $(INSTALLDIR)
|
||||||
|
|
||||||
all: createhfiles $(BUILDDIR)$(NAME)
|
all: createhfiles $(BUILDDIR)$(NAME)
|
||||||
|
|
||||||
$(BUILDDIR)%.so: $(SRCDIR)%.cpp $(BUILDDIR)
|
$(BUILDDIR)%.so: $(SRCDIR)%.cpp $(BUILDDIR)
|
||||||
|
@ -18,7 +30,8 @@ $(BUILDDIR)%: $(SRCDIR)%.cpp $(BUILDDIR)
|
||||||
$(CXX) $(CFLAGS) $(SRCDIR)$*.cpp -o $@
|
$(CXX) $(CFLAGS) $(SRCDIR)$*.cpp -o $@
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -fr $(BUILDDIR)
|
$(RM) -r $(BUILDDIR)
|
||||||
|
$(RM) testserver/plugins/*.so testserver/plugins/CppPlugins/*.so testplugins/*/*.so
|
||||||
|
|
||||||
$(BUILDDIR):
|
$(BUILDDIR):
|
||||||
mkdir -p $@
|
mkdir -p $@
|
||||||
|
@ -27,4 +40,4 @@ createhfiles:
|
||||||
rm -fr $(INCDIR)
|
rm -fr $(INCDIR)
|
||||||
javah -d $(INCDIR) -classpath target/classes/:$(HOME)/.m2/repository/org/bukkit/craftbukkit/1.7.10-R0.1-SNAPSHOT/craftbukkit-1.7.10-R0.1-SNAPSHOT.jar de.mrbesen.cppplugins.CppPlugin
|
javah -d $(INCDIR) -classpath target/classes/:$(HOME)/.m2/repository/org/bukkit/craftbukkit/1.7.10-R0.1-SNAPSHOT/craftbukkit-1.7.10-R0.1-SNAPSHOT.jar de.mrbesen.cppplugins.CppPlugin
|
||||||
|
|
||||||
.phony: createhfiles clean
|
.phony: createhfiles clean plugins
|
||||||
|
|
|
@ -8,11 +8,15 @@ fi
|
||||||
|
|
||||||
#build cpp
|
#build cpp
|
||||||
rm target/*.so
|
rm target/*.so
|
||||||
make -j1 all #that makefile is not paralllizable
|
make -j1 all #that makefile is not paralllizable
|
||||||
if [ "$?" -ne "0" ]; then
|
if [ "$?" -ne "0" ]; then
|
||||||
echo "Error"
|
echo "Error"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
sudo make install
|
||||||
|
|
||||||
|
#build and install all testplugins
|
||||||
|
make installplugins
|
||||||
|
|
||||||
#prepare server
|
#prepare server
|
||||||
mkdir -p testserver/plugins/CppPlugins
|
mkdir -p testserver/plugins/CppPlugins
|
||||||
|
|
|
@ -23,15 +23,6 @@ jmethodID LISTENERSMALLCONTR;
|
||||||
|
|
||||||
CppPlugin* plugin; //what happens, with more than one plugin?
|
CppPlugin* plugin; //what happens, with more than one plugin?
|
||||||
|
|
||||||
/*
|
|
||||||
jint JNI_OnLoad(JavaVM *vm, void *reserved) {
|
|
||||||
DEB("onload" );
|
|
||||||
JNIEnv* env;
|
|
||||||
vm->GetEnv((void**) &env, JNI_VERSION_1_8);
|
|
||||||
|
|
||||||
|
|
||||||
return JNI_VERSION_1_8;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void fixcap(JNIEnv* env) {
|
void fixcap(JNIEnv* env) {
|
||||||
DEB("ensure 1024" );
|
DEB("ensure 1024" );
|
||||||
|
@ -41,28 +32,8 @@ void fixcap(JNIEnv* env) {
|
||||||
env->PushLocalFrame(1024);
|
env->PushLocalFrame(1024);
|
||||||
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
operator long()(JNIDATA d) {
|
|
||||||
return (long) d;
|
|
||||||
}
|
|
||||||
|
|
||||||
long operator|(JNIDATA a, JNIDATA b) {
|
|
||||||
return (long) a | (long) b;
|
|
||||||
}
|
|
||||||
|
|
||||||
long operator|(long a, JNIDATA b) {
|
|
||||||
return a | (long) b;
|
|
||||||
}
|
|
||||||
|
|
||||||
long operator&(long a, JNIDATA b) {
|
|
||||||
return a & (long) b;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
void load(JNIEnv* env, long data) {
|
void load(JNIEnv* env, long data) {
|
||||||
|
|
||||||
DEB("loading with mask: " << data);
|
|
||||||
|
|
||||||
|
|
||||||
if(data & JNI_PLUGINCLASS)
|
if(data & JNI_PLUGINCLASS)
|
||||||
CPPPLUGINCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin");
|
CPPPLUGINCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin");
|
||||||
if(data & JNI_EVENTCLASS)
|
if(data & JNI_EVENTCLASS)
|
||||||
|
@ -71,14 +42,12 @@ void load(JNIEnv* env, long data) {
|
||||||
MAPCLASS = env->FindClass("java/util/Map");
|
MAPCLASS = env->FindClass("java/util/Map");
|
||||||
if(data & JNI_LISTENERCLASS)
|
if(data & JNI_LISTENERCLASS)
|
||||||
LISTENERCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin$CppListener");
|
LISTENERCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin$CppListener");
|
||||||
|
|
||||||
DEB("find classes: " << (!!CPPPLUGINCLASS) << (!!EVENTCLASS) << (!!MAPCLASS) << (!!LISTENERCLASS));
|
DEB("find classes: " << (!!CPPPLUGINCLASS) << (!!EVENTCLASS) << (!!MAPCLASS) << (!!LISTENERCLASS));
|
||||||
|
|
||||||
if(data & JNI_EVENTDATAFIELD)
|
if(data & JNI_EVENTDATAFIELD)
|
||||||
EVENTDATAF = env->GetFieldID(EVENTCLASS, "data", "Ljava/util/Map;");
|
EVENTDATAF = env->GetFieldID(EVENTCLASS, "data", "Ljava/util/Map;");
|
||||||
if(data & JNI_EVENTNAMEFIELD)
|
if(data & JNI_EVENTNAMEFIELD)
|
||||||
EVENTNAMEF = env->GetFieldID(EVENTCLASS, "name", "Ljava/lang/String;");
|
EVENTNAMEF = env->GetFieldID(EVENTCLASS, "name", "Ljava/lang/String;");
|
||||||
|
|
||||||
DEB("findfields: " << (!!EVENTDATAF) << (!!EVENTNAMEF));
|
DEB("findfields: " << (!!EVENTDATAF) << (!!EVENTNAMEF));
|
||||||
|
|
||||||
if(data & JNI_MAPGETMETH)
|
if(data & JNI_MAPGETMETH)
|
||||||
|
@ -110,7 +79,7 @@ JNIEXPORT jboolean JNICALL Java_de_mrbesen_cppplugins_CppPlugin_loadPlugin(JNIEn
|
||||||
const char* cpath = env->GetStringUTFChars(path, 0);
|
const char* cpath = env->GetStringUTFChars(path, 0);
|
||||||
|
|
||||||
//open plugin
|
//open plugin
|
||||||
DEB("open plugin " << cpath );
|
DEB("open plugin " << cpath);
|
||||||
void* handle = dlopen(cpath, RTLD_LAZY);
|
void* handle = dlopen(cpath, RTLD_LAZY);
|
||||||
if (!handle) {
|
if (!handle) {
|
||||||
std::cout << "could not create handle of: " << cpath << " error: " << dlerror() << std::endl;
|
std::cout << "could not create handle of: " << cpath << " error: " << dlerror() << std::endl;
|
||||||
|
@ -131,7 +100,6 @@ JNIEXPORT jboolean JNICALL Java_de_mrbesen_cppplugins_CppPlugin_loadPlugin(JNIEn
|
||||||
|
|
||||||
//store data
|
//store data
|
||||||
//setData(data, env, thisobj);
|
//setData(data, env, thisobj);
|
||||||
DEB("plugin: " << (bool)plugin);
|
|
||||||
return (bool) plugin; // converted to boolean here
|
return (bool) plugin; // converted to boolean here
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,11 +14,13 @@ import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.logging.Logger;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class CppLoader implements PluginLoader {
|
public class CppLoader implements PluginLoader {
|
||||||
|
|
||||||
protected Server serv;
|
protected Server serv;
|
||||||
|
protected Logger log = Logger.getLogger("CppLoader");
|
||||||
|
|
||||||
public CppLoader(Server serv) {
|
public CppLoader(Server serv) {
|
||||||
this.serv = serv;
|
this.serv = serv;
|
||||||
|
@ -125,7 +127,6 @@ public class CppLoader implements PluginLoader {
|
||||||
//cppify event
|
//cppify event
|
||||||
CppEvent cppe = CppEvent.cppify(event);
|
CppEvent cppe = CppEvent.cppify(event);
|
||||||
|
|
||||||
System.out.println("fire event " + cppe.getName() + " in function " + functionid);
|
|
||||||
cppe = plugin.fireEvent(cppe, functionid);
|
cppe = plugin.fireEvent(cppe, functionid);
|
||||||
|
|
||||||
//uncppify
|
//uncppify
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package de.mrbesen.cppplugins;
|
package de.mrbesen.cppplugins;
|
||||||
|
|
||||||
import com.avaje.ebean.EbeanServer;
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Server;
|
import org.bukkit.Server;
|
||||||
|
@ -9,7 +7,6 @@ import org.bukkit.command.Command;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.configuration.file.FileConfiguration;
|
import org.bukkit.configuration.file.FileConfiguration;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
|
||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
import org.bukkit.plugin.Plugin;
|
import org.bukkit.plugin.Plugin;
|
||||||
import org.bukkit.plugin.PluginDescriptionFile;
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
|
@ -62,7 +59,6 @@ public class CppPlugin implements Plugin {
|
||||||
System.out.println("load library from: " + path);
|
System.out.println("load library from: " + path);
|
||||||
try {
|
try {
|
||||||
System.load(path);
|
System.load(path);
|
||||||
System.out.println("run init_()");
|
|
||||||
return init_();
|
return init_();
|
||||||
} catch(UnsatisfiedLinkError e) {
|
} catch(UnsatisfiedLinkError e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
#!/bin/bash
|
||||||
|
old=$(pwd)
|
||||||
|
cd $(dirname $0)
|
||||||
|
folders=$(ls -F | grep "/")
|
||||||
|
for f in $folders; do
|
||||||
|
cd $f
|
||||||
|
make all
|
||||||
|
cd ..
|
||||||
|
done
|
||||||
|
cd $old
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
old=$(pwd)
|
||||||
|
cd $(dirname $0)
|
||||||
|
folders=$(ls -F | grep "/")
|
||||||
|
for f in $folders; do
|
||||||
|
echo cp $f*.so ../testserver/plugins/
|
||||||
|
cp $f*.so ../testserver/plugins/
|
||||||
|
done
|
||||||
|
cd $old
|
|
@ -2,8 +2,10 @@
|
||||||
CFLAGS = -Wall -pedantic-errors -std=c++17 -g
|
CFLAGS = -Wall -pedantic-errors -std=c++17 -g
|
||||||
SRCDIR = src/
|
SRCDIR = src/
|
||||||
INCDIR = ../../inc
|
INCDIR = ../../inc
|
||||||
LDFLAGS = -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -I$(INCDIR) -I../../src/main/cpp/inc
|
LDFLAGS = -I/usr/lib/jvm/java-8-openjdk-amd64/include/ -I/usr/lib/jvm/java-8-openjdk-amd64/include/linux/ -I$(INCDIR)
|
||||||
NAME = simpleevents.so
|
NAME = simpleevents.so
|
||||||
|
|
||||||
all:
|
all:
|
||||||
g++ -fPIC -shared $(CFLAGS) $(SRCDIR)*.cpp ../../src/main/cpp/src/plugin.cpp $(LDFLAGS) -o $(NAME) /home/yannis/git/Cppplugin/testserver/plugins/CppPlugins/libplugin.so
|
g++ -fPIC -shared $(CFLAGS) $(SRCDIR)*.cpp $(LDFLAGS) -o $(NAME) -lplugin
|
||||||
|
|
||||||
|
#/home/yannis/git/Cppplugin/testserver/plugins/CppPlugins/libplugin.so
|
||||||
|
|
Loading…
Reference in New Issue