Permalink
Browse files

Have the Java main call the C main.

  • Loading branch information...
RestlessRodent committed Aug 25, 2016
1 parent d940d3f commit 915e179cccd26897e6f6bb733b762bd51a01f9d7
Showing with 94 additions and 5 deletions.
  1. +2 −2 GNUmakefile
  2. +7 −0 build.xml
  3. +1 −0 include/HOLDER
  4. +29 −0 isrc/sdl/i_main.c
  5. +12 −1 java/core/org/remood/remood/Main.java
  6. +1 −0 src/j.h
  7. +19 −0 src/j_init.c
  8. +2 −2 test.sh
  9. +21 −0 util/runjavah.sh
View
@@ -247,7 +247,7 @@ else
RC_FLAGS = -DNDEBUG
endif
CC_CFLAGS = $(CFLAGS) -fPIC -I$(JAVA_INCLUDE) $(CC_SUBSYSTEMCFLAGS) $(CC_SYSTEMCFLAGS) $(CC_MODECFLAGS) -I$(INPUT_SRC) -I$(INPUT_ISRC)
CC_CFLAGS = $(CFLAGS) -fPIC -I$(JAVA_INCLUDE) -Iinclude/core $(CC_SUBSYSTEMCFLAGS) $(CC_SYSTEMCFLAGS) $(CC_MODECFLAGS) -I$(INPUT_SRC) -I$(INPUT_ISRC)
CC_LFLAGS = $(LDFLAGS) -shared -L$(JAVA_LIB) -lm -ljvm $(CC_SUBSYSTEMLFLAGS) $(CC_SYSTEMLFLAGS) $(CC_MODELFLAGS) -I$(INPUT_SRC) -I$(INPUT_ISRC)
############
@@ -402,7 +402,7 @@ CC_OBJS = $(SYSTEMOBJECTS) \
$(CC_OBJPREFIX)j_init.o
.PHONY:
all: $(CC_EXEOUTPUT) remood-core.jar
all: remood-core.jar $(CC_EXEOUTPUT)
$(CC_EXEOUTPUT): $(CC_OBJS)
View
@@ -54,12 +54,19 @@
<zipfileset dir="${remood.src}"
includes="version" fullpath="version" />
</jar>
<mkdir dir="${user.dir}/include/core" />
<exec executable="${basedir}/util/runjavah.sh" failonerror="true">
<arg value="${user.dir}/remood-core.jar" />
<arg value="${user.dir}/include/core" />
</exec>
</target>
<!-- Clean: Core -->
<target name="clean-core">
<delete dir="${remood.out}/core" />
<delete dir="${remood.jar.core}" />
<delete dir="${user.dir}/include/core" />
</target>
<!-- sdl -->
View
@@ -0,0 +1 @@
JNI native headers are placed here.
View
@@ -14,6 +14,10 @@
#include "m_argv.h"
#include "d_main.h"
#include "j.h"
#include "org_remood_remood_Main.h"
#ifdef LOGMESSAGES
#include <sys/types.h>
#include <sys/stat.h>
@@ -106,3 +110,28 @@ int main(int argc, char **argv)
return 0;
}
JNIEXPORT jint JNICALL Java_org_remood_remood_Main__1_1cMain(JNIEnv* __env,
jclass __cl, jobjectArray __args)
{
int xargc, i;
char** xargv;
jboolean ign;
// Determine argument count (plus 1 for "remood")
xargc = (int)J_GetArrayLength(__args);
// Create argument array
xargv = malloc(sizeof(*xargv) * (xargc + 1));
// First is always "remood"
xargv[0] = "remood";
// Convert string to character arrays
for (i = 0; i < xargc; i++)
xargv[i + 1] = J_GetStringUTFChars(J_GetObjectArrayElement(__args, i),
&ign);
// Call into main
return main(xargc + 1, xargv);
}
@@ -71,7 +71,18 @@ public static void main(String[] __args)
if (__args == null)
throw new NullPointerException();
throw new Error("TODO");
// Call C Main
int rv;
if ((rv = __cMain(__args)) != 0)
System.exit(rv);
}
/**
* Enters the C code from Java land.
*
* @param __args Program arguments.
* @since 2016/08/25
*/
private static native int __cMain(String[] __args);
}
View
@@ -47,6 +47,7 @@ jint *J_GetIntArrayElements(jintArray array, jboolean *isCopy);
void J_ReleaseIntArrayElements(jintArray array, jint *elems, jint mode);
void J_CallVoidMethod(jobject obj, jmethodID methodID, ...);
jobject J_CallStaticObjectMethod(jclass cls, jmethodID methodID, ...);
jobject J_GetObjectArrayElement(jobjectArray array, jint index);
#endif /* REMOOD_J_H__ */
View
@@ -19,6 +19,17 @@ JavaVM* g_JVM = NULL;
/** The global environment. */
JNIEnv* g_Env = NULL;
/** Loaded by JNI, set libraries!. */
int J_InternalMain(int __argc, char** __argv);
jint JNI_OnLoad(JavaVM* __vm, void* __reserved)
{
g_JVM = __vm;
(*__vm)->GetEnv(__vm, &g_Env, JNI_VERSION_1_6);
// Want 1.6
return JNI_VERSION_1_6;
}
/** Exceptions. */
jthrowable J_ExceptionOccurred()
@@ -289,4 +300,12 @@ jobject J_CallStaticObjectMethod(jclass cls, jmethodID methodID, ...)
return rv;
}
jobject J_GetObjectArrayElement(jobjectArray array, jint index)
{
jobject rv = (*g_Env)->GetObjectArrayElement(g_Env, array, index);
__checkException();
return rv;
}
View
@@ -106,9 +106,9 @@ if make "JAVA_INCLUDE=$__ji" \
then
if which gdb > /dev/null
then
gdb --args java -jar "remood-core.jar" -nomouse -devparm $*
gdb --args java -jar "remood-core.jar" -waddir bin/ -nomouse -devparm $*
else
java -jar "remood-core.jar" -nomouse -devparm $*
java -jar "remood-core.jar" -waddir bin/ -nomouse -devparm $*
fi
fi
View
@@ -0,0 +1,21 @@
#!/bin/sh
# ---------------------------------------------------------------------------
# ReMooD Doom Source Port <http://remood.org/>
# Copyright (C) 2005-2016 GhostlyDeath <ghostlydeath@remood.org>
# For more credits, see readme.mkd.
# ---------------------------------------------------------------------------
# ReMooD is under the GNU General Public License v3+, see license.mkd.
# ---------------------------------------------------------------------------
# Convert
if ! javah -cp "$1" -jni -d "$2" $(
# InfoZip appears incapable of a file only listing of ZIP contents, so
# I really hope that the size and date fields remain the same and are not
# specific to locals
LC_ALL="C" unzip -l "$1" | grep '\.class[ \t]*' | \
sed 's/^[ \t0-9:\-]*\(.*\)\.class$/\1 /g' | grep -v '\-' | \
sed 's/\//./g')
then
exit 1
fi

0 comments on commit 915e179

Please sign in to comment.