|
1 # Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
3 # This component and the accompanying materials are made available |
|
4 # under the terms of "Eclipse Public License v1.0" |
|
5 # which accompanies this distribution, and is available |
|
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Convert the given header file from Khronos into a stub implementation file |
|
15 # |
|
16 # |
|
17 |
|
18 use File::Basename; |
|
19 use File::Path; |
|
20 |
|
21 my $debug = 0; |
|
22 my $prog = "conv_khronos_openvg_hdr_to_cpp.pl"; |
|
23 my $source = shift; |
|
24 my $target = shift; |
|
25 my $operation_mode = shift; |
|
26 my @lines; |
|
27 |
|
28 if ($debug) { |
|
29 print "$prog: Args $source $target $operation_mode\n"; |
|
30 } |
|
31 |
|
32 if ("$operation_mode" eq "delete") { |
|
33 &cleanup(); |
|
34 exit 0; |
|
35 } elsif ("$operation_mode" eq "create") { |
|
36 &setupFiles(); |
|
37 &generateStubImplementation(); |
|
38 exit 0; |
|
39 } else { |
|
40 print "Usage error: $prog source target [create|delete]\n"; |
|
41 exit 1; |
|
42 } |
|
43 |
|
44 sub cleanup() |
|
45 { |
|
46 unlink "$target"; |
|
47 } |
|
48 |
|
49 sub setupFiles() |
|
50 { |
|
51 my $dir; |
|
52 $dir = dirname($target); |
|
53 mkpath $dir; |
|
54 |
|
55 open(INFILE, "$source") or die "Can't open input file $source; $!\n"; |
|
56 open(OUTFILE, ">$target") or die "Can't open output file $target; $!\n"; |
|
57 print OUTFILE '/* Auto-generated: ' . "$prog" . ' v1.0 */' . "\n"; |
|
58 print OUTFILE '/* Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved. */' . "\n"; |
|
59 } |
|
60 |
|
61 sub generateStubImplementation() |
|
62 { |
|
63 @lines = <INFILE>; |
|
64 my $s = ""; |
|
65 foreach (@lines) { |
|
66 # Find function prototype lines |
|
67 if (/^VG[U]?_API_CALL/ || length($s) != 0) { |
|
68 $s = $s.$_; |
|
69 if (/;/) { |
|
70 # Convert the function prototype into a stub function definition |
|
71 $s =~ s/\;$/ { }/; |
|
72 # Record the stub functions. There will be a stub implementation |
|
73 # file which includes these stub functions. This ensures we never |
|
74 # accidentally miss a new function added to the header file supplied |
|
75 # as $source. We expect compiler warnings (missing use of arguments, |
|
76 # absent return value etc.). The aim is to get something which will |
|
77 # compile so that a DEF file can be generated. |
|
78 print OUTFILE "$s"; |
|
79 $s = ""; |
|
80 } |
|
81 } |
|
82 } |
|
83 |
|
84 } |