summaryrefslogtreecommitdiff
path: root/generate_export_header.pl
diff options
context:
space:
mode:
authorelliott_c <ocielliottc@users.noreply.github.com>2006-03-06 18:09:15 +0000
committerelliott_c <ocielliottc@users.noreply.github.com>2006-03-06 18:09:15 +0000
commita3717a1908096b14a4cacb951e92999aa4216216 (patch)
tree3d581685e2d242c8c38742c9e724f531b56deb4d /generate_export_header.pl
parentc02c149fdfadd19862193bc9283263497694d4a0 (diff)
downloadMPC-a3717a1908096b14a4cacb951e92999aa4216216.tar.gz
ChangeLogTag: Mon Mar 6 18:09:36 UTC 2006 Chad Elliott <elliott_c@ociweb.com>
Diffstat (limited to 'generate_export_header.pl')
-rwxr-xr-xgenerate_export_header.pl121
1 files changed, 121 insertions, 0 deletions
diff --git a/generate_export_header.pl b/generate_export_header.pl
new file mode 100755
index 00000000..f6e8d6cd
--- /dev/null
+++ b/generate_export_header.pl
@@ -0,0 +1,121 @@
+eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
+ & eval 'exec perl -w -S $0 $argv:q'
+ if 0;
+
+# ******************************************************************
+# Author: Chad Elliott
+# Date: 3/1/2006
+# $Id$
+# Description: Generate an export header file for use with various compilers
+# ******************************************************************
+
+# ******************************************************************
+# Pragma Section
+# ******************************************************************
+
+use strict;
+use FileHandle;
+use File::Basename;
+
+# ******************************************************************
+# Data Section
+# ******************************************************************
+
+my($version) = '$Id$';
+$version =~ s/.*\s+(\d+[\.\d]+)\s+.*/$1/;
+
+# ******************************************************************
+# Subroutine Section
+# ******************************************************************
+
+sub generate_export_header {
+ my($name) = shift;
+ my($output) = shift;
+ my($fh) = new FileHandle();
+
+ if (open($fh, ">$output")) {
+ $name = uc($name);
+ print $fh <<EOM
+#ifndef ${name}_EXPORT_H
+#define ${name}_EXPORT_H
+
+#if !defined(${name}_HAS_DLL)
+# if defined(${name}_AS_STATIC_LIBS)
+# define ${name}_HAS_DLL 0
+# else
+# define ${name}_HAS_DLL 1
+# endif
+#endif
+
+#if (${name}_HAS_DLL == 1)
+# if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)
+# if defined(${name}_BUILD_DLL)
+# define ${name}_Export __symbolic
+# else
+# define ${name}_Export __global
+# endif
+# elif defined(WIN32) || defined(UNDER_CE) || defined(__CYGWIN__)
+# if defined(${name}_BUILD_DLL)
+# define ${name}_Export __declspec(dllexport)
+# else
+# define ${name}_Export __declspec(dllimport)
+# endif
+# elif (defined(__GNUC__) && (__GNUC__ >= 4))
+# if defined(${name}_BUILD_DLL)
+# define ${name}_Export __attribute__((visibility("default")))
+# else
+# define ${name}_Export
+# endif
+# else
+# define ${name}_Export
+# endif
+#else
+# define ${name}_Export
+#endif
+
+#endif
+EOM
+;
+ close($fh);
+ print "Output written to $output\n";
+ }
+}
+
+sub usageAndExit {
+ my($str) = shift;
+ if (defined $str) {
+ print STDERR "$str\n";
+ }
+ print STDERR "Generate Export Header v$version\n",
+ "Usage: ", basename($0), " <library name> [output file]\n";
+ exit(0);
+}
+
+# ******************************************************************
+# Main Section
+# ******************************************************************
+
+my($name) = shift;
+my($output) = shift;
+
+if (!defined $name) {
+ usageAndExit();
+}
+elsif (index($name, '-') == 0) {
+ usageAndExit();
+}
+
+if (!defined $output) {
+ $output = $name . '_' . (substr($name, 0, 1) =~ /[A-Z]/ ? 'E' : 'e') .
+ 'xport.h';
+}
+
+if ($name =~ s/^\d+//) {
+ print "WARNING: Removing beginning numbers from export name.\n";
+}
+if ($name =~ s/-\s/_/g) {
+ print "WARNING: Converting dashes and ",
+ "whitespace to underscores in export name.\n";
+}
+
+exit(generate_export_header($name, $output));