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