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