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