summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2009-03-23 17:28:19 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2009-03-23 17:28:19 +0000
commitabdbd16aed11a024d88920b3ad42b62db7e90ddd (patch)
treed15994e486e40836b2a93a57c6dd3861c4959f3f
downloadmakerun-abdbd16aed11a024d88920b3ad42b62db7e90ddd.tar.gz
makerun-abdbd16aed11a024d88920b3ad42b62db7e90ddd.tar.bz2
Move makerun into its own directory
svn path=/trunk/tools/makerun/; revision=6826
-rw-r--r--Makefile85
-rw-r--r--makerun.c110
2 files changed, 195 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b69eadf
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,85 @@
+BINARIES := makerun
+
+CFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
+ -Wwrite-strings -Wstrict-prototypes \
+ -Wnested-externs -pedantic -std=c99 \
+ -Wno-format-zero-length -Wformat-security -Wstrict-aliasing=2 \
+ -Wmissing-format-attribute -Wunused -Wunreachable-code \
+ -Wformat=2 -Werror-implicit-function-declaration \
+ -Wmissing-declarations -Wmissing-prototypes
+
+ECHO := echo
+INSTALL := install
+MKDIR := mkdir
+MKDIRFLAGS := -p
+
+# Detect host platform
+HOST := $(shell uname -s)
+ifeq ($(HOST),)
+ # Assume RISC OS, as uname's broken there)
+ HOST := riscos
+else
+ ifeq ($(HOST),RISC OS)
+ HOST := riscos
+ endif
+endif
+
+ifeq ($(HOST),riscos)
+ ifeq ($(TARGET),)
+ TARGET := riscos
+ endif
+endif
+
+ifeq ($(TARGET),riscos)
+ ifeq ($(HOST),riscos)
+ GCCSDK_INSTALL_ENV := <NSLibs$$Dir>
+ CC := gcc
+ EXEEXT :=
+ SUBTARGET :=
+ else
+ GCCSDK_INSTALL_CROSSBIN ?= /home/riscos/cross/bin
+ GCCSDK_INSTALL_ENV ?= /home/riscos/env
+ CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
+ ifneq (,$(findstring arm-unknown-riscos-gcc,$(CC)))
+ EXEEXT := ,e1f
+ SUBTARGET := -elf-
+ else
+ EXEEXT := ,ff8
+ SUBTARGET := -aof-
+ endif
+ endif
+
+ CFLAGS += -Driscos -mpoke-function-name -I$(GCCSDK_INSTALL_ENV)/include
+ LIBS = -L$(GCCSDK_INSTALL_ENV)/lib -lOSLib32
+ PREFIX = $(GCCSDK_INSTALL_ENV)
+else
+ CFLAGS += -g
+ LIBS =
+ PREFIX = $(GCCSDK_INSTALL_CROSSBIN)/..
+endif
+
+-include Makefile.config
+
+BINDIR = build-$(TARGET)$(SUBTARGET)bin
+
+BINS = $(addprefix $(BINDIR)/, $(addsuffix $(EXEEXT), $(BINARIES)))
+
+.PHONY: all clean install uninstall
+
+all: $(BINS)
+
+$(BINDIR)/%$(EXEEXT): %.c
+ @$(ECHO) " BUILD: $@"
+ @$(MKDIR) $(MKDIRFLAGS) $(BINDIR)
+ @$(CC) $(CFLAGS) -o $@ $< $(LIBS)
+
+install: $(BINS)
+ $(MKDIR) $(MKDIRFLAGS) $(DESTDIR)$(PREFIX)/bin
+ $(INSTALL) -m 755 $(BINS) $(DESTDIR)$(PREFIX)/bin
+
+uninstall:
+ $(RM) $(addprefix $(DESTDIR)$(PREFIX)/bin/, $(addsuffix $(EXEEXT), $(BINARIES)))
+
+clean:
+ $(RM) -r $(BINDIR)
+
diff --git a/makerun.c b/makerun.c
new file mode 100644
index 0000000..8871b8f
--- /dev/null
+++ b/makerun.c
@@ -0,0 +1,110 @@
+#include <stdio.h>
+#include <string.h>
+
+#ifdef __riscos
+ #include <unixlib/local.h>
+ #include <oslib/osfile.h>
+#endif
+
+struct header {
+ unsigned int decompress;
+ unsigned int selfreloc;
+ unsigned int zeroinit;
+ unsigned int entry;
+ unsigned int exit;
+ unsigned int rosize;
+ unsigned int rwsize;
+ unsigned int dbsize;
+ unsigned int zisize;
+ unsigned int dbtype;
+ unsigned int base;
+ unsigned int wkspace;
+};
+
+int main(int argc, char **argv)
+{
+ FILE *f, *g;
+ struct header header;
+ unsigned int file_size;
+ char buf[256];
+
+ if (argc != 4) {
+ fprintf(stderr, "Usage: %s <runimage> <input> <output>\n",
+ argv[0]);
+ return 1;
+ }
+
+ f = fopen(argv[1], "rb");
+ if (f == NULL) {
+ fprintf(stderr, "Failed opening %s\n", argv[1]);
+ return 1;
+ }
+
+ fread((void*)&header, sizeof(struct header), 1, f);
+
+ fseek(f, 0, SEEK_END);
+ file_size = ftell(f);
+
+ fclose(f);
+
+ if (header.decompress == 0x464c457f /* FLE\x7f */) {
+ /* ELF binary */
+ file_size += 0x8000; /* Add 32k of scratch space */
+ } else {
+ if ((header.entry >> 24) != 0xEB) {
+ fprintf(stderr, "%s not binary\n", argv[1]);
+ return 1;
+ }
+
+ if (header.rosize + header.rwsize + header.dbsize !=
+ file_size) {
+ if ((header.decompress >> 24) != 0xEB) {
+ fprintf(stderr, "Mismatched field sizes\n");
+ return 1;
+ }
+ }
+
+ file_size = header.rosize + header.rwsize +
+ header.dbsize + header.zisize +
+ 0x8000 /* 32k of scratch space */;
+ }
+
+ f = fopen(argv[2], "r");
+ if (f == NULL) {
+ fprintf(stderr, "Failed opening %s\n", argv[2]);
+ return 1;
+ }
+
+ g = fopen(argv[3], "w");
+ if (g == NULL) {
+ fclose(f);
+ fprintf(stderr, "Failed opening %s\n", argv[3]);
+ return 1;
+ }
+
+ while (fgets(buf, sizeof(buf), f) != NULL) {
+ if (strncmp(buf, "WIMPSLOT\n", 9) == 0) {
+ fprintf(g, "WimpSlot -min %dk -max %dk\n",
+ (file_size / 1024), (file_size / 1024));
+ } else {
+ fputs(buf, g);
+ }
+ }
+
+ fclose(g);
+ fclose(f);
+
+#ifdef __riscos
+ if (__riscosify(argv[3], 0, __RISCOSIFY_STRICT_UNIX_SPECS |
+ __RISCOSIFY_NO_SUFFIX | __RISCOSIFY_FILETYPE_NOT_SET,
+ buf, sizeof(buf), NULL) == NULL) {
+ fprintf(stderr, "Riscosify failed\n");
+ return 1;
+ }
+
+ osfile_set_type(buf, osfile_TYPE_OBEY);
+#endif
+
+ return 0;
+}
+