1# -*- cperl -*-
2use Config;
3use ExtUtils::MakeMaker;
4
5use Tk::MMtry qw(try_compile);
6use Tk::MMutil;
7use Tk::Config '!$VERSION';
8
9Tk::MMutil::TkExtMakefile(
10    'NAME'	=> 'Tk::pTk',
11    'VERSION'	=> $Tk::Config::VERSION,
12    'LINKTYPE'	=> 'static',
13    'OBJECT'	=> '$(O_FILES)',
14    macro	=> { WINARCH     => $win_arch },
15    'DEFINE'	=> $define,
16    'INC'	=> "$inc -I. -Ibitmaps -I/usr/local/include",
17    'SKIP'	=> [qw( distclean dist makeaperl xs_o)],
18    'clean'	=> {'FILES' => 'libpTk$(LIB_EXT)'}
19);
20
21sub MY::top_targets {
22 my ($self) = @_;
23 local $_ = $self->MM::top_targets;
24 s/^(\$\(O_FILES\)\s*:.*)$/# Explicit dependencies provided\n# $1/m;
25 return $_;
26}
27
28sub MY::xs_c {
29'
30# Rules for building .t table files from .h files
31.SUFFIXES: .t .h .m
32.h.t :
33	$(PERL) mkVFunc -t $(WINARCH) $<
34.h.m :
35	$(PERL) mkVFunc -m $(WINARCH) $<
36'
37}
38
39sub MY::post_initialize
40{
41 my ($self) = @_;
42 my %mTk;
43 my %exc;
44 my $dir;
45 my @list;
46 if ($Tk::MMutil::IsWin32)
47  {
48   @list = qw(win xlib additions generic tixWin tixGeneric tclWin tclGeneric);
49  }
50 elsif ($win_arch eq 'MSWin32' and $^O eq 'cygwin')
51  {
52   @list = qw(win xlib additions generic tixWin tixGeneric tclUnix tclGeneric);
53  }
54 elsif ($win_arch eq 'open32')
55  {
56   @list = qw(open32 open32/h win xlib additions generic tixWin tixGeneric tclUnix tclGeneric );
57  }
58 elsif ($win_arch eq 'pm')
59  {
60   @list = qw(os2 os2/unix open32 xlib additions generic tixWin tixGeneric tclUnix unix tclGeneric );
61  }
62 else
63  {
64   @list = qw(unix additions generic tixUnix tixGeneric tclUnix tclGeneric );
65  }
66 print STDERR "Generating Dependencies for $^O, win_arch=$win_arch\n";
67 foreach $dir (@list)
68  {
69   my $src = $self->catdir("mTk",$dir);
70   next unless -d $src;
71   if (open(EXC,$self->catfile($src,"pTk.inc")))
72    {
73     while (<EXC>)
74      {
75       chomp;
76       s/\s*#.*$//;
77       s/^\s+//;
78       next unless /\S/;
79       $mTk{$_} = $self->catfile($src,$_) unless (exists $mTk{$_});
80      }
81     close(EXC);
82    }
83   else
84    {
85     opendir(DIR,$src) || die "Cannot open $src:$!";
86     if (open(EXC,$self->catfile($src,"pTk.exc")))
87      {
88       while (<EXC>)
89        {
90         chomp;
91         s/\s*#.*$//;
92         s/^\s+//;
93         next unless /\S/;
94         $exc{$_} = 1;
95         if (-f $_)
96          {
97           chmod(0777,$_);
98           unlink($_);
99           warn "Loose $_\n";
100          }
101        }
102       close(EXC);
103      }
104     else
105      {
106       warn "Cannot open $src/pTk.exc:$!";
107      }
108     my $file;
109     while (defined($file = readdir(DIR)))
110      {
111       next if $exc{$file};
112       if ($file =~ /\.[ch]$/)
113        {
114         $mTk{$file} = $self->catfile($src,$file) unless (exists $mTk{$file});
115        }
116      }
117     closedir(DIR);
118    }
119  }
120 my @loose = ();
121 if (defined($Config{'i_stdlib'}) && try_compile("config/Hstrtoul.c"))
122  {
123   push(@loose,'strtoul.c');
124  }
125 if (defined($Config{'i_string'}) && try_compile("config/Hstrdup.c"))
126  {
127   push(@loose,'strdup.c');
128  }
129 if (try_compile("config/Hstrcasecmp.c"))
130  {
131   push(@loose,'strcasecmp.c');
132  }
133 $self->Tk::MMutil::mTk_CHO(\%mTk,\%exc,@loose);
134 my %files = ();
135 $files{'windows.h'} = 1 if $win_arch eq 'open32';
136 my $name;
137 $self->{'dir_targets'} = [];
138 $dir = $self->catdir('$(INST_ARCHLIBDIR)','pTk');
139 push(@{$self->{'dir_targets'}},$dir);
140 foreach $name ($self->lsdir("."))
141  {
142   next if ($name =~ /^\./);
143   next unless (-f $name);
144   $files{$name} = 1 if ($name =~ /\.[tm]$/);
145  }
146 foreach $name (sort(@{$self->{H}},keys %files))
147  {
148   $self->{PM}->{$name} = $self->catfile($dir,$name);
149  }
150 foreach $name (qw(Tcl-pTk mkVFunc))
151  {
152   $self->{PM}->{$name} = $self->catfile($dir,$name);
153  }
154
155 if ($Tk::MMutil::IsWin32 or $win_arch eq 'open32' or $win_arch eq 'pm' or
156     ($win_arch eq 'MSWin32' and $^O eq 'cygwin'))
157  {my $ddir = $self->catdir('$(INST_ARCHLIBDIR)','X11');
158   my $sdir = $self->catdir('mTk','xlib','X11');
159   push(@{$self->{'dir_targets'}},$ddir);
160   foreach $name ($self->lsdir($sdir))
161    {
162     next if $name =~ /^\.+$/;
163     my $src = $self->catfile($sdir,$name);
164     next unless -f $src;
165     $self->{PM}->{$src} = $self->catfile($ddir,$name);
166    }
167  }
168 $dir = $self->catdir($dir,"compat");
169 push(@{$self->{'dir_targets'}},$dir);
170 foreach $name ($self->lsdir("compat"))
171  {
172   next if $name =~ /^\.+$/;
173   my $src = $self->catfile('compat',$name);
174   next unless -f $src;
175   $self->{PM}->{$src} = $self->catfile($dir,$name);
176  }
177 '';
178}
179
180sub MY::test
181{
182 q[
183test ::
184	@echo 'No tests defined for $(NAME)'
185 ];
186}
187
188sub MY::post_constants
189{
190 '
191INST_STATIC=libpTk$(LIB_EXT)
192';
193};
194
195sub MY::install {
196'
197install :: all
198';
199}
200
201sub MY::dynamic_lib { my $self = shift; "dynamic_lib :: static_lib\n\t".$self->{'NOECHO'}."\$(NOOP)\n" }
202
203sub MY::dynamic     { my $self = shift; "dynamic :: static\n\t".$self->{'NOECHO'}."\$(NOOP)\n" }
204
205sub MY::static
206{
207  my $self = shift;
208  my $str  = $self->MM::static(@_);
209  if ($win_arch eq 'open32' or $win_arch eq 'pm')
210   {
211    $str .= '
212static :: dllInit$(LIB_EXT)
213dllInit$(LIB_EXT): dllMain$(OBJ_EXT)
214	$(AR) $(AR_STATIC_ARGS) $@ dllMain$(OBJ_EXT) && $(RANLIB) $@
215';
216   }
217 return $str;
218}
219
220sub MY::realclean {
221  my $self = shift;
222  my $str  = $self->MM::realclean(@_);
223  $str =~ s/(::\s*clean)/$1 mungeclean/;
224  $str .= "\nmungeclean ::\n";
225  $str .= "\t\$(RM_F) ".join(" \\\n\t",keys %{$self->{'MTK'}})."\n";
226  return $str;
227}
228
229
230sub MY::postamble {
231my $self = shift;
232my $dep = $self->Tk::MMutil::mTk_postamble;
233
234if (0 && $self->can('dir_target'))
235 {
236  $dep .= $self->dir_target(@{$self->{'dir_targets'}});
237
238  $dep .= "config :: " . join(" \\\n\t",map($self->catfile($_,".exists"),@{$self->{'dir_targets'}})) .
239          "\n\t".$self->{NOECHO}."\$(NOOP)\n";
240 }
241
242if ($Tk::MMutil::IsWin32 or ($win_arch eq 'MSWin32' and $^O eq 'cygwin'))
243 {
244  my $cc = $Config{'cc'};
245  my $file = 'tk.res';
246  if ($cc =~ /gcc/i)
247   {
248    $file = 'tkres$(OBJ_EXT)';
249    $dep .= "$file : mTk/win/rc/tk.rc\n\t";
250    $dep .= 'windres --use-temp-file -o $@ --include-dir . --include-dir mTk/win/rc mTk/win/rc/tk.rc';
251   }
252  elsif ($cc =~ /^bcc/i)
253   {
254    $dep .= "$file : mTk/win/rc/tk.rc\n\t";
255    $dep .= 'brc32 -fo $@ -r -i . -i mTk\win\rc mTk\win\rc\tk.rc';
256   }
257  else
258   {
259    $dep .= "$file : mTk/win/rc/tk.rc\n\t";
260    $dep .= 'rc -fo $@ -r -i . -i mTk\win\rc mTk\win\rc\tk.rc';
261   }
262  $dep .= "\nlibpTk\$(LIB_EXT) : $file\n";
263 }
264$dep . '
265Lang.t  Lang.m : Lang.h  Lang.exc  mkVFunc
266tk.t tk.m : tk.h    tk.exc    mkVFunc
267tkInt.t tkInt.m : tkInt.h tkInt.exc mkVFunc
268tkImgPhoto.t tkImgPhoto.m : tkImgPhoto.h tkImgPhoto.exc mkVFunc
269Xlib.t Xlib.m : Xlib.h  Xlib.excwin mkVFunc
270tix.t tix.m   : tix.h tix.exc mkVFunc
271tixInt.t tixInt.m : tixInt.h tixInt.exc mkVFunc
272tkDecls.t tkDecls.m : tkDecls.h tkDecls.exc mkVFunc
273tclDecls.t tclDecls.m : tclDecls.h tclDecls.exc mkVFunc
274tkIntDecls.t tkIntDecls.m : tkIntDecls.h tkIntDecls.exc mkVFunc
275
276config :: Xlib.t Lang.t tk.t tkInt.t tkImgPhoto.t tix.t tixInt.t \
277          tkDecls.t tkIntDecls.t tclDecls.t \
278          Xlib.m Lang.m tk.m tkInt.m tkImgPhoto.m tix.m tixInt.m \
279          tkDecls.m tkIntDecls.m tclDecls.m
280	'.$self->{NOECHO}.'$(NOOP)
281
282';
283}
284
285
286
287
288
289