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-2017, 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
40 # Establish the minimum version of Windows which this build is required
41 # to support; note that we fix the default as WinNT4, but we define it in
42 # a manner which will allow a command line override, and may be adapted,
43 # ultimately, to support a configure time assignment.
45 NTDDI_VERSION := NTDDI_WINNT4
46 NTDDI_VERSION_SPEC := $(NTDDI_VERSION:%=-D NTDDI_VERSION=%)
48 # Build paths and macros.
51 top_srcdir = @top_srcdir@
52 mingwrt_srcdir = @srcdir@
53 w32api_srcdir = @w32api_srcdir@
54 abs_builddir = @abs_builddir@
67 COMPILE.sx = @COMPILE_SX@
72 all: @DEFAULT_MAKECMDGOALS@
73 all-mingwrt-stage-1-only: _mingw.h w32api.h
74 all-mingwrt-stage-1-only: all-mingwrt-objects all-mingwrt-libs
75 all-mingwrt-stage-1-and-2: all-mingwrt-stage-1-only all-mingwrt-dll
76 all-mingwrt: all-mingwrt-stage-1-and-2
77 all-gcc: all-mingwrt-stage-1-only
79 active_goals = $1-$2 $(if @include_deprecated@,$1-deprecated-$2)
80 all-deprecated-mingwrt-stage-1-only: all-deprecated-mingwrt
82 all-stage-1-only: $(call active_goals,all,mingwrt-stage-1-only)
83 all-stage-1-and-2: $(call active_goals,all,mingwrt)
85 # Installation paths and macros.
88 exec_prefix = @exec_prefix@
89 bindir = ${DESTDIR}@bindir@
91 datarootdir = @datarootdir@
92 docdir = ${DESTDIR}${datarootdir}/doc
93 includedir = ${DESTDIR}@includedir@
94 libdir = ${DESTDIR}@libdir@
99 mandir = ${DESTDIR}@mandir@
100 man3dir = ${mandir}/man$(man3ext)
105 INSTALL_DATA = @INSTALL_DATA@ $1 $2
107 mkinstalldirs = @MKDIR_P@ $(addprefix $1,$2)
110 # Keep the configuration in a consistent state. Note that we assume
111 # that configure has been run initially, (otherwise we wouldn't have
112 # a Makefile to begin with); since this also creates config.status,
113 # we may normally assume that it is already available ...
115 vpath configure ${top_srcdir}
116 config.status: configure
117 $(SHELL) config.status --recheck
119 # ... in which case, updating Makefile should be a simple matter of
120 # running config.status ...
122 vpath Makefile.in ${top_srcdir}
123 requires_existing = $(if $(wildcard $1),$1,$1.missing)
124 Makefile: Makefile.in configure $(call requires_existing,config.status)
125 $(SHELL) config.status
128 .PHONY: config.status.missing
129 # ... but, in the event that this may be missing, (e.g. because it
130 # has been manually removed, or removed by "make distclean"), suggest
131 # running configure, and bail out.
133 config.status.missing:
134 $(warning *** cannot execute config.status)
135 $(error please run ${top_srcdir}/configure to regenerate it.)
137 # If configure itself needs to be updated, we must run autoconf in the
138 # top level source directory.
140 vpath configure.ac ${top_srcdir}
141 vpath %.m4 ${top_srcdir}/.. ${top_srcdir}
142 configure: configure.ac aclocal.m4 VERSION.m4
143 cd ${top_srcdir}; autoconf -I ..
145 # Propagate package version, as configured, consistently throughout
148 vpath _mingw.h.in ${top_srcdir}/include
149 vpath w32api.h.in ${w32api_srcdir}/include
151 _mingw.h w32api.h: configure.ac
153 PACKAGE_VERSION_SCRIPT = sed \
154 -e s"`$(call PACKAGE_VERSION_FORMAT,LONG,%d,$$3+1000*($$2+1000*$$1))`" \
155 -e s"`$(call PACKAGE_VERSION_FORMAT,MAJOR,%7d,$$1)`" \
156 -e s"`$(call PACKAGE_VERSION_FORMAT,MINOR,%7d,$$2)`" \
157 -e s"`$(call PACKAGE_VERSION_FORMAT,PATCH,%7d,$$3)`"
159 PACKAGE_VERSION_FORMAT = echo $(PACKAGE_VERSION).0.0 | awk -F. '{ \
160 printf ",%%PACKAGE_VERSION_$1%%,$2,", $3; \
163 _mingw.h w32api.h: %.h: %.h.in
164 $(PACKAGE_VERSION_SCRIPT) $< > $@
166 # Capture dependencies conveyed within source files, ensuring that
167 # header files are taken from our working source tree, and not from
168 # the build-time compiler's installation path. (Note: we use -MD,
169 # and not -MMD in DEPFLAGS; since this package furnishes system
170 # headers, we need changes therein to trigger a rebuild).
174 INCLUDES = -nostdinc -I . -I ${top_srcdir}/include -I ${w32api_srcdir}/include \
175 -I ${top_srcdir} -I ${top_srcdir}/profile -iwithprefixbefore include
177 ALL_CFLAGS = $(CFLAGS) $(DEPFLAGS) $(INCLUDES) $(NTDDI_VERSION_SPEC)
178 ALL_CPPFLAGS = $(CPPFLAGS) $(DEPFLAGS) $(INCLUDES) $(NTDDI_VERSION_SPEC)
180 # The general case, for compiling object files from C source,
181 # requires a small adjustment to the default implicit rule.
184 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
186 # In some cases, both ANSI and UTF-16LE enabled variants of object
187 # modules are compiled from a common source; the UTF-16LE variant is
188 # to be identified by prefixing a "w" to the object file name.
191 $(CC) -c -D UNICODE $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
193 # Compiling object files from *.sx sources: since GCC-4.3, these
194 # have been supported as a case agnostic alternative to *.S sources,
195 # for assembly language sources requiring initial interpretation by
196 # the C preprocessor; owing to the case-insensitive nature of file
197 # naming on MS-Windows, we should prefer these, but we must tell
198 # make how to compile them.
201 $(COMPILE.sx) $($*_cflags) -o $@ $<
203 # Several components of the distributable object code base are to
204 # be provided as free-standing object modules, (rather than being
205 # encapsulated within object libraries); we classify these within
206 # two distinct groups, for support of the current MSVCRT.DLL build
207 # case and the older CRTDLL build case, (noting that, ultimately,
208 # we may wish to deprecate this latter case).
210 all-mingwrt-objects: $(call active_goals,all,crt-objects)
211 all-deprecated-mingwrt-objects: all-deprecated-crt-objects
213 # Further note that, in addition to specifying the build time
214 # inventories for each of these object module categories, each
215 # module should be allocated to an associated installation group,
216 # whence it may be included in the eventual distribution, via a
217 # staged installation.
219 all-crt-objects install-crt-objects: $(addsuffix .$(OBJEXT), crt2 crtmt \
220 crtst dllcrt2 gcrt2 CRT_fp8 CRT_fp10 CRT_noglob binmode txtmode)
222 all-deprecated-crt-objects install-deprecated-crt-objects: \
223 $(addsuffix .$(OBJEXT), crt1 dllcrt1 gcrt1)
225 # The crt1.$(OBJEXT) and crt2.$(OBJEXT) modules, for the (deprecated)
226 # CRTDLL and the (current) MSVCRT build cases respectively, are built
227 # from a common crt1.c source. Similarly, the dllcrt1.$(OBJEXT) and
228 # dllcrt2.$(OBJEXT) modules share the common dllcrt1.c source.
230 # Noting that the source files are named for the deprecated build
231 # case, but that we need to specify this while compiling, we need
232 # this explicit pattern rule...
234 vpath %.c ${mingwrt_srcdir}
235 $(addsuffix .$(OBJEXT), crt1 dllcrt1): %.$(OBJEXT): %.c
236 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -D__CRTDLL__ -o $@ $<
238 # ...while, for the current build case, we need an explicit mapping
239 # to identify the disparately named source file.
241 $(addsuffix .$(OBJEXT), crt2 dllcrt2): %2.$(OBJEXT): %1.c
242 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
244 # The initialization hook for profiling code is inherited from Cygwin,
245 # where it is built as gcrt0.$(OBJEXT); we build it, unmodified, as each
246 # of gcrt1.$(OBJEXT) and gcrt2.$(OBJEXT), to satisfy the differing GCC
247 # specs file dependencies for each of the (deprecated) CRTDLL build
248 # and (current) MSVCRT build cases, respectively.
250 vpath %.c ${mingwrt_srcdir}/profile
251 $(addsuffix .$(OBJEXT), gcrt0 gcrt1 gcrt2): %.$(OBJEXT): gcrt0.c
252 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
254 # The primary runtime library is furnished by Microsoft, in the form
255 # of MSVCRT.DLL, as shipped with MS-Windows itself, or in any one of
256 # its versioned variants, as shipped with the MSVC compiler suite.
258 # We furnish the API for this runtime library, in the form of import
259 # libraries, for both release and debug DLL variants; furthermore,
260 # although we favour the freely available MSVCRT.DLL distributions,
261 # we also provide import libraries tailored to the non-free, and
262 # non-redistributable, MSVCRnn.DLL variants, corresponding to each
263 # of the following enumerated versions from the MSVC suite.
265 msvcrt_versions := 70 71 80 90 100
266 msvcrt_version_script = echo $1 | awk '\
267 { printf "0x%03d00000", gensub( "^[^1-9]*([0-9]*).*", "\\\\1", 1 ) \
270 extra_objects_filter = $(filter %.$(OBJEXT),$1)
271 extra_objects_script = test -z "$(call extra_objects_filter,$2)" \
272 || { echo $(AR) $(ARFLAGS) $1 $(call extra_objects_filter,$2); \
273 $(AR) $(ARFLAGS) $1 $(call extra_objects_filter,$2); \
276 msvcrt_dllname_script = echo $1 | awk '\
277 /^c/{ print "crtdll.dll" } \
278 /^m/{ ext = gsub( "^.*d$$", "&" ) ? "d.dll" : ".dll"; \
279 printf "msvcr%s%s", gsub( "^[^1-9]*[0-9]+.*", "&" ) \
280 ? gensub( "^[^1-9]*([0-9]+).*", "\\\\1", 1 ) \
284 # We categorize our import libraries into "standard" (a.k.a. "release")
285 # versions, augmented by corresponding "debug" variants.
287 std_msvcrt := $(addprefix msvcr,t $(msvcrt_versions))
288 all_msvcrt := $(std_msvcrt) $(addsuffix d,$(std_msvcrt))
290 all-mingwrt-libs: $(call active_goals,all,libmsvcrt)
291 all-libmsvcrt install-mingwrt-libs: $(foreach name,$(all_msvcrt),lib$(name).a)
292 all-libcrtdll install-deprecated-mingwrt-libs: libcrtdll.a libcoldname.a
293 all-deprecated-mingwrt all-deprecated-libmsvcrt: all-libcrtdll
295 # For each import library to be built, we derive a tailored exports
296 # definition file, from a common source.
298 .SUFFIXES: .def.in .def
299 vpath %.def.in ${mingwrt_srcdir}/msvcrt-xref
300 $(addsuffix .def,$(all_msvcrt)): %.def: msvcrt.def.in
301 $(CC) -E -P -D__FILENAME__=$@ -D__DLLNAME__=$* \
302 -D__MSVCRT_VERSION__=`$(call msvcrt_version_script,$*)` \
305 # To accommodate the __USE_MINGW_ANSI_STDIO feature, as specified
306 # in _mingw.h and stdio.h, while retaining a mechanism for accessing
307 # the MSVCRT.DLL functions which it replaces, we augment our import
308 # libraries with extra, alternatively named entry points, each of
309 # which implements a vectored jump to the regular entry point for
310 # the DLL implementation of its corresponding replaced function.
312 msvcrt_repl_prefix = __msvcrt
313 msvcrt_repl_funcs = printf fprintf sprintf vprintf vfprintf vsprintf
315 # This is kludgey, but dlltool lacks the selectivity to do the job
316 # well; (its --ext-prefix-alias option, which is what we would like
317 # to use, is rather like a chainsaw in the hands of a neurosurgeon,
318 # when he should have a scalpel). We cannot selectively apply the
319 # prefix, to just the symbols of interest, so we end up by creating
320 # an initial copy of the import library, WITH the prefix applied to
321 # to EVERYTHING, (noting that, when we create this initial copy, we
322 # MUST specify the "--no-delete" option TWICE, to preserve temporary
323 # object files within the build tree); we then set this initial copy
324 # aside, and create a further copy WITHOUT the extra symbols, while
325 # duplicating the temporary object file name prefix retrieved from
326 # the initial copy, using this $(NM) lookup filter...
328 dlltool_temp_prefix = $(NM) $(1) | sed -n -e '/t.o:$$/{s///p;q' -e '}'
330 # ...after which, we apply the following $(NM) lookup filter to the
331 # initial copy of the import library file, to identify the specific
332 # temporary object files, defining the entry points to remap...
334 msvcrt_repl = $(call nmlookup,$1,$(msvcrt_repl_prefix)_,$(msvcrt_repl_funcs))
335 nmlookup = $(NM) $(1) | sed -n \
336 -e '/:$$/h;/^[0-7][0-7]* *T */{s///;H;g;s/\n//' \
337 $(foreach repl,$(3),-e 's/:_$(2)$(repl)$$//p') \
340 # ...and we add just that selection to the final copy of the import
341 # library, before explicitly deleting ALL temporary object files, and
342 # the (extended) initial copy of the import library.
344 vpath %.def ${mingwrt_srcdir}
345 $(foreach name,$(all_msvcrt) crtdll,lib$(name).a): lib%.a: %.def
346 $(DLLTOOL) --as $(AS) -k --input-def $< --no-delete --no-delete \
347 --dllname `$(call msvcrt_dllname_script,$*)` --output-lib $@ \
348 --ext-prefix-alias $(msvcrt_repl_prefix) && mv $@ lib$*-repl.a
349 $(DLLTOOL) --as $(AS) -k --input-def $< --output-lib $@ \
350 --temp-prefix `$(call dlltool_temp_prefix,lib$*-repl.a)` \
351 --dllname `$(DLLTOOL) --identify lib$*-repl.a`
352 $(AR) $(ARFLAGS) $@ `$(call msvcrt_repl,lib$*-repl.a)` \
353 $(filter %.$(OBJEXT),$^)
354 $(RM) lib$*-repl.a `$(call dlltool_temp_prefix,$@)`*
356 # Older versions of Microsoft's runtime libraries used a naming
357 # convention which is more consistent with POSIX, (and with other
358 # free software usage), than they currently employ; we support
359 # this earlier convention by mapping the old names to equivalent
360 # entry points in the current libraries, using libcoldname.a to
361 # map CRTDLL.DLL entries, and variants of libmoldname.a for each
362 # variant of MSVCRT.DLL
364 std_moldname := moldname $(addprefix moldname,$(msvcrt_versions))
365 all_moldname := $(std_moldname) $(addsuffix d,$(std_moldname))
367 all-mingwrt-libs: all-libmoldname
368 all-libmoldname install-mingwrt-libs: $(foreach name,$(all_moldname),lib$(name).a)
369 $(foreach name,coldname $(all_moldname),lib$(name).a): lib%.a: %.def
370 $(DLLTOOL) --as $(AS) -k -U --input-def $< --output-lib $@ \
371 --dllname `$(call msvcrt_dllname_script,$*)`
372 $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
374 # The oldname libraries are also a convenient place to provide a
375 # few additional functions, with no direct implementation in the
376 # Microsoft DLLs, but which nevertheless are easily emulated.
378 $(foreach name,coldname $(all_moldname),lib$(name).a): $(addsuffix .$(OBJEXT), \
379 isascii iscsym iscsymf toascii)
381 # Selected versions of the oldname libraries also provide a
382 # convenient vehicle for delivery of stubs, emulating functions
383 # which appear in later MSVCRT versions, and which we also wish
384 # to support in conjunction with earlier versions.
386 $(foreach name,moldname $(addprefix moldname,70 71),lib$(name).a) \
387 $(foreach name,moldname $(addprefix moldname,70 71),lib$(name)d.a): \
388 strnlen.jmpstub.$(OBJEXT) wcsnlen.jmpstub.$(OBJEXT)
390 coldname.def: %.def: ${mingwrt_srcdir}/moldname.def.in
391 $(CC) -C -E -P -D__FILENAME__=$@ -D__CRTDLL__ -xc-header $< > $@
393 $(addsuffix .def,$(all_moldname)): %.def: ${mingwrt_srcdir}/moldname.def.in
394 $(CC) -C -E -P -D__FILENAME__=$@ -xc-header $< > $@
396 all-mingwrt-libs install-mingwrt-libs: libmingw32.a libmingwex.a
397 libmingw32.a: $(addsuffix .$(OBJEXT), CRTinit CRTglob setargv \
398 CRTfmode cpu_features CRT_fp10 txtmode main dllmain gccmain crtst \
399 tlsmcrt tlsmthread tlssup tlsthrd pseudo-reloc pseudo-reloc-list)
401 libmingw32.a libmingwex.a libm.a libmingwthrd.a libgmon.a:
402 $(AR) $(ARFLAGS) $@ $?
404 # Complex math objects, to be included in libmingwex.a
405 # (FIXME: consider whether these might be more suitably
406 # delivered in libm.a; ISO-C99 says they belong in the
407 # math library, which by POSIX convention, is libm.a)
409 vpath %.c ${mingwrt_srcdir}/mingwex
410 vpath %.c ${mingwrt_srcdir}/mingwex/complex
411 libmingwex.a: $(addsuffix .$(OBJEXT), cabs cabsf cabsl cacos cacosf \
412 cacosh cacoshf cacoshl cacosl casin casinf casinh casinhf casinhl casinl \
413 catan catanf catanh catanhf catanhl catanl ccos ccosf ccosh ccoshf ccoshl \
414 ccosl cexp cexpf cexpl clog clogf clogl cpow cpowf cpowl cproj cprojf \
415 cprojl csin csinf csinh csinhf csinhl csinl csqrt csqrtf csqrtl \
416 ctan ctanf ctanh ctanhf ctanhl ctanl)
418 libmingwex.a: $(addsuffix .$(OBJEXT), isblank iswblank)
420 # Floating point environment control, in libmingwex.a
421 # (FIXME: once again, maybe better delivered in libm.a)
423 libmingwex.a: $(addsuffix .$(OBJEXT), fegetenv fesetenv feupdateenv \
424 feclearexcept feraiseexcept fetestexcept feholdexcept fegetexceptflag \
425 fesetexceptflag fegetround fesetround)
427 # David Gay's "gdtoa" API, provided in libmingwex.a, and used
428 # by MinGW's ISO-C conforming printf() routines for formatting
429 # floating point output.
431 vpath %.c ${mingwrt_srcdir}/mingwex/gdtoa
432 libmingwex.a: $(addsuffix .$(OBJEXT), g__fmt gethex strtopx g_dfmt gdtoa \
433 gmisc smisc sum g_ffmt hd_init strtodg ulp dmisc g_xfmt hexnan strtodnrp \
436 # "inttypes" conversion routines, provided in libmingwex.a
438 libmingwex.a: $(addsuffix .$(OBJEXT), \
439 imaxdiv strtoimax strtoumax wcstoimax wcstoumax)
441 # Additional math functions, augmenting Microsoft's paltry
442 # selection, also delivered in libmingwex.a, (FIXME: and yet
443 # again, perhaps libm.a would be a better fit)
445 vpath %.c ${mingwrt_srcdir}/mingwex/math
446 vpath %.s ${mingwrt_srcdir}/mingwex/math
447 libmingwex.a: $(addsuffix .$(OBJEXT), cosf cosl acosf acosl sinf sinl asinf \
448 asinl tanf tanl atanf atanl atan2f atan2l coshf coshl acosh acoshf acoshl \
449 sinhf sinhl asinh asinhf asinhl tanhf tanhl atanh atanhf atanhl cbrt cbrtf \
450 cbrtl ceilf ceill copysign copysignf copysignl erfl s_erf sf_erf expf expl \
451 exp2 exp2f exp2l expm1 expm1f expm1l fabs fabsf fabsl fdim fdimf fdiml \
452 floorf floorl fma fmaf fmal fmax fmaxf fmaxl fmin fminf fminl fmodf fmodl \
453 fp_consts fp_constsf fp_constsl fpclassify fpclassifyf fpclassifyl frexpf \
454 frexpl fucom hypotf hypotl ilogb ilogbf ilogbl isnan isnanf isnanl ldexpf \
455 ldexpl lgamma lgammaf lgammal llrint llrintf llrintl log10f log10l log1p \
456 log1pf log1pl log2 log2f log2l logb logbf logbl logf logl lrint lrintf \
457 lrintl llround llroundf llroundl lround lroundf lroundl modff modfl \
458 nearbyint nearbyintf nearbyintl nextafterf nextafterl nexttoward nexttowardf \
459 powf powl powi powif powil remainder remainderf remainderl remquo remquof \
460 remquol rint rintf rintl round roundf roundl scalbn scalbnf scalbnl signbit \
461 signbitf signbitl sqrtf sqrtl tgamma tgammaf tgammal trunc truncf truncl \
462 x87cvt x87cvtf x87log x87log1p x87pow)
464 # Replacement I/O functions in libmingwex.a, providing better POSIX
465 # compatibility than their Microsoft equivalents.
467 vpath %.c ${mingwrt_srcdir}/mingwex/stdio
468 libmingwex.a: $(addsuffix .$(OBJEXT), btowc fprintf fseeko64 ofmtctl pformat \
469 printf snprintf sprintf vfprintf vfscanf vfwscanf vprintf vscanf vsnprintf \
470 vsprintf vsscanf vswscanf vwscanf)
472 # pformat.$(OBJEXT) needs an explicit build rule, since we need to
473 # specify an additional header file path.
475 PFORMAT_CFLAGS = -I ${mingwrt_srcdir}/mingwex/gdtoa
476 pformat.$(OBJEXT): %.$(OBJEXT): %.c
477 $(CC) -c $(ALL_CFLAGS) $(PFORMAT_CFLAGS) $< -o $@
479 # To support Microsoft's DLL version specific exponent digits control,
480 # and "%n" format availability control APIs, in a DLL version agnostic
481 # manner, we also provide the following set of wrapper functions:
483 libmingwex.a: $(addsuffix fmt.$(OBJEXT),varo crto geto seto crtn getn setn)
484 $(addsuffix fmt.$(OBJEXT),varo crto geto seto crtn getn setn): %.$(OBJEXT): ofmt.c
485 $(CC) -c $(ALL_CFLAGS) -D__$*__ -fno-align-functions -o $@ $<
487 # Some additional miscellaneous functions, in libmingwex.a
489 libmingwex.a: $(addsuffix .$(OBJEXT), mingw-aligned-malloc mingw-fseek)
490 libmingwex.a: $(addsuffix .$(OBJEXT), glob getopt basename dirname nsleep)
491 libmingwex.a: $(addsuffix .$(OBJEXT), mkstemp mkdtemp cryptnam setenv)
493 libmingwex.a: $(addsuffix .$(OBJEXT), tdelete tfind tsearch twalk)
494 libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn strerror_r)
495 libmingwex.a: $(addsuffix .$(OBJEXT), getdelim gettimeofday)
497 vpath %.s ${mingwrt_srcdir}/mingwex
498 vpath %.sx ${mingwrt_srcdir}/mingwex
499 libmingwex.a: $(addsuffix .$(OBJEXT), fwide mbrtowc mbsinit strnlen wcrtomb \
500 wcsnlen wcstof wcstold wctob wctrans wctype wmemchr wmemcmp wmemcpy wmemmove \
503 # The wcsnlen() function, enumerated above, is an adaptation of strnlen();
504 # we need a specific rule to compile it, from shared source.
506 wcsnlen.$(OBJEXT): strnlen.sx
507 $(COMPILE.sx) -D_UNICODE $^ -o $@
509 # For the math sources, we support the convention that a single
510 # quux_generic.c source file will produce three objects: quux.o,
511 # quuxf.o, and quuxl.o; since a change in the common source file
512 # will require all three objects to be recompiled, we may handle
513 # this with a single, multiple target, pattern rule.
515 $(addsuffix .$(OBJEXT), % %f %l): %_generic.c
516 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $*.$(OBJEXT) $<
517 $(CC) -c -D FUNCTION=$*f $(CPPFLAGS) $(ALL_CFLAGS) -o $*f.$(OBJEXT) $<
518 $(CC) -c -D FUNCTION=$*l $(CPPFLAGS) $(ALL_CFLAGS) -o $*l.$(OBJEXT) $<
520 # The llround.o, llroundf.o, and llroundl.o variants are a special
521 # case of the preceding rule; (the source is lround_generic.c rather
522 # than llround_generic.c). We can handle this using the following
523 # static pattern rule, (compiling each object individually).
525 $(addsuffix .$(OBJEXT), llround llroundf llroundl): %.$(OBJEXT): lround_generic.c
526 $(CC) -c -D FUNCTION=$* $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
528 # Similarly, we may need to compile quux.o, quuxf.o, and quuxl.o
529 # variants from a common quux_generic.sx assembly language file.
531 vpath %.sx ${mingwrt_srcdir}/mingwex/math
532 $(addsuffix .$(OBJEXT), % %f %l): %_generic.sx
533 $(CC) -c -D_$*_source $(ALL_CPPFLAGS) $(ASFLAGS) -o $*.$(OBJEXT) $<
534 $(CC) -c -D_$*f_source $(ALL_CPPFLAGS) $(ASFLAGS) -o $*f.$(OBJEXT) $<
535 $(CC) -c -D_$*l_source $(ALL_CPPFLAGS) $(ASFLAGS) -o $*l.$(OBJEXT) $<
537 # Several generically implemented functions also require separate
538 # assembly of their generic back-end support routines.
540 x87%.$(OBJEXT): %_generic.sx
541 $(CC) -c $(ALL_CPPFLAGS) $(ASFLAGS) -o $@ $<
543 # Historically, MinGW.org's libm.a has been a dummy, delivering
544 # nothing of value; FIXME: IMO, this sucks; it should deliver the
545 # non-MSVCRT.DLL math functions, as noted above.
547 all-mingwrt-libs install-mingwrt-libs: libm.a
548 libm.a: libm_dummy.$(OBJEXT)
549 libm_dummy.c: Makefile
550 echo "static int __mingw_libm_dummy;" > $@
552 # The mingwrt headers define a number of functions which are normally
553 # expected to be compiled as inline code. Each such function must also
554 # be provided with an externally visible entry point; we provide such
555 # entry points as stubs in libmingwex.a, via the following rules:
557 sinclude Makefile.stub
558 libstub_refnames = grep -lr '__$1.*FUNCTION *=' ${mingwrt_srcdir}
559 jmpstub_prerequisites := $(shell $(call libstub_refnames,JMPSTUB)/include)
560 libimpl_prerequisites := $(shell $(call libstub_refnames,LIBIMPL)/include)
561 Makefile.stub: Makefile $(jmpstub_prerequisites) $(libimpl_prerequisites)
562 echo "# $@: automatically generated file -- do not edit!" > $@
563 $(call jmpstub_awk_script,$(jmpstub_prerequisites)) >> $@
564 $(call libimpl_awk_script,$(libimpl_prerequisites)) >> $@
565 echo "# $@: end of file" >> $@
567 # Stubs are categorized into either of JMPSTUB or LIBIMPL classes;
568 # the rules for building the JMPSTUP inplementations are written to
569 # Makefile.stub, by processing each of their defining header files
570 # through the following awk script...
572 jmpstub_awk_script = test -z "$1" || awk '\
574 symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
575 fmt = "\nlib%s.a: %s\n%s: jmpstub.sx\n\t$$(COMPILE.sx) %s -o $$@ $$^\n"; \
577 /__JMPSTUB(__)? *[(].*FUNCTION/ { \
578 FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
579 LIB = match( $$0, ".*[ ,(:]LIB *= *"symbol, altlib ) ? altlib[1] : "mingwex"; \
580 OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".jmpstub.$$(OBJEXT)"; \
581 OBJNAME_CFLAGS = "-D FUNCTION="FUNCTION; \
582 if( match( $$0, ".*[ ,(:]DLLENTRY *= *"symbol, alias ) ) \
583 OBJNAME_CFLAGS = OBJNAME_CFLAGS" -D DLLENTRY="alias[1]; \
584 else if( match( $$0, ".*[ ,(:]REMAPPED *= *"symbol, alias ) ) \
585 OBJNAME_CFLAGS = OBJNAME_CFLAGS" -D REMAPPED="alias[1]; \
586 printf fmt, LIB, OBJNAME, OBJNAME, OBJNAME_CFLAGS; \
592 # ...while this establishes the dependencies which apply for each
593 # of those in the LIBIMPL class.
595 libimpl_awk_script = test -z "$1" || awk '\
597 symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
598 fmt = "\nlib%s.a: %s\n%s.libimpl: %s\n"; \
600 /__LIBIMPL(__)? *[(].*FUNCTION/ { \
601 FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
602 LIB = match( $$0, ".*[ ,(:]LIB *= *"symbol, altlib ) ? altlib[1] : "mingwex"; \
603 OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".libimpl.$$(OBJEXT)"; \
604 printf fmt, LIB, OBJNAME, FUNCTION, FILENAME; \
610 # In contrast to JMPSTUB implementations, which are best handled
611 # by individual compilation rules in Makefile.stub, generic rules
612 # are sufficient for all LIBIMPL implementations; in each case, we
613 # filter the static attribute from each defined implementation, in
614 # its defining header file, to create an intermediate C source for
615 # each individual function; (note that we also remove any pragma
616 # which identifies the originating file as a system header).
618 libimpl_sed_script = sed \
619 -e '/pragma .* system_header/d' \
620 -e '/__CRT_INLINE *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d' \
621 -e 's/__LIBIMPL.*ALIAS *= *$1[ ,)].*)/__attribute__((__alias__("$1")))/' \
622 -e '/__CRT_ALIAS *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d'
624 LIBIMPL_CFLAGS = $(CFLAGS) $(INCLUDES) $(LIBIMPL_EXTRA_CFLAGS)
625 LIBIMPL_EXTRA_CFLAGS = -fno-align-functions -Wno-deprecated-declarations
627 # LIBIMPL dependencies are tracked using zero sized name.libimpl
628 # files; the intermediate C files are generated as a side effect
629 # of resolving these dependencies...
632 $(call libimpl_sed_script,$*) $< > $@.c
635 # ...and ultimately discarded, after the requisite object file
636 # has been compiled; (note that this creates a vulnerability due
637 # to possible loss of the object file, while the tracking file is
638 # still in place; to circumvent this, we must be able to force a
639 # remake of the tracking file, so also regenerating the .c file,
640 # before it is compiled).
642 libimpl_remake = { $(RM) $1; $(MAKE) --no-print-directory $1; }
643 %.libimpl.$(OBJEXT): %.libimpl
644 test -f $<.c || $(call libimpl_remake,$<)
645 $(CC) -c $(CPPFLAGS) $(LIBIMPL_CFLAGS) -o $@ $<.c
648 # Thread support libraries.
650 all-mingwrt-libs install-mingwrt-libs: libmingwthrd.a libmingwthrd_old.a
651 libmingwthrd.a libmingwthrd_old.a: crtmt.$(OBJEXT)
652 mingwthrd_old.def mingwm10.dll: $(addsuffix .$(OBJEXT), mthr mthr_init)
654 $(DLLTOOL) --as $(AS) --output-def $@ $^
656 libmingwthrd_old.a: lib%.a: %.def
657 $(DLLTOOL) --as $(AS) --input-def $< --dllname mingwm10.dll --output-lib $@
658 $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
660 all-mingwrt-dll install-mingwrt-dll-files: mingwm10.dll
661 mingwm10.dll: mingwthrd_old.def
662 $(CC) -shared -o $@ -Wl,--image-base,0x6FBC0000 \
663 -Wl,--entry,_DllMainCRTStartup@12 $^
665 # Code profiling support, using the GNU profiling library; (note
666 # that applications using this library MUST be licensed to comply
667 # with the GNU General Public License).
669 all-mingwrt-libs install-mingwrt-libs: libgmon.a
670 libgmon.a: $(addsuffix .$(OBJEXT), gmon mcount profil)
676 # Users may expect to be able to specify DESTDIR, to stage the
677 # following stock installation directories outside of the regular
678 # "as configured" installation tree; unfortunately, this expectation
679 # MUST fail, when the stock path is in MS-Windows absolute format, so
680 # we provide an exception mechanism to forbid such usage, and we
681 # proceed to create the directories only when the exception is
684 .PHONY: DESTDIR-UNSUPPORTED
685 bindir docdir includedir libdir mandir htmldir pdfdir:
686 @test -z "$(strip ${DESTDIR})" || case $($@) in ${DESTDIR}?:*) \
687 $(MAKE) --no-print-directory reject=$@ DESTDIR-UNSUPPORTED;; \
689 $(call mkinstalldirs,,$($@))
691 # Note: we MUST use a recursive make invocation here, as the
692 # "error" function within the accompanying diagnostics would be
693 # triggered, irrespective of its placement in an unexecuted
694 # branch of the above exception trapping shell code.
697 $(call MSG_DESTDIR_FORBIDDEN,$(reject),$($(reject):${DESTDIR}%=%))
699 # The following macros, which rely heavily on GNU make's "call"
700 # function, define the diagnostics to be emitted, when the DESTDIR
701 # exception is triggered.
704 MSG_DESTDIR_FORBIDDEN = \
705 $(warning *** $(call MSG_DESTDIR_PATH_CONFLICT,$1,Win32,$2);) \
706 $(error try $(call QUOTE,$(call MSG_DESTDIR_ALTERNATIVE,$1,$2)) instead)
707 MSG_DESTDIR_BAD_PATH = DESTDIR is not supported when $1 contains $2 path $3
708 MSG_DESTDIR_PATH_CONFLICT = $(call MSG_DESTDIR_BAD_PATH,$1,$2,$(call QUOTE,$3))
709 MSG_DESTDIR_ALTERNATIVE = make install $1="$(call MSG_DESTDIR_TRANSFORM,$2)"
710 MSG_DESTDIR_TRANSFORM = ${DESTDIR}$(shell echo $1 | sed 's/^.://')
712 # Install everything.
714 install: inst@DEFAULT_MAKECMDGOALS@
715 install-stage-1-only: install-headers install-libdir-objects install-libs
716 install-stage-1-and-2: install-stage-1-only install-bin
717 install-gcc: install-stage-1-only
719 install-strip: install-strip-mingwrt
721 $(MAKE) --no-print-directory \
722 STRIP_DATA='cd ${libdir}; $(STRIP) --strip-unneeded $$1' \
723 STRIP_DLL='cd ${bindir}; $(STRIP) $$1' install-$*
725 # Install licence files.
727 install-license: install-mingwrt-license
728 install-licence install-mingwrt-licence: %-licence: %-license
730 vpath DISCLAIMER ${mingwrt_srcdir}
731 vpath COPYING ${mingwrt_srcdir}/profile
732 vpath CYGWIN_LICENSE ${mingwrt_srcdir}/profile
733 mingwrt-license-files: COPYING CYGWIN_LICENSE DISCLAIMER
735 # FIXME: The following rule is generalized, such that it may accommodate
736 # both mingwrt and w32api, (and other packages); thus, it should ideally
737 # be relocated into a common (shared) Makefile fragment.
739 install-mingwrt-license install-w32api-license: install-%: docdir %-files
741 $(call mkinstalldirs,,${docdir}/$*/$(PACKAGE_VERSION))
742 $(call INSTALL_DATA,$^,${docdir}/$*/$(PACKAGE_VERSION))
744 # Install headers associated with the MinGW runtime libraries.
746 includedirs: mingwrt-includedirs
747 install-headers install-mingwrt: install-mingwrt-headers
749 mingwrt-includedirs: includedir $(eval mingwrt_include_subdirs=sys parts)
750 $(call mkinstalldirs,${includedir}/,$(mingwrt_include_subdirs))
752 SUB_HEADERS_PRESENT = echo $1/include/$2/*.h | grep -v '[*]' > /dev/null
753 INSTALL_SUB_HEADERS = $(call INSTALL_DATA,$1/include/$2/*.h,${includedir}/$2)
755 install-mingwrt-headers: _mingw.h mingwrt-includedirs
756 $(call INSTALL_DATA,_mingw.h,${includedir})
757 $(call INSTALL_DATA,${mingwrt_srcdir}/include/*.h,${includedir})
758 for dir in $(mingwrt_include_subdirs); do \
759 if $(call SUB_HEADERS_PRESENT,${mingwrt_srcdir},$$dir); then \
760 $(call INSTALL_SUB_HEADERS,${mingwrt_srcdir},$$dir); \
763 $(call INSTALL_DATA,${mingwrt_srcdir}/profile/*.h,${includedir})
765 # Install libraries, and supporting free standing object files.
767 install-libs install-mingwrt: install-mingwrt-libdir-libs
768 install-libdir-objects install-mingwrt: install-mingwrt-libdir-objects
770 install-mingwrt-libdir-libs: libdir $(call active_goals,install,mingwrt-libs)
771 install-mingwrt-libdir-objects: libdir $(call active_goals,install,crt-objects)
773 install-crt-objects install-deprecated-crt-objects \
774 install-mingwrt-libs install-deprecated-mingwrt-libs:
775 $(call INSTALL_DATA,$^,${libdir})
776 $(if $(STRIP_DATA),$(call STRIP_DATA,$^))
781 install-mingwrt: install-mingwrt-dll
782 install-bin install-dll: install-mingwrt-dll
783 install-mingwrt-bin install-w32api-bin: install-%-bin: install-%-dll
784 install-mingwrt-dll install-w32api-dll: install-%-dll: bindir install-%-dll-files
786 $(call INSTALL_DATA,$^,${bindir})
787 $(if $(STRIP_DLL),$(call STRIP_DLL,$^))
792 vpath %.man ${mingwrt_srcdir}/man
793 install-man install-manpages: install-mingwrt-manpages
794 mingwrt-man$(man3ext): $(addsuffix .$(man3ext),basename dirname getline getdelim)
795 install-mingwrt-manpages: mandir mingwrt-man3
798 $(call mkinstalldirs,,${man$*dir})
799 $(call INSTALL_DATA,$^,${man$*dir})
803 $(call format_manpage,$(basename $*),$(suffix $*),$<) $< > $@
805 format_manpage = sed \
806 -e "s/%PAGEREF%/`echo $1 | tr a-z A-Z` $(2:.%=%) `date -r $3 +%d-%b-%Y`/"
808 basename.$(man3ext): export reference_manpage = dirname.$(man3ext).man
809 basename.$(man3ext): %: %.mancopy-recursive
811 getdelim.$(man3ext): export reference_manpage = getline.$(man3ext).man
812 getdelim.$(man3ext): %: %.mancopy-recursive
815 $(MAKE) --no-print-directory $*.mancopy
817 %.mancopy: $(reference_manpage)
818 $(call format_manpage,$(basename $*),$(suffix $*),$<) $< > $*
824 uninstall: uninstall-mingwrt
825 uninstall-bin uninstall-dll uninstall-mingwrt: uninstall-mingwrt-dll
826 uninstall-mingwrt: uninstall-mingwrt-headers uninstall-mingwrt-libdir-libs
827 uninstall-mingwrt: uninstall-mingwrt-libdir-objects
829 REMOVE_HEADERS = cd $1 && $(RM) $(notdir $(wildcard $2))
831 uninstall-mingwrt-headers:
832 $(call REMOVE_HEADERS,${includedir},${mingwrt_srcdir}/include/*.h)
833 for dir in $(mingwrt_include_subdirs); do \
834 files=`cd ${mingwrt_srcdir}/include/$$dir && echo *.h`; \
835 (cd ${includedir}/$$dir && $(RM) $$files); \
837 $(call REMOVE_HEADERS,${includedir},${mingwrt_srcdir}/profile/*.h)
839 uninstall-mingwrt-dll \
840 uninstall-mingwrt-libdir-objects uninstall-mingwrt-libdir-libs: un%:
841 $(MAKE) --no-print-directory mkinstalldirs= \
842 INSTALL_DATA='cd $$2 && $(RM) $$1' $*
848 .PHONY: check-recursive
849 check test tests: check-recursive
858 dist: devdist dlldist licdist mandist srcdist
859 $(RM) -r dist/mingwrt dist/w32api
861 mingwrt-dist-staged w32api-dist-staged: %-dist-staged:
863 $(MAKE) --no-print-directory prefix=`pwd`/dist/$* install-strip-$*
865 devdist: mingwrt-devdist
866 mingwrt_devdist_objects = dist/mingwrt/lib/*.$(OBJEXT)
867 mingwrt-devdist w32api-devdist: %-devdist: %-dist-staged
868 cd dist/$* && tar chf - --hard-dereference include lib | \
869 xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dev.tar.xz
871 dlldist: mingwrt-dlldist
872 mingwrt-dlldist: %-dlldist: %-dist-staged
873 cd dist/$* && tar chf - --hard-dereference bin | \
874 xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dll.tar.xz
876 licdist: mingwrt-licdist
877 mingwrt-licdist w32api-licdist: %-licdist:
879 $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-licence
880 cd tmp && tar chf - --hard-dereference * | \
881 xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-lic.tar.xz
884 mandist: mingwrt-mandist
885 mingwrt-mandist: %-mandist:
887 $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-manpages
888 cd tmp && tar chf - --hard-dereference share | \
889 xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-man.tar.xz
892 srcdist: mingwrt-srcdist
893 mingwrt-srcdist: mingwrt-srcdist-dir mingwrt-srcdist-files
894 cd dist && tar chf - $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | \
895 xz -c > $(PACKAGE_TARNAME)-$(PACKAGE_RELEASE_TAG)-src.tar.xz
896 $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
899 $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
900 $(call mkinstalldirs,,dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION))
902 mingwrt-srcdist-files: mingwrt-srcdist-config-files
903 mingwrt-srcdist-files: mingwrt-srcdist-testsuite-files
904 mingwrt-srcdist-files: mingwrt-srcdist-package-files
906 vpath install-sh ${top_srcdir}/.. ${top_srcdir}
907 mingwrt-srcdist-config-files: aclocal.m4 VERSION.m4 install-sh
908 cp -p $^ dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
910 mingwrt-srcdist-package-files:
911 (cd ${mingwrt_srcdir} && tar chf - --hard-dereference $(notdir $^)) | \
912 (cd dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) && tar xf -)
914 mingwrt-srcdist-package-files: $(wildcard ${mingwrt_srcdir}/*.[chs]) \
915 $(addprefix ${mingwrt_srcdir}/,ChangeLog CONTRIBUTORS DISCLAIMER README) \
916 $(wildcard ${mingwrt_srcdir}/*.def.in) $(wildcard ${mingwrt_srcdir}/config*) \
917 $(addprefix ${mingwrt_srcdir}/,include man mingwex msvcrt-xref profile) \
918 $(addprefix ${mingwrt_srcdir}/,TODO Makefile.in crtdll.def) \
919 $(wildcard ${mingwrt_srcdir}/*.txt)
921 mingwrt-srcdist-testsuite-files: $(wildcard ${mingwrt_srcdir}/tests/*.at)
922 mingwrt-srcdist-testsuite-files: $(wildcard ${mingwrt_srcdir}/tests/*.in)
923 (cd ${mingwrt_srcdir} && tar chf - $(addprefix tests/,$(notdir $^))) | \
924 (cd dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) && tar xf -)
926 install-html install-pdf: install-%: %dir mingwrt-man$(man3ext)
927 $(MAKE) --no-print-directory install-$*-files
929 install-html-files install-pdf-files: install-%-files: \
930 $(addsuffix .%,$(wildcard ${man3dir}/*.$(man3ext)))
932 %.$(man3ext).html: %.$(man3ext)
933 man2html $< | sed -e '1,/^<!DOCTYPE/{/^<!/p;d' -e '}' > ${htmldir}/$(notdir $@)
934 chmod 644 ${htmldir}/$(notdir $@)
936 %.$(man3ext).pdf: %.$(man3ext)
937 man -t $< | ps2pdf - > ${pdfdir}/$(notdir $@)
938 chmod 644 ${pdfdir}/$(notdir $@)
940 html-docdist pdf-docdist: %-docdist:
942 $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*
943 $(RM) -r tmp/share/man
944 cd tmp && tar chf - --hard-dereference share | \
945 xz -c > ../dist/mingwrt-doc-$(PACKAGE_RELEASE_TAG)-$*.tar.xz
952 clean-local: mostlyclean-local
953 $(RM) msvcr*.def moldname*.def mingw*.def lib*.a *.dll
956 $(RM) *.d *.$(OBJEXT) Makefile.stub *.libimpl
958 distclean-local: clean-local
959 $(RM) config.log config.status libm_dummy.c
961 maintainer-clean-warning:
962 $(warning $(MAKE) $(@:%-warning=%))
963 $(warning This command should be used by package maintainers only;)
964 $(warning it deletes files which may require special tools to rebuild.)
966 maintainer-clean-local: maintainer-clean-warning distclean-local
967 $(RM) -r ${mingwrt_srcdir}/autom4te.cache
969 clean mostlyclean distclean maintainer-clean: %clean: %clean-local
971 # $RCSfile$: end of file