-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_export_header.pl
executable file
·126 lines (106 loc) · 3.05 KB
/
generate_export_header.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#! /usr/bin/perl
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 = '1.2';
# ******************************************************************
# Subroutine Section
# ******************************************************************
sub generate_export_header {
my($name, $output) = @_;
my $fh = new FileHandle();
my $status = 0;
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";
}
else {
print STDERR "ERROR: Unable to write to $output\n";
++$status;
}
return $status;
}
sub usageAndExit {
my $str = shift;
print STDERR "$str\n" if (defined $str);
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 . '_' . ($name =~ /^[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));