Further enhance assembler support on Cygwin and DJGPP.
[openssl.git] / crypto / perlasm / x86asm.pl
1 #!/usr/local/bin/perl
2
3 # require 'x86asm.pl';
4 # &asm_init("cpp","des-586.pl");
5 # XXX
6 # XXX
7 # main'asm_finish
8
9 sub main'asm_finish
10         {
11         &file_end();
12         &asm_finish_cpp() if $cpp;
13         print &asm_get_output();
14         }
15
16 sub main'asm_init
17         {
18         ($type,$fn,$i386)=@_;
19         $filename=$fn;
20
21         $cpp=$sol=$aout=$win32=$gaswin=0;
22         if (    ($type eq "elf"))
23                 { require "x86unix.pl"; }
24         elsif ( ($type eq "a.out"))
25                 { $aout=1; require "x86unix.pl"; }
26         elsif ( ($type eq "gaswin"))
27                 { $gaswin=1; $aout=1; require "x86unix.pl"; }
28         elsif ( ($type eq "sol"))
29                 { $sol=1; require "x86unix.pl"; }
30         elsif ( ($type eq "cpp"))
31                 { $cpp=1; require "x86unix.pl"; }
32         elsif ( ($type eq "win32"))
33                 { $win32=1; require "x86ms.pl"; }
34         elsif ( ($type eq "win32n"))
35                 { $win32=1; require "x86nasm.pl"; }
36         else
37                 {
38                 print STDERR <<"EOF";
39 Pick one target type from
40         elf     - linux, FreeBSD etc
41         a.out   - old linux
42         sol     - x86 solaris
43         cpp     - format so x86unix.cpp can be used
44         win32   - Windows 95/Windows NT
45         win32n  - Windows 95/Windows NT NASM format
46 EOF
47                 exit(1);
48                 }
49
50         &asm_init_output();
51
52 &comment("Don't even think of reading this code");
53 &comment("It was automatically generated by $filename");
54 &comment("Which is a perl program used to generate the x86 assember for");
55 &comment("any of elf, a.out, BSDI, Win32, gaswin (for GNU as on Win32) or Solaris");
56 &comment("eric <eay\@cryptsoft.com>");
57 &comment("");
58
59         $filename =~ s/\.pl$//;
60         &file($filename);
61         }
62
63 sub asm_finish_cpp
64         {
65         return unless $cpp;
66
67         local($tmp,$i);
68         foreach $i (&get_labels())
69                 {
70                 $tmp.="#define $i _$i\n";
71                 }
72         print <<"EOF";
73 /* Run the C pre-processor over this file with one of the following defined
74  * ELF - elf object files,
75  * OUT - a.out object files,
76  * BSDI - BSDI style a.out object files
77  * SOL - Solaris style elf
78  */
79
80 #define TYPE(a,b)       .type   a,b
81 #define SIZE(a,b)       .size   a,b
82
83 #if defined(OUT) || (defined(BSDI) && !defined(ELF))
84 $tmp
85 #endif
86
87 #ifdef OUT
88 #define OK      1
89 #define ALIGN   4
90 #if defined(__CYGWIN__) || defined(__DJGPP__)
91 #undef SIZE
92 #undef TYPE
93 #define SIZE(a,b)
94 #define TYPE(a,b)
95 #endif /* __CYGWIN || __DJGPP */
96 #endif
97
98 #if defined(BSDI) && !defined(ELF)
99 #define OK              1
100 #define ALIGN           4
101 #undef SIZE
102 #undef TYPE
103 #define SIZE(a,b)
104 #define TYPE(a,b)
105 #endif
106
107 #if defined(ELF) || defined(SOL)
108 #define OK              1
109 #define ALIGN           16
110 #endif
111
112 #ifndef OK
113 You need to define one of
114 ELF - elf systems - linux-elf, NetBSD and DG-UX
115 OUT - a.out systems - linux-a.out and FreeBSD
116 SOL - solaris systems, which are elf with strange comment lines
117 BSDI - a.out with a very primative version of as.
118 #endif
119
120 /* Let the Assembler begin :-) */
121 EOF
122         }
123
124 1;