218 |
bj |
1 |
eval '(exit $?0)' && eval 'exec perl -w -S $0 ${1+"$@"}'
|
|
|
2 |
& eval 'exec perl -w -S $0 $argv:q'
|
|
|
3 |
if 0;
|
|
|
4 |
|
|
|
5 |
# ******************************************************************
|
|
|
6 |
# Author: Chad Elliott
|
|
|
7 |
# Date: 3/1/2006
|
|
|
8 |
# $Id: generate_export_header.pl,v 1.2 2006/03/15 18:48:14 elliott_c Exp $
|
|
|
9 |
# Description: Generate an export header file for use with various compilers
|
|
|
10 |
# ******************************************************************
|
|
|
11 |
|
|
|
12 |
# ******************************************************************
|
|
|
13 |
# Pragma Section
|
|
|
14 |
# ******************************************************************
|
|
|
15 |
|
|
|
16 |
use strict;
|
|
|
17 |
use FileHandle;
|
|
|
18 |
use File::Basename;
|
|
|
19 |
|
|
|
20 |
# ******************************************************************
|
|
|
21 |
# Data Section
|
|
|
22 |
# ******************************************************************
|
|
|
23 |
|
|
|
24 |
my($version) = '$Id: generate_export_header.pl,v 1.2 2006/03/15 18:48:14 elliott_c Exp $';
|
|
|
25 |
$version =~ s/.*\s+(\d+[\.\d]+)\s+.*/$1/;
|
|
|
26 |
|
|
|
27 |
# ******************************************************************
|
|
|
28 |
# Subroutine Section
|
|
|
29 |
# ******************************************************************
|
|
|
30 |
|
|
|
31 |
sub generate_export_header {
|
|
|
32 |
my($name) = shift;
|
|
|
33 |
my($output) = shift;
|
|
|
34 |
my($fh) = new FileHandle();
|
|
|
35 |
my($status) = 0;
|
|
|
36 |
|
|
|
37 |
if (open($fh, ">$output")) {
|
|
|
38 |
$name = uc($name);
|
|
|
39 |
print $fh <<EOM
|
|
|
40 |
#ifndef ${name}_EXPORT_H
|
|
|
41 |
#define ${name}_EXPORT_H
|
|
|
42 |
|
|
|
43 |
#if !defined(${name}_HAS_DLL)
|
|
|
44 |
# if defined(${name}_AS_STATIC_LIBS)
|
|
|
45 |
# define ${name}_HAS_DLL 0
|
|
|
46 |
# else
|
|
|
47 |
# define ${name}_HAS_DLL 1
|
|
|
48 |
# endif
|
|
|
49 |
#endif
|
|
|
50 |
|
|
|
51 |
#if (${name}_HAS_DLL == 1)
|
|
|
52 |
# if defined(__SUNPRO_CC) && (__SUNPRO_CC >= 0x550)
|
|
|
53 |
# if defined(${name}_BUILD_DLL)
|
|
|
54 |
# define ${name}_Export __symbolic
|
|
|
55 |
# else
|
|
|
56 |
# define ${name}_Export __global
|
|
|
57 |
# endif
|
|
|
58 |
# elif defined(WIN32) || defined(UNDER_CE) || defined(__CYGWIN__)
|
|
|
59 |
# if defined(${name}_BUILD_DLL)
|
|
|
60 |
# define ${name}_Export __declspec(dllexport)
|
|
|
61 |
# else
|
|
|
62 |
# define ${name}_Export __declspec(dllimport)
|
|
|
63 |
# endif
|
|
|
64 |
# elif (defined(__GNUC__) && (__GNUC__ >= 4))
|
|
|
65 |
# if defined(${name}_BUILD_DLL)
|
|
|
66 |
# define ${name}_Export __attribute__((visibility("default")))
|
|
|
67 |
# else
|
|
|
68 |
# define ${name}_Export
|
|
|
69 |
# endif
|
|
|
70 |
# else
|
|
|
71 |
# define ${name}_Export
|
|
|
72 |
# endif
|
|
|
73 |
#else
|
|
|
74 |
# define ${name}_Export
|
|
|
75 |
#endif
|
|
|
76 |
|
|
|
77 |
#endif
|
|
|
78 |
EOM
|
|
|
79 |
;
|
|
|
80 |
close($fh);
|
|
|
81 |
print "Output written to $output\n";
|
|
|
82 |
}
|
|
|
83 |
else {
|
|
|
84 |
print STDERR "ERROR: Unable to write to $output\n";
|
|
|
85 |
++$status;
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
return $status;
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
sub usageAndExit {
|
|
|
92 |
my($str) = shift;
|
|
|
93 |
if (defined $str) {
|
|
|
94 |
print STDERR "$str\n";
|
|
|
95 |
}
|
|
|
96 |
print STDERR "Generate Export Header v$version\n",
|
|
|
97 |
"Usage: ", basename($0), " <library name> [output file]\n";
|
|
|
98 |
exit(0);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
# ******************************************************************
|
|
|
102 |
# Main Section
|
|
|
103 |
# ******************************************************************
|
|
|
104 |
|
|
|
105 |
my($name) = shift;
|
|
|
106 |
my($output) = shift;
|
|
|
107 |
|
|
|
108 |
if (!defined $name) {
|
|
|
109 |
usageAndExit();
|
|
|
110 |
}
|
|
|
111 |
elsif (index($name, '-') == 0) {
|
|
|
112 |
usageAndExit();
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
if (!defined $output) {
|
|
|
116 |
$output = $name . '_' . (substr($name, 0, 1) =~ /[A-Z]/ ? 'E' : 'e') .
|
|
|
117 |
'xport.h';
|
|
|
118 |
}
|
|
|
119 |
|
|
|
120 |
if ($name =~ s/^\d+//) {
|
|
|
121 |
print "WARNING: Removing beginning numbers from export name.\n";
|
|
|
122 |
}
|
|
|
123 |
if ($name =~ s/-\s/_/g) {
|
|
|
124 |
print "WARNING: Converting dashes and ",
|
|
|
125 |
"whitespace to underscores in export name.\n";
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
exit(generate_export_header($name, $output));
|