aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobin Haberkorn <rh@travelping.com>2010-12-30 17:29:35 +0100
committerRobin Haberkorn <rh@travelping.com>2010-12-30 17:29:35 +0100
commit9cae35562022c7ccb0875effcc4f0f11320562b7 (patch)
tree905756dfe555fcaa664cac6cc845a1a1858e4b55
downloadperl-starter-9cae35562022c7ccb0875effcc4f0f11320562b7.tar.gz
preliminary kephra starter with embedded perl
* requires a MinGW environment and installed strawberry perl
-rw-r--r--Makefile25
-rw-r--r--icon.rc1
-rw-r--r--kephra_proton.icobin0 -> 766 bytes
-rw-r--r--kephra_vista_test.icobin0 -> 90378 bytes
-rw-r--r--starter.c76
5 files changed, 102 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..697e32c
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+CC := gcc
+RC := windres
+
+PERL := perl
+PERL_CCOPTS := $(shell $(PERL) -MExtUtils::Embed -e ccopts)
+#PERL_LDOPTS := $(shell $(PERL) -MExtUtils::Embed -e ldopts)
+PERL_LDOPTS := -L/c/strawberry/perl/lib/CORE -lperl510
+
+CFLAGS := $(PERL_CCOPTS) -std=gnu99
+CPPFLAGS :=
+LDFLAGS := $(PERL_LDOPTS) -Wl,--subsystem,windows
+
+all : kephra.exe
+
+starter_xsi.c:
+ $(PERL) -MExtUtils::Embed -e xsinit -- -o $@
+
+icon.o : icon.rc kephra_proton.ico
+ $(RC) $< $@
+
+kephra.exe : starter.o starter_xsi.o icon.o
+ $(CC) -o $@ $^ $(LDFLAGS)
+
+clean:
+ rm -f *.o starter_xsi.c kephra.exe
diff --git a/icon.rc b/icon.rc
new file mode 100644
index 0000000..428d0b1
--- /dev/null
+++ b/icon.rc
@@ -0,0 +1 @@
+DEFAULT ICON "kephra_proton.ico"
diff --git a/kephra_proton.ico b/kephra_proton.ico
new file mode 100644
index 0000000..82d26b3
--- /dev/null
+++ b/kephra_proton.ico
Binary files differ
diff --git a/kephra_vista_test.ico b/kephra_vista_test.ico
new file mode 100644
index 0000000..55e1eaf
--- /dev/null
+++ b/kephra_vista_test.ico
Binary files differ
diff --git a/starter.c b/starter.c
new file mode 100644
index 0000000..ed6f160
--- /dev/null
+++ b/starter.c
@@ -0,0 +1,76 @@
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <errno.h>
+
+#include <EXTERN.h>
+#include <perl.h>
+
+/* perl_parse prefix-parameters */
+static const char *prefix[] = {
+ "kephra", "-Ikre/site", "-Ikre/lib", "src\\kephra.pl", NULL
+};
+
+/* in starter_xsi.c */
+EXTERN_C void xs_init(pTHX);
+
+static PerlInterpreter *my_perl;
+
+int
+main(int argc, char **argv, char **env)
+{
+ int cParams = (sizeof(prefix)/sizeof(*prefix))-1 + argc-1;
+ const char **params, **para;
+
+ char *path, *p;
+
+ PERL_SYS_INIT3(&argc, &argv, &env);
+
+ /* fix working directory */
+ /* NOTE: this works since the last component will always be kephra.exe,
+ * otherwise use _splitpath_s
+ */
+ if (!(path = strdup(argv[0]))) {
+ fprintf(stderr, "strdup: OOM\n");
+ goto leave;
+ }
+ if ((p = strrchr(path, '\\'))) {
+ *p = '\0';
+ if (chdir(path)) {
+ perror("chdir");
+ goto leave;
+ }
+ }
+ free(path);
+
+ params = para = malloc(sizeof(const char *) * cParams);
+ if (!params) {
+ fprintf(stderr, "strdup: OOM\n");
+ goto leave;
+ }
+
+ /* copy prefix parameters */
+ for (const char **av = prefix; *av; av++)
+ *para++ = *av;
+
+ /* copy kephra.exe parameters */
+ for (int c = argc - 1; c; c--)
+ *para++ = *++argv;
+
+ my_perl = perl_alloc();
+ perl_construct(my_perl);
+
+ PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+
+ perl_parse(my_perl, xs_init, cParams, (char **)params, NULL);
+ perl_run(my_perl);
+
+ perl_destruct(my_perl);
+ perl_free(my_perl);
+
+ free(params);
+
+leave:
+ PERL_SYS_TERM();
+}