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/
|
||||
BUILDDIR = target/
|
||||
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
|
||||
NAME = libplugin.so
|
||||
|
||||
SRCFILES = $(wildcard $(SRCDIR)*.cpp)
|
||||
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)
|
||||
|
||||
$(BUILDDIR)%.so: $(SRCDIR)%.cpp $(BUILDDIR)
|
||||
|
@ -18,7 +30,8 @@ $(BUILDDIR)%: $(SRCDIR)%.cpp $(BUILDDIR)
|
|||
$(CXX) $(CFLAGS) $(SRCDIR)$*.cpp -o $@
|
||||
|
||||
clean:
|
||||
rm -fr $(BUILDDIR)
|
||||
$(RM) -r $(BUILDDIR)
|
||||
$(RM) testserver/plugins/*.so testserver/plugins/CppPlugins/*.so testplugins/*/*.so
|
||||
|
||||
$(BUILDDIR):
|
||||
mkdir -p $@
|
||||
|
@ -27,4 +40,4 @@ createhfiles:
|
|||
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
|
||||
|
||||
.phony: createhfiles clean
|
||||
.phony: createhfiles clean plugins
|
||||
|
|
|
@ -8,11 +8,15 @@ fi
|
|||
|
||||
#build cpp
|
||||
rm target/*.so
|
||||
make -j1 all #that makefile is not paralllizable
|
||||
make -j1 all #that makefile is not paralllizable
|
||||
if [ "$?" -ne "0" ]; then
|
||||
echo "Error"
|
||||
exit 1
|
||||
fi
|
||||
sudo make install
|
||||
|
||||
#build and install all testplugins
|
||||
make installplugins
|
||||
|
||||
#prepare server
|
||||
mkdir -p testserver/plugins/CppPlugins
|
||||
|
|
|
@ -23,15 +23,6 @@ jmethodID LISTENERSMALLCONTR;
|
|||
|
||||
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) {
|
||||
DEB("ensure 1024" );
|
||||
|
@ -41,28 +32,8 @@ void fixcap(JNIEnv* env) {
|
|||
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) {
|
||||
|
||||
DEB("loading with mask: " << data);
|
||||
|
||||
|
||||
if(data & JNI_PLUGINCLASS)
|
||||
CPPPLUGINCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin");
|
||||
if(data & JNI_EVENTCLASS)
|
||||
|
@ -71,14 +42,12 @@ void load(JNIEnv* env, long data) {
|
|||
MAPCLASS = env->FindClass("java/util/Map");
|
||||
if(data & JNI_LISTENERCLASS)
|
||||
LISTENERCLASS = env->FindClass("de/mrbesen/cppplugins/CppPlugin$CppListener");
|
||||
|
||||
DEB("find classes: " << (!!CPPPLUGINCLASS) << (!!EVENTCLASS) << (!!MAPCLASS) << (!!LISTENERCLASS));
|
||||
|
||||
if(data & JNI_EVENTDATAFIELD)
|
||||
EVENTDATAF = env->GetFieldID(EVENTCLASS, "data", "Ljava/util/Map;");
|
||||
if(data & JNI_EVENTNAMEFIELD)
|
||||
EVENTNAMEF = env->GetFieldID(EVENTCLASS, "name", "Ljava/lang/String;");
|
||||
|
||||
DEB("findfields: " << (!!EVENTDATAF) << (!!EVENTNAMEF));
|
||||
|
||||
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);
|
||||
|
||||
//open plugin
|
||||
DEB("open plugin " << cpath );
|
||||
DEB("open plugin " << cpath);
|
||||
void* handle = dlopen(cpath, RTLD_LAZY);
|
||||
if (!handle) {
|
||||
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
|
||||
//setData(data, env, thisobj);
|
||||
DEB("plugin: " << (bool)plugin);
|
||||
return (bool) plugin; // converted to boolean here
|
||||
}
|
||||
|
||||
|
|
|
@ -14,11 +14,13 @@ import java.util.HashMap;
|
|||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CppLoader implements PluginLoader {
|
||||
|
||||
protected Server serv;
|
||||
protected Logger log = Logger.getLogger("CppLoader");
|
||||
|
||||
public CppLoader(Server serv) {
|
||||
this.serv = serv;
|
||||
|
@ -125,7 +127,6 @@ public class CppLoader implements PluginLoader {
|
|||
//cppify event
|
||||
CppEvent cppe = CppEvent.cppify(event);
|
||||
|
||||
System.out.println("fire event " + cppe.getName() + " in function " + functionid);
|
||||
cppe = plugin.fireEvent(cppe, functionid);
|
||||
|
||||
//uncppify
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package de.mrbesen.cppplugins;
|
||||
|
||||
import com.avaje.ebean.EbeanServer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Server;
|
||||
|
@ -9,7 +7,6 @@ import org.bukkit.command.Command;
|
|||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.generator.ChunkGenerator;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.PluginDescriptionFile;
|
||||
|
@ -62,7 +59,6 @@ public class CppPlugin implements Plugin {
|
|||
System.out.println("load library from: " + path);
|
||||
try {
|
||||
System.load(path);
|
||||
System.out.println("run init_()");
|
||||
return init_();
|
||||
} catch(UnsatisfiedLinkError e) {
|
||||
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
|
||||
SRCDIR = src/
|
||||
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
|
||||
|
||||
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