b8e1ff7d9e6dc89dbccdf368d5a8b25f7aa6996a
[openssl.git] / util / pl / unix.pl
1 #!/usr/local/bin/perl
2 #
3 # unix.pl - the standard unix makefile stuff.
4 #
5
6 $o='/';
7 $cp='/bin/cp';
8 $rm='/bin/rm -f';
9
10 # C compiler stuff
11
12 if ($gcc)
13         {
14         $cc='gcc';
15         if ($debug)
16                 { $cflags="-g2 -ggdb"; }
17         else
18                 { $cflags="-O3 -fomit-frame-pointer"; }
19         }
20 else
21         {
22         $cc='cc';
23         if ($debug)
24                 { $cflags="-g"; }
25         else
26                 { $cflags="-O"; }
27         }
28 $obj='.o';
29 $ofile='-o ';
30
31 # EXE linking stuff
32 $link='${CC}';
33 $lflags='${CFLAG}';
34 $efile='-o ';
35 $exep='';
36 $ex_libs="";
37
38 # static library stuff
39 $mklib='ar r';
40 $mlflags='';
41 $ranlib=&which("ranlib") or $ranlib="true";
42 $plib='lib';
43 $libp=".a";
44 $shlibp=".a";
45 $lfile='';
46
47 $asm='as';
48 $afile='-o ';
49 $bn_asm_obj="";
50 $bn_asm_src="";
51 $des_enc_obj="";
52 $des_enc_src="";
53 $bf_enc_obj="";
54 $bf_enc_src="";
55
56 %perl1 = (
57           'md5-x86_64' => 'crypto/md5',
58           'x86_64-mont' => 'crypto/bn',
59           'x86_64-mont5' => 'crypto/bn',
60           'x86_64-gf2m' => 'crypto/bn',
61           'modexp512-x86_64' => 'crypto/bn',
62           'aes-x86_64' => 'crypto/aes',
63           'vpaes-x86_64' => 'crypto/aes',
64           'bsaes-x86_64' => 'crypto/aes',
65           'aesni-x86_64' => 'crypto/aes',
66           'aesni-sha1-x86_64' => 'crypto/aes',
67           'sha1-x86_64' => 'crypto/sha',
68           'e_padlock-x86_64' => 'engines',
69           'rc4-x86_64' => 'crypto/rc4',
70           'rc4-md5-x86_64' => 'crypto/rc4',
71           'ghash-x86_64' => 'crypto/modes',
72          );
73
74 # If I were feeling more clever, these could probably be extracted
75 # from makefiles.
76 sub platform_perlasm_compile_target
77         {
78         local($target, $source, $bname) = @_;
79
80         for $p (keys %perl1)
81                 {
82                 if ($target eq "\$(OBJ_D)/$p.o")
83                         {
84                         return << "EOF";
85 \$(TMP_D)/$p.s: $perl1{$p}/asm/$p.pl
86         \$(PERL) $perl1{$p}/asm/$p.pl \$(PERLASM_SCHEME) > \$@
87 EOF
88                         }
89                 }
90         if ($target eq '$(OBJ_D)/x86_64cpuid.o')
91                 {
92                 return << 'EOF';
93 $(TMP_D)/x86_64cpuid.s: crypto/x86_64cpuid.pl
94         $(PERL) crypto/x86_64cpuid.pl $(PERLASM_SCHEME) > $@
95 EOF
96                 }
97         elsif ($target eq '$(OBJ_D)/sha256-x86_64.o')
98                 {
99                 return << 'EOF';
100 $(TMP_D)/sha256-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
101         $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
102 EOF
103                 }
104         elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
105                 {
106                 return << 'EOF';
107 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
108         $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
109 EOF
110                 }
111         elsif ($target eq '$(OBJ_D)/sha512-x86_64.o')
112                 {
113                 return << 'EOF';
114 $(TMP_D)/sha512-x86_64.s: crypto/sha/asm/sha512-x86_64.pl
115         $(PERL) crypto/sha/asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@
116 EOF
117                 }
118
119         die $target;
120         }
121
122 sub special_compile_target
123         {
124         local($target) = @_;
125
126         if ($target eq 'crypto/bn/x86_64-gcc')
127                 {
128                 return << "EOF";
129 \$(TMP_D)/x86_64-gcc.o: crypto/bn/asm/x86_64-gcc.c
130         \$(CC) \$(CFLAGS) -c -o \$@ crypto/bn/asm/x86_64-gcc.c
131 EOF
132                 }
133         return undef;
134         }
135
136 sub do_lib_rule
137         {
138         local($obj,$target,$name,$shlib)=@_;
139         local($ret,$_,$Name);
140
141         $target =~ s/\//$o/g if $o ne '/';
142         $target="$target";
143         ($Name=$name) =~ tr/a-z/A-Z/;
144
145         $ret.="$target: \$(${Name}OBJ)\n";
146         $ret.="\t\$(RM) $target\n";
147         $ret.="\t\$(MKLIB) $target \$(${Name}OBJ)\n";
148         $ret.="\t\$(RANLIB) $target\n\n";
149         }
150
151 sub do_link_rule
152         {
153         local($target,$files,$dep_libs,$libs)=@_;
154         local($ret,$_);
155         
156         $file =~ s/\//$o/g if $o ne '/';
157         $n=&bname($target);
158         $ret.="$target: $files $dep_libs\n";
159         $ret.="\t\$(LINK) ${efile}$target \$(LFLAGS) $files $libs\n\n";
160         return($ret);
161         }
162
163 sub which
164         {
165         my ($name)=@_;
166         my $path;
167         foreach $path (split /:/, $ENV{PATH})
168                 {
169                 if (-x "$path/$name")
170                         {
171                         return "$path/$name";
172                         }
173                 }
174         }
175
176 1;