Commits

M6 KVM committed bf7d091

Generate a user configuration header file - daybothreads-config.h

Comments (0)

Files changed (6)

 libdaybothreads_la_SOURCES += portthread.c
 libdaybothreads_la_SOURCES += atomscalar.c
 
-nobase_include_HEADERS = daybothreads.h
+nobase_include_HEADERS  = daybothreads.h
+nobase_include_HEADERS += daybothreads-config.h
 
 dnl $Id: configure.ac,v 0.6 2006/03/28 00:00:00 ddrp Exp $
 dnl Daybo Logic Threads Abstraction Library
-dnl Copyright (C) 2001-2006 Daybo Logic.
+dnl Copyright (C) 2001-2011 Daybo Logic.
 dnl All rights reserved.
 
 dnl Redistribution and use in source and binary forms, with or without

daybothreads-config.h.in

+/*
+ Daybo Logic Threads Abstraction Library
+ Copyright (C) 2001-2011 Daybo Logic.
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ 1. Redistributions of source code must retain the above copyright
+    notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+    notice, this list of conditions and the following disclaimer in the
+    documentation and/or other materials provided with the distribution.
+ 3. Neither the name of the project nor the names of its contributors
+    may be used to endorse or promote products derived from this software
+    without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ SUCH DAMAGE.
+
+  Daybo Logic,
+  Flat 2 Barker Court,
+  Victoria Avenue,
+  Redfield,
+  Bristol
+  England.
+  UK
+  BS5 9NW
+
+  +44 117 954 2306
+  David Duncan Ross Palmer <http://www.daybologic.co.uk/mailddrp/>
+  http://www.daybologic.co.uk/dev/daybothreads
+*/
+
+#ifndef INC_DAYBOTHREADS_CONFIG_H
+#define INC_DAYBOTHREADS_CONFIG_H
+/*-------------------------------------------------------------------------*/
+/*
+  This header is automagically generated from daybothreads-config.h.in,
+  do not modify.  It should be included by users of the library.
+*/
+
+#ifdef DAYBOTHREADS_SOURCE
+# error ("This header is designed to be included by library users, not library code")
+#endif /*DAYBOTHREADS_SOURCE*/
+
+/*
+  daybothreads.h expects one of these macros to be defined:
+  DAYBOTHREADS_NT
+  DAYBOTHREADS_PTH
+  DAYBOTHREADS_PTHREAD
+*/
+DAYBOTHREADS_BACKEND_DEFINE This line will be replaced.
+/*-------------------------------------------------------------------------*/
+#endif /*!INC_DAYBOTHREADS_CONFIG_H*/
+libdaybothreads (0.4.1-2) stable; urgency=low
+
+  * Write out daybothreads-config.h so users can determine back-end library
+    they need to link to.
+
+ -- David Palmer <palmer@overchat.org>  Sat, 26 Feb 2011 22:59:44 +0000
+
 libdaybothreads (0.4.1-1) stable; urgency=low
 
   * Initial packaged release.
 	dh_testdir
 
 	# Add here commands to compile the package.
+	perl -w ./make-user-conf.pl
 	$(MAKE)
 	$(MAKE) check
 

make-user-conf.pl

+#!/usr/bin/perl -w
+#
+# This script is used by the debian/rules file, to generate a user variant of the config.h,
+# called daybothreads-config.h from daybothreads-config.h and config.h
+#
+# This is just used to replace the line which contains __DAYBOTHREADS_BACKEND_DEFINE__
+# with whichever back-end we want to build against.  This is because this is the only
+# way that users of the compiled library can tell which back-end we were built to use.
+#
+
+use strict;
+use warnings;
+use diagnostics;
+
+use constant CONFIG_H => 'config.h';
+use constant DAYBOTHREADS_CONFIG_H => 'daybothreads-config.h';
+use constant DAYBOTHREADS_CONFIG_H_IN => 'daybothreads-config.h.in';
+use constant FAIL_OPEN => 'opening';
+use constant FAIL_WRITE => 'writing';
+use constant EXIT_SUCCESS => (0);
+use constant EXIT_FAILURE => (1);
+use constant SEARCH_LINE => 'DAYBOTHREADS_BACKEND_DEFINE';
+
+sub Main();
+sub Fail($$);
+sub IsKnown($);
+
+sub Main()
+{
+  my $macro = undef;
+  my @config_txt;
+  if ( open(my $config_h, '< ' . CONFIG_H()) ) {
+    @config_txt = <$config_h>;
+    close($config_h);
+  } else {
+    Fail(FAIL_OPEN(), CONFIG_H());
+  }
+
+  foreach my $conf_line ( @config_txt ) {
+    chomp($conf_line);
+    # Look for defines, just the names, not the substs
+    if ( $conf_line =~ m/^\#define\s+([A-Z0-9_]+)/ ) {
+      if ( IsKnown($1) ) {
+        $macro = $1;
+        last;
+      }
+    }
+  }
+
+  if ( !$macro ) {
+    printf(STDERR "No known back-end detected in %s\n", CONFIG_H());
+    return EXIT_FAILURE();
+  }
+
+  if ( open(my $daybothreads_config_h_in, '< ' . DAYBOTHREADS_CONFIG_H_IN()) ) {
+    if ( open(my $daybothreads_config_h, '> ' . DAYBOTHREADS_CONFIG_H()) ) {
+      my $fail = 0;
+      while ( my $l = <$daybothreads_config_h_in> ) {
+        $l = '#define ' . $macro . "\n"
+          if ( index($l, SEARCH_LINE()) > -1 );
+
+        if ( print($daybothreads_config_h $l) != 1 ) {
+          $fail = 1;
+          last;
+        }
+      }
+      close($daybothreads_config_h);
+      Fail(FAIL_WRITE(), DAYBOTHREADS_CONFIG_H_IN())
+        if ( $fail );
+    } else {
+      close($daybothreads_config_h_in);
+      Fail(FAIL_WRITE(), DAYBOTHREADS_CONFIG_H());
+    }
+    close($daybothreads_config_h_in);
+  } else {
+    Fail(FAIL_OPEN(), DAYBOTHREADS_CONFIG_H_IN());
+  }
+
+  return EXIT_SUCCESS();
+}
+
+sub Fail($$)
+{
+  my ( $Doing, $FileName ) = @_;
+  printf(STDERR "Failure whilst %s %s - %s\n", $Doing, $FileName, $!);
+  exit(EXIT_FAILURE());
+}
+
+sub IsKnown($)
+{
+  my $Macro = $_[0];
+  my @known = (
+    'DAYBOTHREADS_NT',
+    'DAYBOTHREADS_PTH',
+    'DAYBOTHREADS_PTHREAD'
+  );
+
+  foreach my $k ( @known ) {
+    return 1 if ( $Macro eq $k );
+  }
+  return 0;
+}
+
+exit(Main());
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.