987bd6461651ac296630ed087a3e4704cc4241a9
[deliverable/titan.core.git] / regression_test / XML / XmlWorkflow / bin / prj2mk.pl
1 #!/usr/bin/perl -w
2 ###############################################################################
3 # Copyright (c) 2000-2016 Ericsson Telecom AB
4 # All rights reserved. This program and the accompanying materials
5 # are made available under the terms of the Eclipse Public License v1.0
6 # which accompanies this distribution, and is available at
7 # http://www.eclipse.org/legal/epl-v10.html
8 #
9 # Contributors:
10 # Balasko, Jeno
11 # Kovacs, Ferenc
12 # Pandi, Krisztian
13 # Raduly, Csaba
14 #
15 ###############################################################################
16
17 use strict;
18
19 if ($] < 5.006) {
20 # ancient perl, we must be on Solaris :(
21 my @perlloc = qw( /proj/TTCN/Tools/perl-5.10.1/bin/perl /mnt/TTCN/Tools/perl-5.10.1/bin/perl );
22 foreach (@perlloc) {
23 if (-x $_) {
24 warn "Let's try with $_ instead";
25 exec( $_, $0, @ARGV ) or die "That didn't work either: $!";
26 }
27 }
28 }
29
30
31 use strict;
32
33 die "Need an argument" unless 0 < @ARGV;
34 open(PRJ, '<' . $ARGV[0]) or die "open prj: $!";
35
36 my $prj_dir = $ARGV[0]; # ARGV[0] is the .prj name
37 my $local_prj = 0;
38 # Strip all non-slash characters (filename) after the last slash;
39 # this keeps the directory part. If ARGV[0] was just a filename with no dirs,
40 # then it's the current directory.
41 do {
42 $prj_dir = './';
43 $local_prj = 1;
44 } unless $prj_dir =~ s!/[^/]+$!/!;
45
46 # Pick up parameters from the environment
47 my $split = defined $ENV{CODE_SPLIT} ? '-Utype' : '';
48 my $rt2 = defined $ENV{RT2} ? '-R' : '';
49
50 my %files;
51 my @excluded;
52 my $cfgfile;
53
54 # Line-by-line analysis of an XML file...
55 while ( <PRJ> )
56 {
57 chomp;
58 my $loc;
59 if (($loc) = m/path="([^"]+)"/ or ($loc) = m/<(?:Module|Other_Source)>([^<]+)<\/(?:Module|Other_Source)>/) {
60 # If it has no path, it's next to the .prj
61 # If it has no absolute path, base it off the .prj dir
62 if ($loc !~ m{^/}) {
63 $loc = $prj_dir . $loc;
64 }
65 # Testports are stored locally
66 $loc =~ s!^.*vobs/.*?/.*?/TestPorts!..!;
67 $files{ $loc } = 1;
68 }
69 elsif ( ($loc) = m{<UnUsed_List>([^<]+)</UnUsed_List>} ) {
70 die "Didn't expect another UnUsed_List" if scalar @excluded;
71 @excluded = split /,/, $loc;
72 }
73 elsif ( m[<Config>([^<]+)</Config>] ) {
74 $cfgfile = $1;
75 # If it has no path, it's next to the .prj
76 if ($cfgfile !~ m{/}) {
77 $cfgfile = $prj_dir . $cfgfile;
78 }
79 }
80 }
81
82 close(PRJ) or die "close prj: $!";
83
84 # hash slice deletion: deletes all keys in @excluded from %files
85 delete @files{ @excluded };
86
87 my @files = keys %files;
88
89 # Filter out files which are in the current directory.
90 # They should not be symlinked
91 my @symlinkfiles = $local_prj ? @files : grep { $_ !~ m(^./) } @files;
92
93 # Symlink all files into bin/
94 print "Symlinking " . scalar @symlinkfiles . " files\n";
95 system("ln -s @symlinkfiles ./");
96
97 # Remove the path from the filenames
98 map { s!.+/!!g } @files;
99
100 # Generate the makefile
101 print("LD_LIBRARY_PATH is $ENV{LD_LIBRARY_PATH}\n");#temporary debug printout
102 print("$ENV{TTCN3_DIR}/bin/ttcn3_makefilegen -gs $split $rt2 -e XmlTest @files\n");
103
104 system( "\$TTCN3_DIR/bin/ttcn3_makefilegen -gs $split $rt2 -e XmlTest -o Makefile.1 @files");
105
106 # Post-process the generated makefile
107 open(MAKEFILE_IN , '<' . 'Makefile.1') or die "open input: $!";
108 open(MAKEFILE_OUT, '>' . 'Makefile' ) or die "open output: $!";
109
110 $\ = $/;
111 # Uncomment the TTCN3_DIR in the makefile
112 # (which points to the TTCN3_DIR set in Makefile.cfg)
113 # Add the bin directory to the fromt of the PATH,
114 # so calls to xsd2ttcn without full path still find the "right" one.
115 while (<MAKEFILE_IN>) {
116 chomp;
117
118 # Don't bother editing these settings in the Makefile by hand
119 next if s{^(PLATFORM|CXX|CPPFLAGS|CXXFLAGS|LDFLAGS|OPENSSL_DIR|XMLDIR) [:+]?=.*}
120 {# $1 Overridden by Makefile.cfg};
121
122 # remove Makefile.1 from OTHER_FILES (added by makefilegen due to -o)
123 next if s!(OTHER_FILES = .*) Makefile.1!$1!;
124
125 # Always put in location info; emit GCC-style messages
126 next if s/(COMPILER_FLAGS) =.*/$1 := /;
127
128 # RT2 flag is added into TTCN3_COMPILER by Makefile.regression
129 next if s!\$\(TTCN3_DIR\)/bin/compiler!\$(TTCN3_COMPILER)!;
130
131 # Include common settings for the regression test.
132 # It overrides local settings in the Makefile.
133 if ( /Rules for building the executable/ ) {
134 print MAKEFILE_OUT <<MKF;
135 TOPDIR := ../../..
136 include ../../../Makefile.regression
137 export PATH+=:\$(TTCN3_DIR)/bin:
138 export LD_LIBRARY_PATH+=:\$(ABS_SRC):\$(TTCN3_DIR)/lib:
139 MKF
140 }
141 }
142 continue {
143 print MAKEFILE_OUT;
144 }
145
146 # Add the 'run' target and a rule to rebuild the Makefile
147
148 print MAKEFILE_OUT <<MMM;
149 run: \$(TARGET) $cfgfile
150 \t./\$^
151
152 Makefile: prj2mk.pl ../src/xmlTest.prj
153 \tmake -C .. bin/Makefile
154
155 MMM
156
157 close(MAKEFILE_OUT) or die "close output: $!";
158 close(MAKEFILE_IN) or die "close input: $!";
159 unlink('Makefile.1');
160
161 __END__
162
163 perl -nwle 'print $1 if /path="([^"]+)"/' xmlTest.prj | xargs ttcn3_makefilegen -gs -e XmlTest
This page took 0.05246 seconds and 4 git commands to generate.