4 # Makefile template for MinGW.org Runtime Library Package
6 PACKAGE_TARNAME := @PACKAGE_TARNAME@
7 PACKAGE_VERSION := @PACKAGE_VERSION@
9 # Written by Keith Marshall <keithmarshall@users.sourceforge.net>
10 # Copyright (C) 2014, MinGW.org Project
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:
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
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.
33 # The default target is "all"; declare it early, to avoid any possible
34 # inadvertent override from any included file.
38 PACKAGE_RELEASE_TAG := $(PACKAGE_VERSION)$(PACKAGE_RELEASE:%=-%)-mingw32
39 NTDDI_VERSION_SPEC := -D NTDDI_VERSION=0x04000000
41 # Build paths and macros.
44 top_srcdir = @top_srcdir@
45 mingwrt_srcdir = @srcdir@
46 w32api_srcdir = @w32api_srcdir@
47 abs_builddir = @abs_builddir@
60 COMPILE.sx = @COMPILE_SX@
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
70 include_deprecated = @include_deprecated@
71 active_goals = $1-$2 $(if $(include_deprecated),$1-deprecated-$2)
73 all-stage-1: $(call active_goals,all,mingwrt-stage-1)
74 all-stage-1-and-2: $(call active_goals,all,mingwrt)
76 # Installation paths and macros.
79 exec_prefix = @exec_prefix@
80 bindir = ${DESTDIR}@bindir@
82 datarootdir = @datarootdir@
83 docdir = ${DESTDIR}${datarootdir}/doc
84 includedir = ${DESTDIR}@includedir@
85 libdir = ${DESTDIR}@libdir@
90 mandir = ${DESTDIR}@mandir@
91 man3dir = ${mandir}/man$(man3ext)
96 INSTALL_DATA = @INSTALL_DATA@
98 mkinstalldirs = @MKDIR_P@
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 ...
105 vpath configure ${top_srcdir}
106 config.status: configure
107 $(SHELL) config.status --recheck
109 # ... in which case, updating Makefile should be a simple matter of
110 # running config.status ...
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
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.
123 config.status.missing:
124 $(warning *** cannot execute config.status)
125 $(error please run ${top_srcdir}/configure to regenerate it.)
127 # If configure itself needs to be updated, we must run autoconf in the
128 # top level source directory.
130 vpath %.m4 ${top_srcdir}
131 vpath configure.ac ${top_srcdir}
132 configure: configure.ac aclocal.m4
133 cd ${top_srcdir}; autoconf
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.
141 INCLUDES = -nostdinc -I . -I ${top_srcdir}/include -I ${w32api_srcdir}/include \
142 -I ${top_srcdir} -I ${top_srcdir}/profile -iwithprefixbefore include
144 ALL_CFLAGS = $(CFLAGS) $(DEPFLAGS) $(INCLUDES) $(NTDDI_VERSION_SPEC)
146 # The general case, for compiling object files from C source,
147 # requires a small adjustment to the default implicit rule.
150 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
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.
157 $(CC) -c -D UNICODE $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
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.
167 $(COMPILE.sx) $($*_cflags) -o $@ $<
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).
176 all-mingwrt-objects: $(call active_goals,all,crt-objects)
177 all-deprecated-mingwrt-objects: all-deprecated-crt-objects
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.
185 all-crt-objects install-crt-objects: $(addsuffix .$(OBJEXT), crt2 crtmt \
186 crtst dllcrt2 gcrt2 CRT_fp8 CRT_fp10 CRT_noglob binmode txtmode)
188 all-deprecated-crt-objects install-deprecated-crt-objects: \
189 $(addsuffix .$(OBJEXT), crt1 dllcrt1 gcrt1)
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.
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...
200 vpath %.c ${mingwrt_srcdir}
201 $(addsuffix .$(OBJEXT), crt1 dllcrt1): %.$(OBJEXT): %.c
202 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -D__CRTDLL__ -o $@ $<
204 # ...while, for the current build case, we need an explicit mapping
205 # to identify the disparately named source file.
207 $(addsuffix .$(OBJEXT), crt2 dllcrt2): %2.$(OBJEXT): %1.c
208 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
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.
216 vpath %.c ${mingwrt_srcdir}/profile
217 $(addsuffix .$(OBJEXT), gcrt0 gcrt1 gcrt2): %.$(OBJEXT): gcrt0.c
218 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
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.
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.
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 ) \
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); \
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 ) \
250 # We categorize our import libraries into "standard" (a.k.a. "release")
251 # versions, augmented by corresponding "debug" variants.
253 std_msvcrt := $(addprefix msvcr,t $(msvcrt_versions))
254 all_msvcrt := $(std_msvcrt) $(addsuffix d,$(std_msvcrt))
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
261 # FIXME: We should aim to remove this interim work-around...
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)
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)
274 # For each import library to be built, we derive a tailored exports
275 # definition file, from a common source.
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,$*)` \
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.
290 msvcrt_repl_prefix = __msvcrt
291 msvcrt_repl_funcs = printf fprintf sprintf vprintf vfprintf vsprintf
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...
306 dlltool_temp_prefix = $(NM) $(1) | sed -n -e '/t.o:$$/{s///p;q' -e '}'
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...
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') \
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.
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,$@)`*
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
342 std_moldname := moldname $(addprefix moldname,$(msvcrt_versions))
343 all_moldname := $(std_moldname) $(addsuffix d,$(std_moldname))
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,$^)
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.
356 $(foreach name,coldname $(all_moldname),lib$(name).a): $(addsuffix .$(OBJEXT), \
357 isascii iscsym iscsymf strcasecmp strncasecmp toascii wcscmpi)
359 coldname.def: %.def: ${mingwrt_srcdir}/moldname.def.in
360 $(CC) -C -E -P -D__FILENAME__=$@ -D__CRTDLL__ -xc-header $< > $@
362 $(addsuffix .def,$(all_moldname)): %.def: ${mingwrt_srcdir}/moldname.def.in
363 $(CC) -C -E -P -D__FILENAME__=$@ -xc-header $< > $@
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)
370 libmingw32.a libmingwex.a libm.a libmingwthrd.a libgmon.a:
371 $(AR) $(ARFLAGS) $@ $?
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)
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)
387 libmingwex.a: $(addsuffix .$(OBJEXT), isblank iswblank)
389 # Floating point environment control, in libmingwex.a
390 # (FIXME: once again, maybe better delivered in libm.a)
392 libmingwex.a: $(addsuffix .$(OBJEXT), fegetenv fesetenv feupdateenv \
393 feclearexcept feraiseexcept fetestexcept feholdexcept fegetexceptflag \
394 fesetexceptflag fegetround fesetround)
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.
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 \
405 # "inttypes" conversion routines, provided in libmingwex.a
407 libmingwex.a: $(addsuffix .$(OBJEXT), \
408 imaxabs imaxdiv strtoimax strtoumax wcstoimax wcstoumax)
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)
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)
432 # Replacement I/O functions in libmingwex.a, providing better POSIX
433 # compatibility than their Microsoft equivalents.
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)
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.
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
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 $@
455 # Some additional miscellaneous functions, in libmingwex.a
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)
461 libmingwex.a: $(addsuffix .$(OBJEXT), tdelete tfind tsearch twalk)
463 libmingwex.a: $(addsuffix .$(OBJEXT), _Exit atoll lltoa lltow \
466 libmingwex.a: gettimeofday.$(OBJEXT)
467 libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn)
469 libmingwex.a: $(addsuffix .$(OBJEXT), fwide mbrtowc mbsinit wcrtomb wcstof \
470 wcstold wctob wmemchr wmemcmp wmemcpy wmemmove wmemset)
472 libmingwex.a: $(addsuffix .$(OBJEXT), wctrans wctype)
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.
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) $<
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).
490 $(addsuffix .$(OBJEXT), llround llroundf llroundl): %.$(OBJEXT): lround_generic.c
491 $(CC) -c -D FUNCTION=$* $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
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.
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;" > $@
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:
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" >> $@
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...
523 jmpstub_awk_script = test -z "$1" || awk '\
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"; \
528 /__JMPSTUB(__)? *[(].*FUNCTION/ { \
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; \
539 # ...while this establishes the dependencies which apply for each
540 # of those in the LIBIMPL class.
542 libimpl_awk_script = test -z "$1" || awk '\
544 symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
545 fmt = "\nlib%s.a: %s\n%s.libimpl: %s\n"; \
547 /__LIBIMPL(__)? *[(].*FUNCTION/ { \
549 FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
550 OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".libimpl.$$(OBJEXT)"; \
551 printf fmt, LIB, OBJNAME, FUNCTION, FILENAME; \
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).
565 libimpl_sed_script = sed \
566 -e '/__CRT_ALIAS *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d' \
567 -e '/pragma .* system_header/d'
569 LIBIMPL_CFLAGS = $(CFLAGS) $(INCLUDES) -fno-align-functions
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...
576 $(call libimpl_sed_script,$*) $< > $@.c
579 # ...and ultimately discarded, after the requisite object file
582 %.libimpl.$(OBJEXT): %.libimpl
583 $(CC) -c $(CPPFLAGS) $(LIBIMPL_CFLAGS) -o $@ $<.c
586 # Thread support libraries.
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)
592 $(DLLTOOL) --as $(AS) --output-def $@ $^
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,$^)
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 $^
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).
607 all-mingwrt-libs install-mingwrt-libs: libgmon.a
608 libgmon.a: $(addsuffix .$(OBJEXT), gmon mcount profil)
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
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;; \
627 $(mkinstalldirs) $($@)
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.
635 $(call MSG_DESTDIR_FORBIDDEN,$(reject),$($(reject):${DESTDIR}%=%))
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.
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/^.://')
650 # Install everything.
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
657 # Install licence files.
659 install-license: install-mingwrt-license
660 install-licence install-mingwrt-licence: %-licence: %-license
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
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.
671 install-mingwrt-license install-w32api-license: install-%: docdir %-files
673 $(mkinstalldirs) ${docdir}/$*/$(PACKAGE_VERSION)
674 $(INSTALL_DATA) $^ ${docdir}/$*/$(PACKAGE_VERSION)
676 # Install headers associated with the MinGW runtime libraries.
678 includedirs: mingwrt-includedirs
679 install-headers install-mingwrt: install-mingwrt-headers
681 ${includedir}/sys: includedir
682 mingwrt-includedirs: ${includedir}/sys
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}
690 # Install libraries, and supporting free standing object files.
692 install-libs install-mingwrt: install-mingwrt-libdir-libs
693 install-libdir-objects install-mingwrt: install-mingwrt-libdir-objects
695 install-mingwrt-libdir-libs: libdir $(call active_goals,install,mingwrt-libs)
696 install-mingwrt-libdir-objects: libdir $(call active_goals,install,crt-objects)
698 install-crt-objects install-deprecated-crt-objects \
699 install-mingwrt-libs install-deprecated-mingwrt-libs:
700 $(INSTALL_DATA) $^ ${libdir}
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
709 $(INSTALL_DATA) $^ ${bindir}
713 install-man install-manpages: install-mingwrt-manpages
714 format_manpage = sed "s/%PAGEREF%/`echo $1 | tr a-z A-Z` $2/"
716 vpath %.man ${mingwrt_srcdir}/man
717 basename.$(man3ext) dirname.$(man3ext): %.$(man3ext): dirname.man
718 $(call format_manpage,$*,$(man3ext)) $< > $@
720 mingwrt-man$(man3ext): basename.$(man3ext) dirname.$(man3ext)
722 install-mingwrt-manpages: mandir mingwrt-man3
724 $(mkinstalldirs) ${man$*dir}
725 $(INSTALL_DATA) $^ ${man$*dir}
733 dist: devdist dlldist licdist mandist srcdist
734 $(RM) -r dist/mingwrt dist/w32api
736 mingwrt-dist-staged w32api-dist-staged: %-dist-staged:
738 $(MAKE) --no-print-directory prefix=`pwd`/dist/$* install-$*
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
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
753 licdist: mingwrt-licdist
754 mingwrt-licdist w32api-licdist: %-licdist:
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
761 mandist: mingwrt-mandist
762 mingwrt-mandist: %-mandist:
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
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)
776 $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
777 $(mkinstalldirs) dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
779 mingwrt-srcdist-files:
780 (cd ${mingwrt_srcdir} && tar chf - --hard-dereference $(notdir $^)) | \
781 (cd dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) && tar xf -)
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)
791 install-html install-pdf: install-%: %dir mingwrt-man$(man3ext)
792 $(MAKE) --no-print-directory install-$*-files
794 install-html-files install-pdf-files: install-%-files: \
795 $(addsuffix .%,$(wildcard ${man3dir}/*.$(man3ext)))
797 %.$(man3ext).html: %.$(man3ext)
798 man2html $< | sed -e '1,/^<!DOCTYPE/{/^<!/p;d' -e '}' > ${htmldir}/$(notdir $@)
799 chmod 644 ${htmldir}/$(notdir $@)
801 %.$(man3ext).pdf: %.$(man3ext)
802 man -t $< | ps2pdf - > ${pdfdir}/$(notdir $@)
803 chmod 644 ${pdfdir}/$(notdir $@)
805 html-docdist pdf-docdist: %-docdist:
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
817 clean-local: mostlyclean-local
818 $(RM) msvcr*.def moldname*.def mingw*.def lib*.a *.dll
821 $(RM) *.d *.$(OBJEXT) Makefile.stub
823 distclean-local: clean-local
824 $(RM) config.log config.status libm_dummy.c
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.)
831 maintainer-clean-local: maintainer-clean-warning distclean-local
832 $(RM) -r ${mingwrt_srcdir}/autom4te.cache
834 clean mostlyclean distclean maintainer-clean: %clean: %clean-local
836 # $RCSfile$: end of file