comparison src/build-msvctools/Makefile @ 3061:f8299bb6c872

Initial support for native MSVC compilation. * add MSVC support files: compiler wrappers and support libraries * adapt libiconv to work with MSVC * adapt gettext to work with MSVC
author Michael Goffioul <michael.goffioul@gmail.com>
date Mon, 17 Jun 2013 22:43:11 -0400
parents
children b39e8dc859f7
comparison
equal deleted inserted replaced
3060:cbdf4575016d 3061:f8299bb6c872
1 TARGETS = \
2 ar-msvc \
3 cc-msvc.exe \
4 clgcc.exe \
5 clg++.exe \
6 dirent.h \
7 dirent.lib \
8 getopt.h \
9 getopt.lib \
10 inttypes.h \
11 lt-postproc \
12 ranlib-msvc \
13 stdbool.h \
14 unistd.h \
15 compat/mingwcompat.lib \
16 math/msvcmath.lib \
17 gfortran-msvc.exe \
18 gfortran-msvc.lib \
19 gfortran-msvc-static.lib
20
21 MSVCSTDINT := $(shell echo '\#include <stdint.h>' > t.c; cl -nologo -showIncludes -c t.c | $(SED) -n -e 's/^Note: including file: \(.*stdint\.h\)$$/\1/p'; rm -f t.c t.obj)
22 ifeq ($(MSVCSTDINT),)
23 TARGETS += stdint.h
24 endif
25
26 .PHONY: all
27 all: $(TARGETS)
28
29 cc-msvc.exe: cc-msvc.cc
30 cl -nologo -O2 -EHsc cc-msvc.cc
31
32 clgcc.exe clg++.exe: cc-msvc.exe
33 cp -a $< $@
34
35 fixlibtool2: fixlibtool2.in
36 $(SED) \
37 -e "s/@LIBRARY_PREFIX@/$(LIBRARY_PREFIX)/" \
38 -e "s/@LIBRARY_SUFFIX@/$(LIBRARY_SUFFIX)/" $< > $@
39
40 stdint.h inttypes.h:
41 $(WGET) http://msinttypes.googlecode.com/svn/trunk/$@
42
43 dirent.h:
44 $(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/include/dirent.h?format=raw'
45 $(SED) -i -e 's/FILENAME_MAX/260/g' \
46 -e 's/__MINGW_NOTHROW//g' \
47 -e 's,^.*_mingw\.h.*$$,/*&*/,' \
48 -e 's/_A_VOLID/0x00/g' \
49 $@
50
51 dirent.c:
52 $(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/src/libcrt/tchar/dirent.c?format=raw'
53
54 dirent.obj: dirent.c dirent.h
55 cl -nologo -O2 -MD -I. \
56 -DFILENAME_MAX=260 \
57 -Dinline=__inline \
58 -D_TDIR=DIR \
59 -D_tdirent=dirent \
60 -D_topendir=opendir \
61 -D_tclosedir=closedir \
62 -D_treaddir=readdir \
63 -D_trewinddir=rewinddir \
64 -D_tseekdir=seekdir \
65 -D_ttelldir=telldir \
66 -c dirent.c -Fo$@
67
68 wdirent.obj: dirent.c dirent.h
69 cl -nologo -O2 -MD -I. \
70 -D_UNICODE \
71 -DFILENAME_MAX=260 \
72 -Dinline=__inline \
73 -D_osver=GetVersion\(\) \
74 -D_TDIR=_WDIR \
75 -D_tdirent=_wdirent \
76 -D_topendir=_wopendir \
77 -D_tclosedir=_wclosedir \
78 -D_treaddir=_wreaddir \
79 -D_trewinddir=_wrewinddir \
80 -D_tseekdir=_wseekdir \
81 -D_ttelldir=_wtelldir \
82 -c dirent.c -Fo$@
83
84 dirent.lib: dirent.obj wdirent.obj
85 lib -out:$@ $^
86
87 getopt.h:
88 $(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/include/getopt.h?format=raw'
89 $(SED) -i -e 's/__MINGW_NOTHROW//g' \
90 -e 's,^.*_mingw\.h.*$$,/*&*/,' \
91 getopt.h
92
93 getopt.c: getopt.diff
94 $(WGET) -O $@ 'http://sourceforge.net/p/mingw/mingw-org-wsl/ci/master/tree/src/libcrt/misc/getopt.c?format=raw'
95 $(PATCH) -p0 < getopt.diff
96
97 getopt.obj: getopt.c getopt.h
98 cl -nologo -O2 -MD -I. -c $< -Fo$@
99
100 getopt.lib: getopt.obj
101 lib -out:$@ $^
102
103 compat/mingwcompat.lib:
104 $(MAKE) -C compat
105
106 math/msvcmath.lib:
107 $(MAKE) -C math SED='$(SED)'
108
109 math/msvcmath.h: math/msvcmath.lib
110
111 gfortran-msvc.exe: gfortran-msvc.cc
112 cl -nologo -O2 -EHsc gfortran-msvc.cc
113
114 gfortran-msvc-gcc-patch.stamp:
115 (cd ../gcc-$(GCCVERSION)/ && patch -p1) < gcc.diff
116 (cd ../gcc-$(GCCVERSION)/ && \
117 cp libgcc/config/i386/gthr-win32.h libgcc/gthr-default.h)
118 touch $@
119
120 gfortran-msvc-build:
121 mkdir $@
122
123 gfortran-msvc-build/.libs/libgfortran.a: gfortran-msvc-gcc-patch.stamp gfortran-msvc-build
124 cd gfortran-msvc-build && \
125 ../../gcc-$(GCCVERSION)/libgfortran/configure \
126 --disable-libquadmath-support \
127 --disable-shared \
128 --enable-static \
129 --disable-multilib \
130 CFLAGS="-O2 -mstackrealign -mincoming-stack-boundary=2" \
131 FCFLAGS="-O3 -ff2c -mstackrealign -mincoming-stack-boundary=2"
132 $(MAKE) -C gfortran-msvc-build
133
134 gfortran.lst: gfortran-msvc-build/.libs/libgfortran.a
135 ar x $<
136 ar t $< > $@
137
138 gfortran.def: gfortran.lst
139 (echo 'EXPORTS'; nm -C @$< | grep ' T _gfortran_' | cut -d' ' -f3) > $@
140
141 libgfortran-dllinit.o: libgfortran-dllinit.c cc-msvc.exe
142 cc-msvc -O2 -c $< -o $@
143
144 libgfortran-msvcinit.o: libgfortran-msvcinit.c cc-msvc.exe
145 cc-msvc -O2 -c $< -o $@
146
147 gfortran-msvc.lib: gfortran-msvc-build/.libs/libgfortran.a gfortran.def gfortran.lst \
148 compat/mingwcompat.lib cc-msvc.exe libgfortran-dllinit.o
149 cc-msvc -shared -o $(LIBRARY_PREFIX)gfortran-msvc$(LIBRARY_SUFFIX).dll \
150 libgfortran-dllinit.o @gfortran.lst -Wl,-def:gfortran.def -Wl,-implib:gfortran-msvc.lib \
151 -Lcompat -Lmath -lmingwcompat -ladvapi32
152
153 gfortran-msvc-static.lib: gfortran-msvc-build/.libs/libgfortran.a gfortran.lst libgfortran-msvcinit.o
154 lib -out:$@ libgfortran-msvcinit.o @gfortran.lst
155
156 .PHONY: install
157 install: all
158 $(INSTALL) -d $(DESTDIR)/bin
159 $(INSTALL) ar-msvc $(DESTDIR)/bin/
160 $(INSTALL) cc-msvc.exe $(DESTDIR)/bin/
161 $(INSTALL) clgcc.exe $(DESTDIR)/bin/
162 $(INSTALL) clg++.exe $(DESTDIR)/bin/
163 $(INSTALL) lt-postproc $(DESTDIR)/bin/
164 $(INSTALL) gfortran-msvc.exe $(DESTDIR)/bin/
165 $(INSTALL) ranlib-msvc $(DESTDIR)/bin/
166 $(INSTALL) $(LIBRARY_PREFIX)gfortran-msvc$(LIBRARY_SUFFIX).dll $(DESTDIR)/bin/
167 $(INSTALL) -d $(DESTDIR)/include
168 test -n "$(MSVCSTDINT)" || $(INSTALL) stdint.h $(DESTDIR)/include
169 $(INSTALL) inttypes.h $(DESTDIR)/include
170 $(INSTALL) unistd.h $(DESTDIR)/include
171 $(INSTALL) stdbool.h $(DESTDIR)/include
172 $(INSTALL) dirent.h $(DESTDIR)/include
173 $(INSTALL) getopt.h $(DESTDIR)/include
174 $(INSTALL) math/msvcmath.h $(DESTDIR)/include/math.h
175 $(INSTALL) -d $(DESTDIR)/lib
176 $(INSTALL) dirent.lib $(DESTDIR)/lib
177 $(INSTALL) getopt.lib $(DESTDIR)/lib
178 $(INSTALL) compat/mingwcompat.lib $(DESTDIR)/lib
179 $(INSTALL) math/msvcmath.lib $(DESTDIR)/lib
180 $(INSTALL) gfortran-msvc.lib $(DESTDIR)/lib
181 $(INSTALL) gfortran-msvc-static.lib $(DESTDIR)/lib