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