@@ -14,6 +14,7 @@
include Makefile.in
CFLAGS ?= -g -Wall
+LDFLAGS += -lz
PROG=risu
SRCS=risu.c comms.c risu_$(ARCH).c risu_reginfo_$(ARCH).c
@@ -31,7 +32,7 @@ all: $(PROG) $(BINS)
dump: $(RISU_ASMS)
$(PROG): $(OBJS)
- $(CC) $(STATIC) $(CFLAGS) -o $@ $^
+ $(CC) $(STATIC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
%.risu.asm: %.risu.bin
${OBJDUMP} -b binary -m $(ARCH) -D $^ > $@
@@ -6,6 +6,10 @@ compile() {
$CC $CFLAGS -c -o ${1}.o ${1}.c 2>/dev/null
}
+link() {
+ $LD $LDFLAGS -l${2} -o ${1} ${1}.o 2>/dev/null
+}
+
check_define() {
c=${tmp_dir}/check_define_${1}
cat > ${c}.c <<EOF
@@ -34,6 +38,50 @@ guess_arch() {
fi
}
+check_type() {
+ c=${tmp_dir}/check_type_${1}
+ cat > ${c}.c <<EOF
+#include <inttypes.h>
+#include <stdint.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+
+int main(void) { $1 thisone; return 0; }
+EOF
+ compile $c
+}
+
+check_lib() {
+ c=${tmp_dir}/check_lib${1}
+ cat > ${c}.c <<EOF
+#include <stdint.h>
+#include <$2.h>
+
+int main(void) { $3; return 0; }
+EOF
+ compile $c && link $c $1
+}
+
+generate_config() {
+ cfg=config.h
+ echo "generating config.h..."
+
+ echo "/* config.h - generated by the 'configure' script */" > $cfg
+ echo "#ifndef CONFIG_H" >> $cfg
+ echo "#define CONFIG_H 1" >> $cfg
+
+ if check_type uintptr_t ; then
+ echo "#define HAVE_UINTPTR_T 1" >> $cfg
+ fi
+ if check_type socklen_t ; then
+ echo "#define HAVE_SOCKLEN_T 1" >> $cfg
+ fi
+
+ echo "#endif /* CONFIG_H */" >> $cfg
+
+ echo "...done"
+}
+
generate_makefilein() {
m=Makefile.in
echo "generating Makefile.in..."
@@ -93,6 +141,7 @@ done
CC="${CC-${CROSS_PREFIX}gcc}"
AS="${AS-${CROSS_PREFIX}as}"
+LD="${LD-${CROSS_PREFIX}ld}"
OBJCOPY="${OBJCOPY-${CROSS_PREFIX}objcopy}"
OBJDUMP="${OBJDUMP-${CROSS_PREFIX}objdump}"
@@ -100,6 +149,12 @@ if test "x${ARCH}" = "x"; then
guess_arch
fi
+if ! check_lib z zlib "zlibVersion()"; then
+ echo "Cannot find libz compression library"
+ exit 1
+fi
+
+generate_config
generate_makefilein
echo "type 'make' to start the build"
@@ -25,6 +25,7 @@
#include <sys/mman.h>
#include <fcntl.h>
#include <string.h>
+#include <zlib.h>
#include "risu.h"
@@ -32,6 +33,7 @@ void *memblock = 0;
int apprentice_socket, master_socket;
int trace_file = 0;
+gzFile gz_trace_file;
sigjmp_buf jmpbuf;
@@ -52,13 +54,13 @@ void report_test_status(void *pc)
int write_trace(void *ptr, size_t bytes)
{
- size_t res = write(trace_file, ptr, bytes);
+ size_t res = gzwrite(gz_trace_file, ptr, bytes);
return res == bytes;
}
int read_trace(void *ptr, size_t bytes)
{
- size_t res = read(trace_file, ptr, bytes);
+ size_t res = gzread(gz_trace_file, ptr, bytes);
return res == bytes;
}
@@ -166,8 +168,9 @@ int master(int sock)
{
if (sigsetjmp(jmpbuf, 1))
{
- if (trace_file) {
- close(trace_file);
+ if (trace_file)
+ {
+ gzclose(gz_trace_file);
fprintf(stderr,"Done...\n");
return 0;
} else {
@@ -284,6 +287,7 @@ int main(int argc, char **argv)
if (trace_fn)
{
trace_file = open(trace_fn, O_WRONLY|O_CREAT, S_IRWXU);
+ gz_trace_file = gzdopen(trace_file, "wb9");
} else {
fprintf(stderr, "master port %d\n", port);
sock = master_connect(port);
@@ -295,6 +299,7 @@ int main(int argc, char **argv)
if (trace_fn)
{
trace_file = open(trace_fn, O_RDONLY);
+ gz_trace_file = gzdopen(trace_file, "rb");
} else {
fprintf(stderr, "apprentice host %s port %d\n", hostname, port);
sock = apprentice_connect(hostname, port);
This uses the magic of zlib's gzread/write interface to wrap the tracefile in compression. The code changes are tiny. I spent more time messing about with the configure/linker stuff to auto-detect bits. Signed-off-by: Alex Bennée <alex.bennee@linaro.org> --- Makefile | 3 ++- configure | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ risu.c | 13 +++++++++---- 3 files changed, 66 insertions(+), 5 deletions(-) -- 2.10.2