OSDN Git Service

Implement wrappers for emulation of POSIX dlfcn API.
[mingw/mingw-org-wsl.git] / mingwrt / Makefile.in
1 # @configure_input@
2 # $Id$
3 #
4 # Makefile template for MinGW.org Runtime Library Package
5
6 PACKAGE_TARNAME := @PACKAGE_TARNAME@
7 PACKAGE_VERSION := @PACKAGE_VERSION@
8
9 # Written by Keith Marshall <keithmarshall@users.sourceforge.net>
10 # Copyright (C) 2014, MinGW.org Project
11 #
12 #
13 # Permission is hereby granted, free of charge, to any person obtaining a
14 # copy of this software and associated documentation files (the "Software"),
15 # to deal in the Software without restriction, including without limitation
16 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
17 # and/or sell copies of the Software, and to permit persons to whom the
18 # Software is furnished to do so, subject to the following conditions:
19
20 # The above copyright notice and this permission notice (including the next
21 # paragraph) shall be included in all copies or substantial portions of the
22 # Software.
23
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
26 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
27 # AUTHORS OR THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
28 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
29 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
30 # DEALINGS IN THE SOFTWARE.
31
32
33 # The default target is "all"; declare it early, to avoid any possible
34 # inadvertent override from any included file.
35 #
36 all:
37 PACKAGE_RELEASE := 
38 PACKAGE_RELEASE_TAG := $(PACKAGE_VERSION)$(PACKAGE_RELEASE:%=-%)-mingw32
39 NTDDI_VERSION_SPEC := -D NTDDI_VERSION=0x04000000
40
41 # Build paths and macros.
42 #
43 srcdir = @srcdir@
44 top_srcdir = @top_srcdir@
45 mingwrt_srcdir = @srcdir@
46 w32api_srcdir = @w32api_srcdir@
47 abs_builddir = @abs_builddir@
48
49 CC = @CC@
50 CFLAGS = @CFLAGS@
51 CPPFLAGS = @CPPFLAGS@
52
53 OBJEXT = @OBJEXT@
54
55 AR = @AR@
56 ARFLAGS = @ARFLAGS@
57 RANLIB = @RANLIB@
58
59 AS = @AS@
60 COMPILE.sx = @COMPILE_SX@
61 DLLTOOL = @DLLTOOL@
62 STRIP = @STRIP@
63 NM = @NM@
64
65 all: @DEFAULT_MAKECMDGOALS@
66 all-mingwrt-stage-1: all-mingwrt-objects all-mingwrt-libs
67 all-mingwrt-stage-1-and-2: all-mingwrt-stage-1 all-mingwrt-dll
68 all-mingwrt: all-mingwrt-stage-1-and-2
69
70 include_deprecated = @include_deprecated@
71 active_goals = $1-$2 $(if $(include_deprecated),$1-deprecated-$2)
72
73 all-stage-1: $(call active_goals,all,mingwrt-stage-1)
74 all-stage-1-and-2: $(call active_goals,all,mingwrt)
75
76 # Installation paths and macros.
77 #
78 prefix = @prefix@
79 exec_prefix = @exec_prefix@
80 bindir = ${DESTDIR}@bindir@
81
82 datarootdir = @datarootdir@
83 docdir = ${DESTDIR}${datarootdir}/doc
84 includedir = ${DESTDIR}@includedir@
85 libdir = ${DESTDIR}@libdir@
86
87 htmldir = @htmldir@
88 pdfdir = @pdfdir@
89
90 mandir = ${DESTDIR}@mandir@
91 man3dir = ${mandir}/man$(man3ext)
92
93 man3ext = 3
94
95 INSTALL = @INSTALL@
96 INSTALL_DATA = @INSTALL_DATA@
97
98 mkinstalldirs = @MKDIR_P@
99
100 # Keep the configuration in a consistent state.  Note that we assume
101 # that configure has been run initially, (otherwise we wouldn't have 
102 # a Makefile to begin with); since this also creates config.status,
103 # we may normally assume that it is already available ...
104 #
105 vpath configure ${top_srcdir}
106 config.status: configure
107         $(SHELL) config.status --recheck
108
109 # ... in which case, updating Makefile should be a simple matter of
110 # running config.status ...
111 #
112 vpath Makefile.in ${top_srcdir}
113 requires_existing = $(if $(wildcard $1),$1,$1.missing)
114 Makefile: Makefile.in configure $(call requires_existing,config.status)
115         $(SHELL) config.status
116         $(RM) Makefile.stub
117
118 .PHONY: config.status.missing
119 # ... but, in the event that this may be missing, (e.g. because it
120 # has been manually removed, or removed by "make distclean"), suggest
121 # running configure, and bail out.
122 #
123 config.status.missing:
124         $(warning *** cannot execute config.status)
125         $(error please run ${top_srcdir}/configure to regenerate it.)
126
127 # If configure itself needs to be updated, we must run autoconf in the
128 # top level source directory.
129 #
130 vpath %.m4 ${top_srcdir}
131 vpath configure.ac ${top_srcdir}
132 configure: configure.ac aclocal.m4
133         cd ${top_srcdir}; autoconf
134
135 # Capture dependencies conveyed within source files, ensuring that
136 # header files are taken from our working source tree, and not from
137 # the build-time compiler's installation path.
138 #
139 sinclude *.d
140 DEPFLAGS = -MMD -MP
141 INCLUDES = -nostdinc -I . -I ${top_srcdir}/include -I ${w32api_srcdir}/include \
142   -I ${top_srcdir} -I ${top_srcdir}/profile -iwithprefixbefore include
143
144 ALL_CFLAGS = $(CFLAGS) $(DEPFLAGS) $(INCLUDES) $(NTDDI_VERSION_SPEC)
145
146 # The general case, for compiling object files from C source,
147 # requires a small adjustment to the default implicit rule.
148 #
149 %.$(OBJEXT): %.c
150         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
151
152 # In some cases, both ANSI and UTF-16LE enabled variants of object
153 # modules are compiled from a common source; the UTF-16LE variant is
154 # to be identified by prefixing a "w" to the object file name.
155 #
156 w%.$(OBJEXT): %.c
157         $(CC) -c -D UNICODE $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
158
159 # Compiling object files from *.sx sources: since GCC-4.3, these
160 # have been supported as a case agnostic alternative to *.S sources,
161 # for assembly language sources requiring initial interpretation by
162 # the C preprocessor; owing to the case-insensitive nature of file
163 # naming on MS-Windows, we should prefer these, but we must tell
164 # make how to compile them.
165 #
166 %.$(OBJEXT): %.sx
167         $(COMPILE.sx) $($*_cflags) -o $@ $<
168
169 # Several components of the distributable object code base are to
170 # be provided as free-standing object modules, (rather than being
171 # encapsulated within object libraries); we classify these within
172 # two distinct groups, for support of the current MSVCRT.DLL build
173 # case and the older CRTDLL build case, (noting that, ultimately,
174 # we may wish to deprecate this latter case).
175 #
176 all-mingwrt-objects: $(call active_goals,all,crt-objects)
177 all-deprecated-mingwrt-objects: all-deprecated-crt-objects
178
179 # Further note that, in addition to specifying the build time
180 # inventories for each of these object module categories, each
181 # module should be allocated to an associated installation group,
182 # whence it may be included in the eventual distribution, via a
183 # staged installation.
184 #
185 all-crt-objects install-crt-objects: $(addsuffix .$(OBJEXT), crt2 crtmt \
186   crtst dllcrt2 gcrt2 CRT_fp8 CRT_fp10 CRT_noglob binmode txtmode)
187
188 all-deprecated-crt-objects install-deprecated-crt-objects: \
189   $(addsuffix .$(OBJEXT), crt1 dllcrt1 gcrt1)
190
191 # The crt1.$(OBJEXT) and crt2.$(OBJEXT) modules, for the (deprecated)
192 # CRTDLL and the (current) MSVCRT build cases respectively, are built
193 # from a common crt1.c source.  Similarly, the dllcrt1.$(OBJEXT) and
194 # dllcrt2.$(OBJEXT) modules share the common dllcrt1.c source.
195 #
196 # Noting that the source files are named for the deprecated build
197 # case, but that we need to specify this while compiling, we need
198 # this explicit pattern rule...
199 #
200 vpath %.c ${mingwrt_srcdir}
201 $(addsuffix .$(OBJEXT), crt1 dllcrt1): %.$(OBJEXT): %.c
202         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -D__CRTDLL__ -o $@ $<
203
204 # ...while, for the current build case, we need an explicit mapping
205 # to identify the disparately named source file.
206 #
207 $(addsuffix .$(OBJEXT), crt2 dllcrt2): %2.$(OBJEXT): %1.c
208         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
209
210 # The initialization hook for profiling code is inherited from Cygwin,
211 # where it is built as gcrt0.$(OBJEXT); we build it, unmodified, as each
212 # of gcrt1.$(OBJEXT) and gcrt2.$(OBJEXT), to satisfy the differing GCC
213 # specs file dependencies for each of the (deprecated) CRTDLL build
214 # and (current) MSVCRT build cases, respectively.
215 #
216 vpath %.c ${mingwrt_srcdir}/profile
217 $(addsuffix .$(OBJEXT), gcrt0 gcrt1 gcrt2): %.$(OBJEXT): gcrt0.c
218         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
219
220 # The primary runtime library is furnished by Microsoft, in the form
221 # of MSVCRT.DLL, as shipped with MS-Windows itself, or in any one of
222 # its versioned variants, as shipped with the MSVC compiler suite.
223 #
224 # We furnish the API for this runtime library, in the form of import
225 # libraries, for both release and debug DLL variants; furthermore,
226 # although we favour the freely available MSVCRT.DLL distributions,
227 # we also provide import libraries tailored to the non-free, and
228 # non-redistributable, MSVCRnn.DLL variants, corresponding to each
229 # of the following enumerated versions from the MSVC suite.
230 #
231 msvcrt_versions := 70 71 80 90 100
232 msvcrt_version_script = echo $1 | awk '\
233   { printf "0x%03d0", gensub( "^[^1-9]*([0-9]*).*", "\\\\1", 1 ) \
234   }'
235
236 extra_objects_filter = $(filter %.$(OBJEXT),$1)
237 extra_objects_script = test -z "$(call extra_objects_filter,$2)" \
238   || { echo $(AR) $(ARFLAGS) $1 $(call extra_objects_filter,$2); \
239        $(AR) $(ARFLAGS) $1 $(call extra_objects_filter,$2); \
240      }
241
242 msvcrt_dllname_script = echo $1 | awk '\
243   /^c/{ print "crtdll.dll" } \
244   /^m/{ ext = gsub( "^.*d$$", "&" ) ? "d.dll" : ".dll"; \
245         printf "msvcr%s%s", gsub( "^[^1-9]*[0-9]+.*", "&" ) \
246           ? gensub( "^[^1-9]*([0-9]+).*", "\\\\1", 1 ) \
247           : "t", ext; \
248       }'
249
250 # We categorize our import libraries into "standard" (a.k.a. "release")
251 # versions, augmented by corresponding "debug" variants.
252 #
253 std_msvcrt := $(addprefix msvcr,t $(msvcrt_versions))
254 all_msvcrt := $(std_msvcrt) $(addsuffix d,$(std_msvcrt))
255
256 all-mingwrt-libs: $(call active_goals,all,libmsvcrt)
257 all-libmsvcrt install-mingwrt-libs: $(foreach name,$(all_msvcrt),lib$(name).a)
258 all-libcrtdll install-deprecated-mingwrt-libs: libcrtdll.a libcoldname.a
259 all-deprecated-mingwrt all-deprecated-libmsvcrt: all-libcrtdll
260
261 # FIXME: We should aim to remove this interim work-around...
262 #
263 # MSVCRT.DLL, MSVCR70.DLL, and MSVCR71.DLL, (both regular and debug
264 # variants), lack the _get_output_format() function, which is required
265 # by the printf() module in libmingwex.a; add our own implementation.
266 # (Note that we also apply this for CRTDLL.DLL, via libcrtdll.a)
267 #
268 vpath ofmt_stub.s ${mingwrt_srcdir}
269 $(foreach ver,t 70 71,libmsvcr$(ver).a) libcrtdll.a \
270 $(foreach ver,t 70 71,libmsvcr$(ver)d.a): ofmt_stub.$(OBJEXT)
271 #
272 # End of work-around
273
274 # For each import library to be built, we derive a tailored exports
275 # definition file, from a common source.
276 #
277 .SUFFIXES: .def.in .def
278 $(addsuffix .def,$(all_msvcrt)): %.def: ${mingwrt_srcdir}/msvcrt.def.in
279         $(CC) -C -E -P -D__FILENAME__=$@ -D__$*__=1 \
280           -D__MSVCRT_VERSION__=`$(call msvcrt_version_script,$*)` \
281           -xc-header $< > $@
282
283 # To accommodate the __USE_MINGW_ANSI_STDIO feature, as specified
284 # in _mingw.h and stdio.h, while retaining a mechanism for accessing
285 # the MSVCRT.DLL functions which it replaces, we augment our import 
286 # libraries with extra, alternatively named entry points, each of
287 # which implements a vectored jump to the regular entry point for
288 # the DLL implementation of its corresponding replaced function.
289 #
290 msvcrt_repl_prefix = __msvcrt
291 msvcrt_repl_funcs = printf fprintf sprintf vprintf vfprintf vsprintf
292
293 # This is kludgey, but dlltool lacks the selectivity to do the job
294 # well; (its --ext-prefix-alias option, which is what we would like
295 # to use, is rather like a chainsaw in the hands of a neurosurgeon,
296 # when he should have a scalpel).  We cannot selectively apply the
297 # prefix, to just the symbols of interest, so we end up by creating
298 # an initial copy of the import library, WITH the prefix applied to
299 # to EVERYTHING, (noting that, when we create this initial copy, we
300 # MUST specify the "--no-delete" option TWICE, to preserve temporary
301 # object files within the build tree); we then set this initial copy
302 # aside, and create a further copy WITHOUT the extra symbols, while
303 # duplicating the temporary object file name prefix retrieved from
304 # the initial copy, using this $(NM) lookup filter...
305 #
306 dlltool_temp_prefix = $(NM) $(1) | sed -n -e '/t.o:$$/{s///p;q' -e '}'
307
308 # ...after which, we apply the following $(NM) lookup filter to the
309 # initial copy of the import library file, to identify the specific
310 # temporary object files, defining the entry points to remap...
311 #
312 msvcrt_repl = $(call nmlookup,$1,$(msvcrt_repl_prefix)_,$(msvcrt_repl_funcs))
313 nmlookup = $(NM) $(1) | sed -n \
314   -e '/:$$/h;/^[0-7][0-7]*  *T  */{s///;H;g;s/\n//' \
315   $(foreach repl,$(3),-e 's/:_$(2)$(repl)$$//p') \
316   -e '}'
317
318 # ...and we add just that selection to the final copy of the import
319 # library, before explicitly deleting ALL temporary object files, and
320 # the (extended) initial copy of the import library.
321 #
322 vpath %.def ${mingwrt_srcdir}
323 $(foreach name,$(all_msvcrt) crtdll,lib$(name).a): lib%.a: %.def
324         $(DLLTOOL) --as $(AS) -k --input-def $< --no-delete --no-delete \
325           --dllname `$(call msvcrt_dllname_script,$*)` --output-lib $@  \
326           --ext-prefix-alias $(msvcrt_repl_prefix) && mv $@ lib$*-repl.a
327         $(DLLTOOL) --as $(AS) -k --input-def $< --output-lib $@ \
328           --temp-prefix `$(call dlltool_temp_prefix,lib$*-repl.a)` \
329           --dllname `$(DLLTOOL) --identify lib$*-repl.a`
330         $(AR) $(ARFLAGS) $@ `$(call msvcrt_repl,lib$*-repl.a)` \
331           $(filter %.$(OBJEXT),$^)
332         $(RM) lib$*-repl.a `$(call dlltool_temp_prefix,$@)`*
333
334 # Older versions of Microsoft's runtime libraries used a naming
335 # convention which is more consistent with POSIX, (and with other
336 # free software usage), than they currently employ; we support
337 # this earlier convention by mapping the old names to equivalent
338 # entry points in the current libraries, using libcoldname.a to
339 # map CRTDLL.DLL entries, and variants of libmoldname.a for each
340 # variant of MSVCRT.DLL
341 #
342 std_moldname := moldname $(addprefix moldname,$(msvcrt_versions))
343 all_moldname := $(std_moldname) $(addsuffix d,$(std_moldname))
344
345 all-mingwrt-libs: all-libmoldname
346 all-libmoldname install-mingwrt-libs: $(foreach name,$(all_moldname),lib$(name).a)
347 $(foreach name,coldname $(all_moldname),lib$(name).a): lib%.a: %.def
348         $(DLLTOOL) --as $(AS) -k -U --input-def $< --output-lib $@ \
349           --dllname `$(call msvcrt_dllname_script,$*)`
350         $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
351
352 # The oldname libraries are also a convenient place to provide a
353 # few additional functions, with no direct implementation in the
354 # Microsoft DLLs, but which nevertheless are easily emulated.
355 #
356 $(foreach name,coldname $(all_moldname),lib$(name).a): $(addsuffix .$(OBJEXT), \
357   isascii iscsym iscsymf strcasecmp strncasecmp toascii wcscmpi)
358
359 coldname.def: %.def: ${mingwrt_srcdir}/moldname.def.in
360         $(CC) -C -E -P -D__FILENAME__=$@ -D__CRTDLL__ -xc-header $< > $@
361
362 $(addsuffix .def,$(all_moldname)): %.def: ${mingwrt_srcdir}/moldname.def.in
363         $(CC) -C -E -P -D__FILENAME__=$@ -xc-header $< > $@
364
365 all-mingwrt-libs install-mingwrt-libs: libmingw32.a libmingwex.a
366 libmingw32.a: $(addsuffix .$(OBJEXT), CRTinit CRTglob setargv \
367   CRTfmode cpu_features CRT_fp10 txtmode main dllmain gccmain crtst \
368   tlsmcrt tlsmthread tlssup tlsthrd pseudo-reloc pseudo-reloc-list)
369
370 libmingw32.a libmingwex.a libm.a libmingwthrd.a libgmon.a:
371         $(AR) $(ARFLAGS) $@ $?
372
373 # Complex math objects, to be included in libmingwex.a
374 # (FIXME: consider whether these might be more suitably
375 # delivered in libm.a; ISO-C99 says they belong in the
376 # math library, which by POSIX convention, is libm.a)
377 #
378 vpath %.c ${mingwrt_srcdir}/mingwex
379 vpath %.c ${mingwrt_srcdir}/mingwex/complex
380 libmingwex.a: $(addsuffix .$(OBJEXT), cabs carg catan ccoshf clog creal csqrt \
381   cabsf cargf catanf ccoshl clogf crealf csqrtf cabsl cargl catanh ccosl clogl \
382   creall csqrtl cacos casin catanhf cexp cpow csin ctan cacosf casinf catanhl \
383   cexpf cpowf csinf ctanf cacosh casinh catanl cexpl cpowl csinh ctanh cacoshf \
384   casinhf ccos cimag cproj csinhf ctanhf cacoshl casinhl ccosf cimagf cprojf \
385   csinhl ctanhl cacosl casinl ccosh cimagl cprojl csinl ctanl)
386
387 libmingwex.a: $(addsuffix .$(OBJEXT), isblank iswblank)
388
389 # Floating point environment control, in libmingwex.a
390 # (FIXME: once again, maybe better delivered in libm.a)
391 #
392 libmingwex.a: $(addsuffix .$(OBJEXT), fegetenv fesetenv feupdateenv \
393   feclearexcept feraiseexcept fetestexcept feholdexcept fegetexceptflag \
394   fesetexceptflag fegetround fesetround)
395
396 # David Gay's "gdtoa" API, provided in libmingwex.a, and used
397 # by MinGW's ISO-C conforming printf() routines for formatting
398 # floating point output.
399 #
400 vpath %.c ${mingwrt_srcdir}/mingwex/gdtoa
401 libmingwex.a: $(addsuffix .$(OBJEXT), g__fmt gethex strtopx g_dfmt gdtoa \
402   gmisc smisc sum g_ffmt hd_init strtodg ulp dmisc g_xfmt hexnan strtodnrp \
403   dtoa misc strtof)
404
405 # "inttypes" conversion routines, provided in libmingwex.a
406 #
407 libmingwex.a: $(addsuffix .$(OBJEXT), \
408   imaxabs imaxdiv strtoimax strtoumax wcstoimax wcstoumax)
409
410 # Additional math functions, augmenting Microsoft's paltry
411 # selection, also delivered in libmingwex.a, (FIXME: and yet
412 # again, perhaps libm.a would be a better fit)
413 #
414 vpath %.c ${mingwrt_srcdir}/mingwex/math
415 vpath %.s ${mingwrt_srcdir}/mingwex/math
416 libmingwex.a: $(addsuffix .$(OBJEXT), cosf cosl acosf acosl sinf sinl asinf \
417   asinl tanf tanl atanf atanl atan2f atan2l coshf coshl acosh acoshf acoshl \
418   sinhf sinhl asinh asinhf asinhl tanhf tanhl atanh atanhf atanhl cbrt cbrtf \
419   cbrtl ceilf ceill copysign copysignf copysignl erfl s_erf sf_erf expf expl \
420   exp2 exp2f exp2l expm1 expm1f expm1l fabs fabsf fabsl fdim fdimf fdiml \
421   floorf floorl fma fmaf fmal fmax fmaxf fmaxl fmin fminf fminl fmodf fmodl \
422   fp_consts fp_constsf fp_constsl fpclassify fpclassifyf fpclassifyl frexpf \
423   frexpl fucom hypotf hypotl ilogb ilogbf ilogbl isnan isnanf isnanl ldexpf \
424   ldexpl lgamma lgammaf lgammal llrint llrintf llrintl log10f log10l log1p \
425   log1pf log1pl log2 log2f log2l logb logbf logbl logf logl lrint lrintf \
426   lrintl llround llroundf llroundl lround lroundf lroundl modff modfl \
427   nearbyint nearbyintf nearbyintl nextafterf nextafterl nexttoward nexttowardf \
428   powf powl powi powif powil remainder remainderf remainderl remquo remquof \
429   remquol rint rintf rintl round roundf roundl scalbn scalbnf scalbnl signbit \
430   signbitf signbitl sqrtf sqrtl tgamma tgammaf tgammal trunc truncf truncl)
431
432 # Replacement I/O functions in libmingwex.a, providing better POSIX
433 # compatibility than their Microsoft equivalents.
434 #
435 vpath %.c ${mingwrt_srcdir}/mingwex/stdio
436 libmingwex.a: $(addsuffix .$(OBJEXT), btowc fopen64 fprintf fseeko64 ftello64 \
437   lseek64 pformat printf snprintf snwprintf sprintf vfprintf vfscanf vfwscanf \
438   vprintf vscanf vsnprintf vsnwprintf vsprintf vsscanf vswscanf vwscanf)
439
440 # FIXME: We should adopt a semantic implementation similar to the
441 # dlsym( RTLD_DEFAULT, "_get_output_format" ) call in POSIX, to let
442 # us handle the following fall-back more effectively.
443 #
444 # pformat.$(OBJEXT) needs an explicit build rule; we always build it
445 # assuming that __MSVCRT_VERSION__ >= 0x0800, (and thus assuming that
446 # the Microsoft runtime provides the _get_output_format() function);
447 # we then rely on ofmt_stub.s, (in the top mingwrt source directory),
448 # to provide a fall-back implementation, so maintaining forward
449 # compatibility for earlier versions of MSVCRT.DLL
450 #
451 PFORMAT_CFLAGS = -I ${mingwrt_srcdir}/mingwex/gdtoa -D__MSVCRT_VERSION__=0x0800
452 pformat.$(OBJEXT): %.$(OBJEXT): %.c
453         $(CC) -c $(ALL_CFLAGS) $(PFORMAT_CFLAGS) $< -o $@
454
455 # Some additional miscellaneous functions, in libmingwex.a
456 #
457 #libmingwex.a: $(addsuffix .$(OBJEXT), glob membarrier)
458 libmingwex.a: $(addsuffix .$(OBJEXT), mingw-aligned-malloc mingw-fseek glob)
459 libmingwex.a: $(addsuffix .$(OBJEXT), getopt basename dirname ftruncate usleep)
460
461 libmingwex.a: $(addsuffix .$(OBJEXT), tdelete tfind tsearch twalk)
462
463 libmingwex.a: $(addsuffix .$(OBJEXT), _Exit atoll lltoa lltow \
464   ulltoa ulltow wtoll)
465
466 libmingwex.a: gettimeofday.$(OBJEXT)
467 libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn)
468
469 libmingwex.a: $(addsuffix .$(OBJEXT), fwide mbrtowc mbsinit wcrtomb wcstof \
470   wcstold wctob wmemchr wmemcmp wmemcpy wmemmove wmemset)
471
472 libmingwex.a: $(addsuffix .$(OBJEXT), wctrans wctype)
473
474 # For the math sources, we support the convention that a single
475 # quux_generic.c source file will produce three objects: quux.o,
476 # quuxf.o, and quuxl.o; since a change in the common source file
477 # will require all three objects to be recompiled, we may handle
478 # this with a single, multiple target, pattern rule.
479 #
480 $(addsuffix .$(OBJEXT), % %f %l): %_generic.c
481         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $*.$(OBJEXT) $<
482         $(CC) -c -D FUNCTION=$*f $(CPPFLAGS) $(ALL_CFLAGS) -o $*f.$(OBJEXT) $<
483         $(CC) -c -D FUNCTION=$*l $(CPPFLAGS) $(ALL_CFLAGS) -o $*l.$(OBJEXT) $<
484
485 # The llround.o, llroundf.o, and llroundl.o variants are a special
486 # case of the preceding rule; (the source is lround_generic.c rather
487 # than llround_generic.c).  We can handle this using the following
488 # static pattern rule, (compiling each object individually).
489 #
490 $(addsuffix .$(OBJEXT), llround llroundf llroundl): %.$(OBJEXT): lround_generic.c
491         $(CC) -c -D FUNCTION=$* $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
492
493 # Historically, MinGW.org's libm.a has been a dummy, delivering
494 # nothing of value; FIXME: IMO, this sucks; it should deliver the
495 # non-MSVCRT.DLL math functions, as noted above.
496 #
497 all-mingwrt-libs install-mingwrt-libs: libm.a
498 libm.a: libm_dummy.$(OBJEXT)
499 libm_dummy.c: Makefile
500         echo "static int __mingw_libm_dummy;" > $@
501
502 # The mingwrt headers define a number of functions which are normally
503 # expected to be compiled as inline code.  Each such function must also
504 # be provided with an externally visible entry point; we provide such
505 # entry points as stubs in libmingwex.a, via the following rules:
506 #
507 sinclude Makefile.stub
508 vpath jmpstub.sx ${mingwrt_srcdir}/mingwex
509 libstub_refnames = grep -lr '__$1.*FUNCTION *=' ${mingwrt_srcdir}
510 jmpstub_prerequisites := $(shell $(call libstub_refnames,JMPSTUB)/include)
511 libimpl_prerequisites := $(shell $(call libstub_refnames,LIBIMPL)/include)
512 Makefile.stub: Makefile $(jmpstub_prerequisites) $(libimpl_prerequisites)
513         echo "# $@: automatically generated file -- do not edit!" > $@
514         $(call jmpstub_awk_script,$(jmpstub_prerequisites)) >> $@
515         $(call libimpl_awk_script,$(libimpl_prerequisites)) >> $@
516         echo "# $@: end of file" >> $@
517
518 # Stubs are categorized into either of JMPSTUB or LIBIMPL classes;
519 # the rules for building the JMPSTUP inplementations are written to
520 # Makefile.stub, by processing each of their defining header files
521 # through the following awk script...
522 #
523 jmpstub_awk_script = test -z "$1" || awk '\
524   BEGIN { \
525     symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
526     fmt = "\nlib%s.a: %s\n%s: jmpstub.sx\n\t$$(COMPILE.sx) %s -o $$@ $$^\n"; \
527   } \
528   /__JMPSTUB(__)? *[(].*FUNCTION/ { \
529     LIB = "mingwex"; \
530     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
531     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".jmpstub.$$(OBJEXT)"; \
532     OBJNAME_CFLAGS = "-D FUNCTION="FUNCTION; \
533     printf fmt, LIB, OBJNAME, OBJNAME, OBJNAME_CFLAGS; \
534   } \
535   END { \
536     printf "\n"; \
537   }' $1
538
539 # ...while this establishes the dependencies which apply for each
540 # of those in the LIBIMPL class.
541 #
542 libimpl_awk_script = test -z "$1" || awk '\
543   BEGIN { \
544     symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
545     fmt = "\nlib%s.a: %s\n%s.libimpl: %s\n"; \
546   } \
547   /__LIBIMPL(__)? *[(].*FUNCTION/ { \
548     LIB = "mingwex"; \
549     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
550     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".libimpl.$$(OBJEXT)"; \
551     printf fmt, LIB, OBJNAME, FUNCTION, FILENAME; \
552   } \
553   END { \
554     printf "\n"; \
555   }' $1
556
557 # In contrast to JMPSTUB implementations, which are best handled
558 # by individual compilation rules in Makefile.stub, generic rules
559 # are sufficient for all LIBIMPL implementations; in each case, we
560 # filter the static attribute from each defined implementation, in
561 # its defining header file, to create an intermediate C source for
562 # each individual function; (note that we also remove any pragma
563 # which identifies the originating file as a system header).
564 #
565 libimpl_sed_script = sed \
566   -e '/__CRT_ALIAS  *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d' \
567   -e '/pragma .* system_header/d'
568
569 LIBIMPL_CFLAGS = $(CFLAGS) $(INCLUDES) -fno-align-functions
570
571 # LIBIMPL dependencies are tracked using zero sized name.libimpl
572 # files; the intermediate C files are generated as a side effect
573 # of resolving these dependencies...
574 #
575 %.libimpl:
576         $(call libimpl_sed_script,$*) $< > $@.c
577         > $@
578
579 # ...and ultimately discarded, after the requisite object file
580 # has been compiled.
581 #
582 %.libimpl.$(OBJEXT): %.libimpl
583         $(CC) -c $(CPPFLAGS) $(LIBIMPL_CFLAGS) -o $@ $<.c
584         $(RM) $<.c
585
586 # Thread support libraries.
587 #
588 all-mingwrt-libs install-mingwrt-libs: libmingwthrd.a libmingwthrd_old.a
589 libmingwthrd.a libmingwthrd_old.a: crtmt.$(OBJEXT)
590 mingwthrd_old.def mingwm10.dll: $(addsuffix .$(OBJEXT), mthr mthr_init)
591 mingwthrd_old.def:
592         $(DLLTOOL) --as $(AS) --output-def $@ $^
593
594 libmingwthrd_old.a: lib%.a: %.def
595         $(DLLTOOL) --as $(AS) --input-def $< --dllname mingwm10.dll --output-lib $@
596         $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
597
598 all-mingwrt-dll install-mingwrt-dll-files: mingwm10.dll
599 mingwm10.dll: mingwthrd_old.def
600         $(CC) -shared -o $@ -Wl,--image-base,0x6FBC0000 \
601           -Wl,--entry,_DllMainCRTStartup@12 $^
602
603 # Code profiling support, using the GNU profiling library; (note
604 # that applications using this library MUST be licensed to comply
605 # with the GNU General Public License).
606 #
607 all-mingwrt-libs install-mingwrt-libs: libgmon.a
608 libgmon.a: $(addsuffix .$(OBJEXT), gmon mcount profil)
609
610
611 # Installation Rules
612 # ------------------
613 #
614 # Users may expect to be able to specify DESTDIR, to stage the
615 # following stock installation directories outside of the regular
616 # "as configured" installation tree; unfortunately, this expectation
617 # MUST fail, when the stock path is in MS-Windows absolute format, so
618 # we provide an exception mechanism to forbid such usage, and we
619 # proceed to create the directories only when the exception is
620 # NOT triggered.
621 #
622 .PHONY: DESTDIR-UNSUPPORTED
623 bindir docdir includedir libdir mandir htmldir pdfdir:
624         @test -z "$(strip ${DESTDIR})" || case $($@) in ${DESTDIR}?:*) \
625           $(MAKE) --no-print-directory reject=$@ DESTDIR-UNSUPPORTED;; \
626           esac
627         $(mkinstalldirs) $($@)
628
629 # Note: we MUST use a recursive make invocation here, as the
630 # "error" function within the accompanying diagnostics would be
631 # triggered, irrespective of its placement in an unexecuted
632 # branch of the above exception trapping shell code.
633 #
634 DESTDIR-UNSUPPORTED:
635         $(call MSG_DESTDIR_FORBIDDEN,$(reject),$($(reject):${DESTDIR}%=%))
636
637 # The following macros, which rely heavily on GNU make's "call"
638 # function, define the diagnostics to be emitted, when the DESTDIR
639 # exception is triggered.
640 #
641 QUOTE = `$1'#'`
642 MSG_DESTDIR_FORBIDDEN = \
643   $(warning *** $(call MSG_DESTDIR_PATH_CONFLICT,$1,Win32,$2);) \
644   $(error try $(call QUOTE,$(call MSG_DESTDIR_ALTERNATIVE,$1,$2)) instead)
645 MSG_DESTDIR_BAD_PATH = DESTDIR is not supported when $1 contains $2 path $3
646 MSG_DESTDIR_PATH_CONFLICT = $(call MSG_DESTDIR_BAD_PATH,$1,$2,$(call QUOTE,$3))
647 MSG_DESTDIR_ALTERNATIVE = make install $1="$(call MSG_DESTDIR_TRANSFORM,$2)"
648 MSG_DESTDIR_TRANSFORM = ${DESTDIR}$(shell echo $1 | sed 's/^.://')
649
650 # Install everything.
651 #
652 install: install-mingwrt
653 install-stage-1-only: install-headers install-libdir-objects install-libs
654 install-stage-1-and-2: install-stage-1-only install-bin
655 install-gcc: install-stage-1-only
656
657 # Install licence files.
658 #
659 install-license: install-mingwrt-license
660 install-licence install-mingwrt-licence: %-licence: %-license
661
662 vpath DISCLAIMER ${mingwrt_srcdir}
663 vpath COPYING ${mingwrt_srcdir}/profile
664 vpath CYGWIN_LICENSE ${mingwrt_srcdir}/profile
665 mingwrt-license-files: COPYING CYGWIN_LICENSE DISCLAIMER
666
667 # FIXME: The following rule is generalized, such that it may accommodate
668 # both mingwrt and w32api, (and other packages); thus, it should ideally
669 # be relocated into a common (shared) Makefile fragment.
670 #
671 install-mingwrt-license install-w32api-license: install-%: docdir %-files
672 %-license-files:
673         $(mkinstalldirs) ${docdir}/$*/$(PACKAGE_VERSION)
674         $(INSTALL_DATA) $^ ${docdir}/$*/$(PACKAGE_VERSION)
675
676 # Install headers associated with the MinGW runtime libraries.
677 #
678 includedirs: mingwrt-includedirs
679 install-headers install-mingwrt: install-mingwrt-headers
680
681 ${includedir}/sys: includedir
682 mingwrt-includedirs: ${includedir}/sys
683         $(mkinstalldirs) $^
684
685 install-mingwrt-headers: mingwrt-includedirs
686         $(INSTALL_DATA) ${mingwrt_srcdir}/include/*.h ${includedir}
687         $(INSTALL_DATA) ${mingwrt_srcdir}/include/sys/*.h ${includedir}/sys
688         $(INSTALL_DATA) ${mingwrt_srcdir}/profile/*.h ${includedir}
689
690 # Install libraries, and supporting free standing object files.
691 #
692 install-libs install-mingwrt: install-mingwrt-libdir-libs
693 install-libdir-objects install-mingwrt: install-mingwrt-libdir-objects
694
695 install-mingwrt-libdir-libs: libdir $(call active_goals,install,mingwrt-libs)
696 install-mingwrt-libdir-objects: libdir $(call active_goals,install,crt-objects)
697
698 install-crt-objects install-deprecated-crt-objects \
699 install-mingwrt-libs install-deprecated-mingwrt-libs:
700         $(INSTALL_DATA) $^ ${libdir}
701
702 # Install DLLs.
703 #
704 install-mingwrt: install-mingwrt-dll
705 install-bin install-dll: install-mingwrt-dll 
706 install-mingwrt-bin install-w32api-bin: install-%-bin: install-%-dll
707 install-mingwrt-dll install-w32api-dll: install-%-dll: bindir install-%-dll-files
708 install-%-dll-files:
709         $(INSTALL_DATA) $^ ${bindir}
710
711 # Install manpages.
712 #
713 install-man install-manpages: install-mingwrt-manpages
714 format_manpage = sed "s/%PAGEREF%/`echo $1 | tr a-z A-Z` $2/"
715
716 vpath %.man ${mingwrt_srcdir}/man
717 basename.$(man3ext) dirname.$(man3ext): %.$(man3ext): dirname.man
718         $(call format_manpage,$*,$(man3ext)) $< > $@
719
720 mingwrt-man$(man3ext): basename.$(man3ext) dirname.$(man3ext)
721
722 install-mingwrt-manpages: mandir mingwrt-man3
723 mingwrt-man%:
724         $(mkinstalldirs) ${man$*dir}
725         $(INSTALL_DATA) $^ ${man$*dir}
726         $(RM) $^
727
728
729 # Distribution
730 # ------------
731 #
732 .PHONY: dist
733 dist: devdist dlldist licdist mandist srcdist
734         $(RM) -r dist/mingwrt dist/w32api
735
736 mingwrt-dist-staged w32api-dist-staged: %-dist-staged:
737         $(RM) -r dist/$*
738         $(MAKE) --no-print-directory prefix=`pwd`/dist/$* install-$*
739
740 devdist: mingwrt-devdist
741 mingwrt_devdist_objects = dist/mingwrt/lib/*.$(OBJEXT)
742 mingwrt-devdist w32api-devdist: %-devdist: %-dist-staged
743         $(STRIP) -g $($*_devdist_objects) dist/$*/lib/*.a
744         cd dist/$* && tar chf - --hard-dereference include lib | \
745           xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dev.tar.xz
746
747 dlldist: mingwrt-dlldist
748 mingwrt-dlldist: %-dlldist: %-dist-staged
749         $(STRIP) dist/$*/bin/*.dll
750         cd dist/$* && tar chf - --hard-dereference bin | \
751           xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dll.tar.xz
752
753 licdist: mingwrt-licdist
754 mingwrt-licdist w32api-licdist: %-licdist:
755         $(RM) -r tmp
756         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-licence
757         cd tmp && tar chf - --hard-dereference * | \
758           xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-lic.tar.xz
759         $(RM) -r tmp
760
761 mandist: mingwrt-mandist
762 mingwrt-mandist: %-mandist:
763         $(RM) -r tmp
764         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-manpages
765         cd tmp && tar chf - --hard-dereference share | \
766           xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-man.tar.xz
767         $(RM) -r tmp
768
769 srcdist: mingwrt-srcdist
770 mingwrt-srcdist: mingwrt-srcdist-dir mingwrt-srcdist-files
771         cd dist && tar chf - $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | \
772           xz -c > $(PACKAGE_TARNAME)-$(PACKAGE_RELEASE_TAG)-src.tar.xz
773         $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
774
775 mingwrt-srcdist-dir:
776         $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
777         $(mkinstalldirs) dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
778
779 mingwrt-srcdist-files:
780         (cd ${mingwrt_srcdir} && tar chf - --hard-dereference $(notdir $^)) | \
781           (cd dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) && tar xf -)
782
783 mingwrt-srcdist-files: $(wildcard ${mingwrt_srcdir}/*.[chs]) \
784   $(addprefix ${mingwrt_srcdir}/,ChangeLog CONTRIBUTORS DISCLAIMER README) \
785   $(wildcard ${mingwrt_srcdir}/*.def.in) $(wildcard ${mingwrt_srcdir}/config*) \
786   $(addprefix ${mingwrt_srcdir}/,aclocal.m4 install-sh Makefile.in TODO) \
787   $(addprefix ${mingwrt_srcdir}/,include man mingwex profile) \
788   $(addprefix ${mingwrt_srcdir}/,crtdll.def) \
789   $(wildcard ${mingwrt_srcdir}/*.txt)
790
791 install-html install-pdf: install-%: %dir mingwrt-man$(man3ext)
792         $(MAKE) --no-print-directory install-$*-files
793
794 install-html-files install-pdf-files: install-%-files: \
795   $(addsuffix .%,$(wildcard ${man3dir}/*.$(man3ext)))
796
797 %.$(man3ext).html: %.$(man3ext)
798         man2html $< | sed -e '1,/^<!DOCTYPE/{/^<!/p;d' -e '}' > ${htmldir}/$(notdir $@)
799         chmod 644 ${htmldir}/$(notdir $@)
800
801 %.$(man3ext).pdf: %.$(man3ext)
802         man -t $< | ps2pdf - > ${pdfdir}/$(notdir $@)
803         chmod 644 ${pdfdir}/$(notdir $@)
804
805 html-docdist pdf-docdist: %-docdist:
806         $(RM) -r tmp
807         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*
808         $(RM) -r tmp/share/man
809         cd tmp && tar chf - --hard-dereference share | \
810           xz -c > ../dist/mingwrt-doc-$(PACKAGE_RELEASE_TAG)-$*.tar.xz
811         $(RM) -r tmp
812
813
814 # Clean-up Rules
815 # --------------
816 #
817 clean-local: mostlyclean-local
818         $(RM) msvcr*.def moldname*.def mingw*.def lib*.a *.dll
819
820 mostlyclean-local:
821         $(RM) *.d *.$(OBJEXT) Makefile.stub
822
823 distclean-local: clean-local
824         $(RM) config.log config.status libm_dummy.c
825
826 maintainer-clean-warning:
827         $(warning $(MAKE) $(@:%-warning=%))
828         $(warning This command should be used by package maintainers only;)
829         $(warning it deletes files which may require special tools to rebuild.)
830
831 maintainer-clean-local: maintainer-clean-warning distclean-local
832         $(RM) -r ${mingwrt_srcdir}/autom4te.cache
833
834 clean mostlyclean distclean maintainer-clean: %clean: %clean-local
835
836 # $RCSfile$: end of file