~ubuntu-branches/ubuntu/trusty/pdl/trusty-proposed

« back to all changes in this revision

Viewing changes to .pc/build-pdl-wrapper-via-makefile.patch/pdl.PL

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2012-06-09 15:36:15 UTC
  • mfrom: (2.1.12 sid)
  • Revision ID: package-import@ubuntu.com-20120609153615-9btghuyapev3n722
Tags: 1:2.4.11-4ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - debian/perldl.conf: Enabled bad-val as NAN

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
if($^O =~ /mswin32/i) {exit}
 
2
open(FOO,">pdl.c");
 
3
print FOO <<'nosubs';
 
4
 
 
5
/******************************
 
6
 * pdl.c - perldl spawner
 
7
 * Works around a problem with many unices that you can't use an interpreter
 
8
 * to run an interpreter -- so "#!/usr/bin/perldl" won't work.
 
9
 * This is a compiled piece of code that launches perldl "directly", 
 
10
 * so that the poor kernel's mind isn't blown.
 
11
 *
 
12
 * If you feed in a single non-switch argument it gets prepended with a 
 
13
 * "-" to let perldl know that it's an input file.  That way you can be lazy
 
14
 * and say "#!/usr/bin/pdl" at the top of your script.
 
15
 * 
 
16
 * Don't modify this .c code -- modify the generator, pdl.PL, instead.
 
17
 *
 
18
 * CED 21-Jul-2004
 
19
 */
 
20
 
 
21
 
 
22
#include <unistd.h>
 
23
#include <stdlib.h>
 
24
#include <stdio.h>
 
25
#include <sys/types.h>
 
26
#include <sys/wait.h>
 
27
 
 
28
main(int argc, char **argv) {
 
29
  char perldl[BUFSIZ];
 
30
  int pipes[2];
 
31
  int pid,i;
 
32
  int status;
 
33
 
 
34
  if(pipe(pipes)) {perror; exit(1);}
 
35
  pid = fork();
 
36
  if(pid==0) {
 
37
    dup2(pipes[1],1);
 
38
    dup2(pipes[2],2);
 
39
    system("which perldl");
 
40
    exit(0);
 
41
  }
 
42
  read(pipes[0],perldl,BUFSIZ);
 
43
  pid = wait(&status);
 
44
  if(! WIFEXITED(status) ) {
 
45
    fprintf(stderr,"Hmmm... couldn't seem to find perldl anywhere. Quitting.\n");
 
46
    goto exit;
 
47
  }
 
48
 
 
49
  /* Remove trailing newline */
 
50
  for(i=0;i<BUFSIZ && perldl[i]; i++) 
 
51
    if(perldl[i]=='\n' || perldl[i]=='\r')
 
52
        perldl[i]='\0';
 
53
 
 
54
  if(argc==2) {
 
55
    if(argv[1][0]!='-') {
 
56
      char **argv2 = malloc((argc+2)*sizeof(char *));
 
57
      int i;
 
58
 
 
59
      if(!argv2) 
 
60
        goto exit;
 
61
 
 
62
      for(i=0;i<argc;i++)
 
63
        argv2[i+1]=argv[i];
 
64
 
 
65
      argv2[1]="-";
 
66
      argv2[0]="perldl";
 
67
      argv2[argc+1]=0;
 
68
 
 
69
      execv(perldl,argv2);
 
70
      fprintf(stderr,"couldn't execv %s\n",perldl);
 
71
      goto exit;
 
72
    }
 
73
  }
 
74
 
 
75
  argv[0]="perldl";
 
76
  execv(perldl,argv);
 
77
  fprintf(stderr,"couldn't execv %s (%d args)\n",perldl,argc);
 
78
  goto exit;
 
79
 
 
80
exit: 
 
81
  perror("pdl (perldl trampoline)");
 
82
  exit(-1);
 
83
}
 
84
nosubs
 
85
  ;
 
86
 
 
87
use Config;
 
88
my $dir = 'blib/bin';
 
89
#manually create directory. Older versions of EU::MM (at least as late
 
90
#as 6.17 which ships with perl 5.8.6) don't automatically create it.
 
91
mkdir $dir unless -e $dir && -d $dir;
 
92
`$Config{cc} -o $dir/pdl pdl.c`;
 
93
 
 
94
exit 0;