From b2f9cb29d7978ecd1c27b76670d8a99f4acd85ed Mon Sep 17 00:00:00 2001 From: short <> Date: Sun, 23 May 2004 15:20:54 +0000 Subject: [PATCH] +Option --enable-bundle for the fully static built single-file binary. --- Makefile.am | 3 +- autogen.pl | 5 ++-- configure.ac | 9 ++++++ init.d/Makefile.am | 27 +++++++++++++++++ init.d/udpgate.init | 61 ++++++++++++++++++++++++++++++++++++++ src/Makefile.am | 20 ++++++++++++- src/bundle.h | 35 ++++++++++++++++++++++ src/bundle.pl | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 239 insertions(+), 5 deletions(-) create mode 100644 init.d/Makefile.am create mode 100755 init.d/udpgate.init create mode 100644 src/bundle.h create mode 100755 src/bundle.pl diff --git a/Makefile.am b/Makefile.am index e1e04e5..dc9060a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -20,7 +20,8 @@ include $(top_srcdir)/Makefile-head.am AUTOMAKE_OPTIONS=gnu ACLOCAL_AMFLAGS=-I macros -SUBDIRS=macros src po +# Keep 'po' and 'init.d' before 'src' for our .gmo files bundling. +SUBDIRS=macros po init.d src ## to automatically rebuild aclocal.m4 if any of the macros in ## `macros/' change @MAINT@include macros/macros.dep diff --git a/autogen.pl b/autogen.pl index 1386fee..001f2c6 100755 --- a/autogen.pl +++ b/autogen.pl @@ -35,13 +35,12 @@ AutoGen->run( "COPYRIGHT_HOLDER"=>'Jan Kratochvil ', "ARGV"=>\@ARGV, "clean"=>[qw( - .include_test_false.c - .include_test_all.stamp *.pod.pl *.pod *.[0-9] ./ChangeLog.bak ./debian/changelog - ./doc/*-pod.* + ./init.d/udpgate ./src/udpgate + ./src/bundle.c ./src/ui-gnome-callbacks.[ch] ./src/ui-gnome-interface.[ch] ./src/ui-gnome-support.[ch] diff --git a/configure.ac b/configure.ac index 9d3c40b..ac82242 100644 --- a/configure.ac +++ b/configure.ac @@ -58,8 +58,16 @@ AM_CONDITIONAL(MAINTAINER_MODE,[test "$USE_MAINTAINER_MODE" = "yes"]) AC_ARG_ENABLE(man-pages, [ --enable-man-pages=no/yes/auto pod2man(1) required for man pages (def.=yes)],,enable_man_pages=yes) +AC_ARG_ENABLE(bundle, + [ --enable-bundle Build single binary containing locale and init.d files (def.=no)],,enable_bundle=no) +AM_CONDITIONAL(ENABLE_BUNDLE,[ test "x$enable_bundle" = "xyes" ]) +if test "x$enable_bundle" = "xyes" +then + AC_DEFINE(ENABLE_BUNDLE,,[Build single binary containing locale and init.d files.]) +fi + PERL= AC_PATH_PROGS(PERL,perl5 perl) AM_CONDITIONAL(HAVE_PERL,test -n "$PERL") @@ -235,6 +243,7 @@ udpgate.spec ./macros/glade-w.sh Makefile ./macros/Makefile +./init.d/Makefile ./src/Makefile ]) diff --git a/init.d/Makefile.am b/init.d/Makefile.am new file mode 100644 index 0000000..9e4788d --- /dev/null +++ b/init.d/Makefile.am @@ -0,0 +1,27 @@ +# $Id$ +# automake source for UDP Gateway startup scripts Makefile +# Copyright (C) 2004 Jan Kratochvil +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; exactly version 2 of June 1991 is required +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +include $(top_srcdir)/Makefile-head.am + +initddir=$(sysconfdir)/rc.d/init.d +initd_SCRIPTS=udpgate +EXTRA_DIST+=udpgate.init +CLEANFILES+=udpgate +udpgate: udpgate.init + $(LN_S) $< $@ + diff --git a/init.d/udpgate.init b/init.d/udpgate.init new file mode 100755 index 0000000..bb48bd6 --- /dev/null +++ b/init.d/udpgate.init @@ -0,0 +1,61 @@ +#! /bin/sh +# Startup script for udpgate +# +# chkconfig: 2345 98 02 +# description: UDP packats gateway + +# Source function library. +. /etc/rc.d/init.d/functions + +[ -f /usr/sbin/udpgate ] || exit 0 + +prog="udpgate" + +start() { + echo -n $"Starting $prog: " + daemon udpgate --start + RETVAL=$? + echo + return $RETVAL +} + +stop() { + if test "x`pidof udpgate`" != x; then + echo -n $"Stopping $prog: " + killproc udpgate + echo + fi + RETVAL=$? + return $RETVAL +} + +case "$1" in + start) + start + ;; + + stop) + stop + ;; + + status) + status udpgate + ;; + restart) + stop + start + ;; + condrestart) + if test "x`pidof udpgate`" != x; then + stop + start + fi + ;; + + *) + echo $"Usage: $0 {start|stop|restart|condrestart|status}" + exit 1 + +esac + +exit $RETVAL diff --git a/src/Makefile.am b/src/Makefile.am index afc9da3..cb6d3ba 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -36,6 +36,23 @@ GNOME_SRCS= \ $(GLADE_OUT) endif +if ENABLE_BUNDLE + +nodist_udpgate_SOURCES=bundle.c + +BUNDLE_SRCS= \ + bundle.h + +EXTRA_DIST+= \ + bundle.pl + +# FIXME: GNU make(1) dependency by $(addprefix ...) +bundle_files=$(top_srcdir)/init.d/$(PACKAGE).init $(addprefix $(top_builddir)/$(POSUB)/,$(CATALOGS)) +bundle.c: bundle.pl $(bundle_files) + $(PERL) bundle.pl $(bundle_files) >$@ + +endif + udpgate_SOURCES= \ configuration.c \ configuration.h \ @@ -47,7 +64,8 @@ udpgate_SOURCES= \ packet.h \ ui-line.c \ ui-line.h \ - $(GNOME_SRCS) + $(GNOME_SRCS) \ + $(BUNDLE_SRCS) EXTRA_DIST+= \ $(GLADE_IN) diff --git a/src/bundle.h b/src/bundle.h new file mode 100644 index 0000000..12289c1 --- /dev/null +++ b/src/bundle.h @@ -0,0 +1,35 @@ +/* $Id$ + * Include file for the bundled files with UDPGate. + * Copyright (C) 2004 Jan Kratochvil + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; exactly version 2 of June 1991 is required + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + + +#ifndef _UDPGATE_BUNDLE_H +#define _UDPGATE_BUNDLE_H 1 + + +#include +#include + + +G_BEGIN_DECLS + +GHashTable *bundle_hash_new(void); + +G_END_DECLS + + +#endif /* _UDPGATE_BUNDLE_H */ diff --git a/src/bundle.pl b/src/bundle.pl new file mode 100755 index 0000000..fdd252b --- /dev/null +++ b/src/bundle.pl @@ -0,0 +1,84 @@ +#! /usr/bin/perl +# +# $Id$ +# Perl generator for the bundled files with UDPGate. +# Copyright (C) 2004 Jan Kratochvil +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; exactly version 2 of June 1991 is required +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + +use vars qw($VERSION); +$VERSION=do { my @r=(q$Revision$=~/\d+/g); sprintf "%d.".("%03d"x$#r),@r; }; +use strict; +use warnings; + +use File::Basename; + + +print <<"EOH"; +/* AUTOGENERATED FILE! DO NOT EDIT! + * Bundled files with UDPGate. + */ + + +#include "config.h" + +#include + +#include "bundle.h" /* self */ + + +GHashTable *bundle_hash_new(void) +{ +static GHashTable *hash; +EOH +my @files; +for my $pathname (@ARGV) { + local *F; + open F,$pathname or die "Cannot open $pathname: $!"; + local $/=undef(); + my $F=; + close F or warn "Cannot close $pathname: $!"; + my $filename=basename $pathname; + (my $filename_sym=$filename)=~tr/a-zA-Z/_/c; + $filename_sym=~s/^_*//; # Prevent conflict with system internal symbols. + push @files,{ + "filename" =>$filename, + "filename_sym"=>$filename_sym, + }; + my $Fout=unpack "H*",$F; + $Fout=~s/../0x$&,/g; + $Fout=~s/(?:.....){1,16}/\t\t$&\n/g; + $Fout=~s/,\n$//; + print <<"EOH"; +static const guint8 ${filename_sym}_data[]={ +$Fout + }; +EOH + } +print <<"EOH"; + + if (!hash) { + hash=g_hash_table_new(g_str_hash,g_str_equal); +EOH + for (@files) { + print "\t\tg_hash_table_insert(hash,\"".$_->{"filename"}."\",(gpointer)".$_->{"filename_sym"}."_data);\n"; + } +print <<"EOH"; + } + return hash; +} + +/* EOF */ +EOH -- 1.8.3.1