OSDN Git Service

Another CRT_INLINE function implementation rationalization.
[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 # For each import library to be built, we derive a tailored exports
262 # definition file, from a common source.
263 #
264 .SUFFIXES: .def.in .def
265 $(addsuffix .def,$(all_msvcrt)): %.def: ${mingwrt_srcdir}/msvcrt.def.in
266         $(CC) -C -E -P -D__FILENAME__=$@ -D__$*__=1 \
267           -D__MSVCRT_VERSION__=`$(call msvcrt_version_script,$*)` \
268           -xc-header $< > $@
269
270 # To accommodate the __USE_MINGW_ANSI_STDIO feature, as specified
271 # in _mingw.h and stdio.h, while retaining a mechanism for accessing
272 # the MSVCRT.DLL functions which it replaces, we augment our import 
273 # libraries with extra, alternatively named entry points, each of
274 # which implements a vectored jump to the regular entry point for
275 # the DLL implementation of its corresponding replaced function.
276 #
277 msvcrt_repl_prefix = __msvcrt
278 msvcrt_repl_funcs = printf fprintf sprintf vprintf vfprintf vsprintf
279
280 # This is kludgey, but dlltool lacks the selectivity to do the job
281 # well; (its --ext-prefix-alias option, which is what we would like
282 # to use, is rather like a chainsaw in the hands of a neurosurgeon,
283 # when he should have a scalpel).  We cannot selectively apply the
284 # prefix, to just the symbols of interest, so we end up by creating
285 # an initial copy of the import library, WITH the prefix applied to
286 # to EVERYTHING, (noting that, when we create this initial copy, we
287 # MUST specify the "--no-delete" option TWICE, to preserve temporary
288 # object files within the build tree); we then set this initial copy
289 # aside, and create a further copy WITHOUT the extra symbols, while
290 # duplicating the temporary object file name prefix retrieved from
291 # the initial copy, using this $(NM) lookup filter...
292 #
293 dlltool_temp_prefix = $(NM) $(1) | sed -n -e '/t.o:$$/{s///p;q' -e '}'
294
295 # ...after which, we apply the following $(NM) lookup filter to the
296 # initial copy of the import library file, to identify the specific
297 # temporary object files, defining the entry points to remap...
298 #
299 msvcrt_repl = $(call nmlookup,$1,$(msvcrt_repl_prefix)_,$(msvcrt_repl_funcs))
300 nmlookup = $(NM) $(1) | sed -n \
301   -e '/:$$/h;/^[0-7][0-7]*  *T  */{s///;H;g;s/\n//' \
302   $(foreach repl,$(3),-e 's/:_$(2)$(repl)$$//p') \
303   -e '}'
304
305 # ...and we add just that selection to the final copy of the import
306 # library, before explicitly deleting ALL temporary object files, and
307 # the (extended) initial copy of the import library.
308 #
309 vpath %.def ${mingwrt_srcdir}
310 $(foreach name,$(all_msvcrt) crtdll,lib$(name).a): lib%.a: %.def
311         $(DLLTOOL) --as $(AS) -k --input-def $< --no-delete --no-delete \
312           --dllname `$(call msvcrt_dllname_script,$*)` --output-lib $@  \
313           --ext-prefix-alias $(msvcrt_repl_prefix) && mv $@ lib$*-repl.a
314         $(DLLTOOL) --as $(AS) -k --input-def $< --output-lib $@ \
315           --temp-prefix `$(call dlltool_temp_prefix,lib$*-repl.a)` \
316           --dllname `$(DLLTOOL) --identify lib$*-repl.a`
317         $(AR) $(ARFLAGS) $@ `$(call msvcrt_repl,lib$*-repl.a)` \
318           $(filter %.$(OBJEXT),$^)
319         $(RM) lib$*-repl.a `$(call dlltool_temp_prefix,$@)`*
320
321 # Older versions of Microsoft's runtime libraries used a naming
322 # convention which is more consistent with POSIX, (and with other
323 # free software usage), than they currently employ; we support
324 # this earlier convention by mapping the old names to equivalent
325 # entry points in the current libraries, using libcoldname.a to
326 # map CRTDLL.DLL entries, and variants of libmoldname.a for each
327 # variant of MSVCRT.DLL
328 #
329 std_moldname := moldname $(addprefix moldname,$(msvcrt_versions))
330 all_moldname := $(std_moldname) $(addsuffix d,$(std_moldname))
331
332 all-mingwrt-libs: all-libmoldname
333 all-libmoldname install-mingwrt-libs: $(foreach name,$(all_moldname),lib$(name).a)
334 $(foreach name,coldname $(all_moldname),lib$(name).a): lib%.a: %.def
335         $(DLLTOOL) --as $(AS) -k -U --input-def $< --output-lib $@ \
336           --dllname `$(call msvcrt_dllname_script,$*)`
337         $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
338
339 # The oldname libraries are also a convenient place to provide a
340 # few additional functions, with no direct implementation in the
341 # Microsoft DLLs, but which nevertheless are easily emulated.
342 #
343 $(foreach name,coldname $(all_moldname),lib$(name).a): $(addsuffix .$(OBJEXT), \
344   isascii iscsym iscsymf strcasecmp strncasecmp toascii wcscmpi)
345
346 coldname.def: %.def: ${mingwrt_srcdir}/moldname.def.in
347         $(CC) -C -E -P -D__FILENAME__=$@ -D__CRTDLL__ -xc-header $< > $@
348
349 $(addsuffix .def,$(all_moldname)): %.def: ${mingwrt_srcdir}/moldname.def.in
350         $(CC) -C -E -P -D__FILENAME__=$@ -xc-header $< > $@
351
352 all-mingwrt-libs install-mingwrt-libs: libmingw32.a libmingwex.a
353 libmingw32.a: $(addsuffix .$(OBJEXT), CRTinit CRTglob setargv \
354   CRTfmode cpu_features CRT_fp10 txtmode main dllmain gccmain crtst \
355   tlsmcrt tlsmthread tlssup tlsthrd pseudo-reloc pseudo-reloc-list)
356
357 libmingw32.a libmingwex.a libm.a libmingwthrd.a libgmon.a:
358         $(AR) $(ARFLAGS) $@ $?
359
360 # Complex math objects, to be included in libmingwex.a
361 # (FIXME: consider whether these might be more suitably
362 # delivered in libm.a; ISO-C99 says they belong in the
363 # math library, which by POSIX convention, is libm.a)
364 #
365 vpath %.c ${mingwrt_srcdir}/mingwex
366 vpath %.c ${mingwrt_srcdir}/mingwex/complex
367 libmingwex.a: $(addsuffix .$(OBJEXT), cabs cabsf cabsl cacos cacosf \
368   cacosh cacoshf cacoshl cacosl casin casinf casinh casinhf casinhl casinl \
369   catan catanf catanh catanhf catanhl catanl ccos ccosf ccosh ccoshf ccoshl \
370   ccosl cexp cexpf cexpl clog clogf clogl cpow cpowf cpowl cproj cprojf \
371   cprojl csin csinf csinh csinhf csinhl csinl csqrt csqrtf csqrtl \
372   ctan ctanf ctanh ctanhf ctanhl ctanl)
373
374 libmingwex.a: $(addsuffix .$(OBJEXT), isblank iswblank)
375
376 # Floating point environment control, in libmingwex.a
377 # (FIXME: once again, maybe better delivered in libm.a)
378 #
379 libmingwex.a: $(addsuffix .$(OBJEXT), fegetenv fesetenv feupdateenv \
380   feclearexcept feraiseexcept fetestexcept feholdexcept fegetexceptflag \
381   fesetexceptflag fegetround fesetround)
382
383 # David Gay's "gdtoa" API, provided in libmingwex.a, and used
384 # by MinGW's ISO-C conforming printf() routines for formatting
385 # floating point output.
386 #
387 vpath %.c ${mingwrt_srcdir}/mingwex/gdtoa
388 libmingwex.a: $(addsuffix .$(OBJEXT), g__fmt gethex strtopx g_dfmt gdtoa \
389   gmisc smisc sum g_ffmt hd_init strtodg ulp dmisc g_xfmt hexnan strtodnrp \
390   dtoa misc strtof)
391
392 # "inttypes" conversion routines, provided in libmingwex.a
393 #
394 libmingwex.a: $(addsuffix .$(OBJEXT), \
395   imaxdiv strtoimax strtoumax wcstoimax wcstoumax)
396
397 # Additional math functions, augmenting Microsoft's paltry
398 # selection, also delivered in libmingwex.a, (FIXME: and yet
399 # again, perhaps libm.a would be a better fit)
400 #
401 vpath %.c ${mingwrt_srcdir}/mingwex/math
402 vpath %.s ${mingwrt_srcdir}/mingwex/math
403 libmingwex.a: $(addsuffix .$(OBJEXT), cosf cosl acosf acosl sinf sinl asinf \
404   asinl tanf tanl atanf atanl atan2f atan2l coshf coshl acosh acoshf acoshl \
405   sinhf sinhl asinh asinhf asinhl tanhf tanhl atanh atanhf atanhl cbrt cbrtf \
406   cbrtl ceilf ceill copysign copysignf copysignl erfl s_erf sf_erf expf expl \
407   exp2 exp2f exp2l expm1 expm1f expm1l fabs fabsf fabsl fdim fdimf fdiml \
408   floorf floorl fma fmaf fmal fmax fmaxf fmaxl fmin fminf fminl fmodf fmodl \
409   fp_consts fp_constsf fp_constsl fpclassify fpclassifyf fpclassifyl frexpf \
410   frexpl fucom hypotf hypotl ilogb ilogbf ilogbl isnan isnanf isnanl ldexpf \
411   ldexpl lgamma lgammaf lgammal llrint llrintf llrintl log10f log10l log1p \
412   log1pf log1pl log2 log2f log2l logb logbf logbl logf logl lrint lrintf \
413   lrintl llround llroundf llroundl lround lroundf lroundl modff modfl \
414   nearbyint nearbyintf nearbyintl nextafterf nextafterl nexttoward nexttowardf \
415   powf powl powi powif powil remainder remainderf remainderl remquo remquof \
416   remquol rint rintf rintl round roundf roundl scalbn scalbnf scalbnl signbit \
417   signbitf signbitl sqrtf sqrtl tgamma tgammaf tgammal trunc truncf truncl)
418
419 # Replacement I/O functions in libmingwex.a, providing better POSIX
420 # compatibility than their Microsoft equivalents.
421 #
422 vpath %.c ${mingwrt_srcdir}/mingwex/stdio
423 libmingwex.a: $(addsuffix .$(OBJEXT), btowc fprintf fseeko64 lseek64 \
424   pformat printf snprintf snwprintf sprintf vfprintf vfscanf vfwscanf vprintf \
425   vscanf vsnprintf vsnwprintf vsprintf vsscanf vswscanf vwscanf)
426
427 # pformat.$(OBJEXT) needs an explicit build rule, since we need to
428 # specify an additional header file path.
429 #
430 PFORMAT_CFLAGS = -I ${mingwrt_srcdir}/mingwex/gdtoa
431 pformat.$(OBJEXT): %.$(OBJEXT): %.c
432         $(CC) -c $(ALL_CFLAGS) $(PFORMAT_CFLAGS) $< -o $@
433
434 # To support Microsoft's DLL version specific exponent digits control,
435 # and "%n" format availability control APIs, in a DLL version agnostic
436 # manner, we also provide the following set of wrapper functions:
437 #
438 libmingwex.a: $(addsuffix fmt.$(OBJEXT),varo crto geto seto crtn getn setn)
439 $(addsuffix fmt.$(OBJEXT),varo crto geto seto crtn getn setn): %.$(OBJEXT): ofmt.c
440         $(CC) -c $(ALL_CFLAGS) -D__$*__ -fno-align-functions -o $@ $<
441
442 # Some additional miscellaneous functions, in libmingwex.a
443 #
444 #libmingwex.a: $(addsuffix .$(OBJEXT), glob membarrier)
445 libmingwex.a: $(addsuffix .$(OBJEXT), mingw-aligned-malloc mingw-fseek glob)
446 libmingwex.a: $(addsuffix .$(OBJEXT), getopt basename dirname ftruncate usleep)
447 libmingwex.a: $(addsuffix .$(OBJEXT), mkstemp mkdtemp cryptnam)
448
449 libmingwex.a: $(addsuffix .$(OBJEXT), tdelete tfind tsearch twalk)
450
451 libmingwex.a: gettimeofday.$(OBJEXT)
452 libmingwex.a: $(addsuffix .$(OBJEXT), dirent wdirent dlfcn)
453
454 libmingwex.a: $(addsuffix .$(OBJEXT), fwide mbrtowc mbsinit wcrtomb wcstof \
455   wcstold wctob wmemchr wmemcmp wmemcpy wmemmove wmemset)
456
457 libmingwex.a: $(addsuffix .$(OBJEXT), wctrans wctype)
458
459 # For the math sources, we support the convention that a single
460 # quux_generic.c source file will produce three objects: quux.o,
461 # quuxf.o, and quuxl.o; since a change in the common source file
462 # will require all three objects to be recompiled, we may handle
463 # this with a single, multiple target, pattern rule.
464 #
465 $(addsuffix .$(OBJEXT), % %f %l): %_generic.c
466         $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $*.$(OBJEXT) $<
467         $(CC) -c -D FUNCTION=$*f $(CPPFLAGS) $(ALL_CFLAGS) -o $*f.$(OBJEXT) $<
468         $(CC) -c -D FUNCTION=$*l $(CPPFLAGS) $(ALL_CFLAGS) -o $*l.$(OBJEXT) $<
469
470 # The llround.o, llroundf.o, and llroundl.o variants are a special
471 # case of the preceding rule; (the source is lround_generic.c rather
472 # than llround_generic.c).  We can handle this using the following
473 # static pattern rule, (compiling each object individually).
474 #
475 $(addsuffix .$(OBJEXT), llround llroundf llroundl): %.$(OBJEXT): lround_generic.c
476         $(CC) -c -D FUNCTION=$* $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
477
478 # Historically, MinGW.org's libm.a has been a dummy, delivering
479 # nothing of value; FIXME: IMO, this sucks; it should deliver the
480 # non-MSVCRT.DLL math functions, as noted above.
481 #
482 all-mingwrt-libs install-mingwrt-libs: libm.a
483 libm.a: libm_dummy.$(OBJEXT)
484 libm_dummy.c: Makefile
485         echo "static int __mingw_libm_dummy;" > $@
486
487 # The mingwrt headers define a number of functions which are normally
488 # expected to be compiled as inline code.  Each such function must also
489 # be provided with an externally visible entry point; we provide such
490 # entry points as stubs in libmingwex.a, via the following rules:
491 #
492 sinclude Makefile.stub
493 vpath jmpstub.sx ${mingwrt_srcdir}/mingwex
494 libstub_refnames = grep -lr '__$1.*FUNCTION *=' ${mingwrt_srcdir}
495 jmpstub_prerequisites := $(shell $(call libstub_refnames,JMPSTUB)/include)
496 libimpl_prerequisites := $(shell $(call libstub_refnames,LIBIMPL)/include)
497 Makefile.stub: Makefile $(jmpstub_prerequisites) $(libimpl_prerequisites)
498         echo "# $@: automatically generated file -- do not edit!" > $@
499         $(call jmpstub_awk_script,$(jmpstub_prerequisites)) >> $@
500         $(call libimpl_awk_script,$(libimpl_prerequisites)) >> $@
501         echo "# $@: end of file" >> $@
502
503 # Stubs are categorized into either of JMPSTUB or LIBIMPL classes;
504 # the rules for building the JMPSTUP inplementations are written to
505 # Makefile.stub, by processing each of their defining header files
506 # through the following awk script...
507 #
508 jmpstub_awk_script = test -z "$1" || awk '\
509   BEGIN { \
510     symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
511     fmt = "\nlib%s.a: %s\n%s: jmpstub.sx\n\t$$(COMPILE.sx) %s -o $$@ $$^\n"; \
512   } \
513   /__JMPSTUB(__)? *[(].*FUNCTION/ { \
514     LIB = "mingwex"; \
515     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
516     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".jmpstub.$$(OBJEXT)"; \
517     OBJNAME_CFLAGS = "-D FUNCTION="FUNCTION; \
518     if( match( $$0, ".*[ ,(:]REMAPPED *= *"symbol, alias ) ) \
519       OBJNAME_CFLAGS = OBJNAME_CFLAGS" -D REMAPPED="alias[1]; \
520     printf fmt, LIB, OBJNAME, OBJNAME, OBJNAME_CFLAGS; \
521   } \
522   END { \
523     printf "\n"; \
524   }' $1
525
526 # ...while this establishes the dependencies which apply for each
527 # of those in the LIBIMPL class.
528 #
529 libimpl_awk_script = test -z "$1" || awk '\
530   BEGIN { \
531     symbol = "([A-Z_a-z][A-Z_a-z0-9]*)"; \
532     fmt = "\nlib%s.a: %s\n%s.libimpl: %s\n"; \
533   } \
534   /__LIBIMPL(__)? *[(].*FUNCTION/ { \
535     LIB = "mingwex"; \
536     FUNCTION = gensub( ".*[ ,(:]FUNCTION *= *"symbol".*", "\\1", 1 ); \
537     OBJNAME = gensub( "_*(.*)_*", "\\1", 1, FUNCTION )".libimpl.$$(OBJEXT)"; \
538     printf fmt, LIB, OBJNAME, FUNCTION, FILENAME; \
539   } \
540   END { \
541     printf "\n"; \
542   }' $1
543
544 # In contrast to JMPSTUB implementations, which are best handled
545 # by individual compilation rules in Makefile.stub, generic rules
546 # are sufficient for all LIBIMPL implementations; in each case, we
547 # filter the static attribute from each defined implementation, in
548 # its defining header file, to create an intermediate C source for
549 # each individual function; (note that we also remove any pragma
550 # which identifies the originating file as a system header).
551 #
552 libimpl_sed_script = sed \
553   -e '/pragma .* system_header/d' \
554   -e '/__CRT_INLINE  *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d' \
555   -e 's/__LIBIMPL.*ALIAS *= *$1[ ,)].*)/__attribute__((__alias__("$1")))/' \
556   -e '/__CRT_ALIAS  *__LIBIMPL.*FUNCTION *= *$1[ ,)].*)/d'
557
558 LIBIMPL_CFLAGS = $(CFLAGS) $(INCLUDES) -fno-align-functions
559
560 # LIBIMPL dependencies are tracked using zero sized name.libimpl
561 # files; the intermediate C files are generated as a side effect
562 # of resolving these dependencies...
563 #
564 %.libimpl:
565         $(call libimpl_sed_script,$*) $< > $@.c
566         > $@
567
568 # ...and ultimately discarded, after the requisite object file
569 # has been compiled; (note that this creates a vulnerability due
570 # to possible loss of the object file, while the tracking file is
571 # still in place; to circumvent this, we must be able to force a
572 # remake of the tracking file, so also regenerating the .c file,
573 # before it is compiled).
574 #
575 libimpl_remake = { $(RM) $1; $(MAKE) --no-print-directory $1; }
576 %.libimpl.$(OBJEXT): %.libimpl
577         test -f $<.c || $(call libimpl_remake,$<)
578         $(CC) -c $(CPPFLAGS) $(LIBIMPL_CFLAGS) -o $@ $<.c
579         $(RM) $<.c
580
581 # Thread support libraries.
582 #
583 all-mingwrt-libs install-mingwrt-libs: libmingwthrd.a libmingwthrd_old.a
584 libmingwthrd.a libmingwthrd_old.a: crtmt.$(OBJEXT)
585 mingwthrd_old.def mingwm10.dll: $(addsuffix .$(OBJEXT), mthr mthr_init)
586 mingwthrd_old.def:
587         $(DLLTOOL) --as $(AS) --output-def $@ $^
588
589 libmingwthrd_old.a: lib%.a: %.def
590         $(DLLTOOL) --as $(AS) --input-def $< --dllname mingwm10.dll --output-lib $@
591         $(AR) $(ARFLAGS) $@ $(call extra_objects_filter,$^)
592
593 all-mingwrt-dll install-mingwrt-dll-files: mingwm10.dll
594 mingwm10.dll: mingwthrd_old.def
595         $(CC) -shared -o $@ -Wl,--image-base,0x6FBC0000 \
596           -Wl,--entry,_DllMainCRTStartup@12 $^
597
598 # Code profiling support, using the GNU profiling library; (note
599 # that applications using this library MUST be licensed to comply
600 # with the GNU General Public License).
601 #
602 all-mingwrt-libs install-mingwrt-libs: libgmon.a
603 libgmon.a: $(addsuffix .$(OBJEXT), gmon mcount profil)
604
605
606 # Installation Rules
607 # ------------------
608 #
609 # Users may expect to be able to specify DESTDIR, to stage the
610 # following stock installation directories outside of the regular
611 # "as configured" installation tree; unfortunately, this expectation
612 # MUST fail, when the stock path is in MS-Windows absolute format, so
613 # we provide an exception mechanism to forbid such usage, and we
614 # proceed to create the directories only when the exception is
615 # NOT triggered.
616 #
617 .PHONY: DESTDIR-UNSUPPORTED
618 bindir docdir includedir libdir mandir htmldir pdfdir:
619         @test -z "$(strip ${DESTDIR})" || case $($@) in ${DESTDIR}?:*) \
620           $(MAKE) --no-print-directory reject=$@ DESTDIR-UNSUPPORTED;; \
621           esac
622         $(mkinstalldirs) $($@)
623
624 # Note: we MUST use a recursive make invocation here, as the
625 # "error" function within the accompanying diagnostics would be
626 # triggered, irrespective of its placement in an unexecuted
627 # branch of the above exception trapping shell code.
628 #
629 DESTDIR-UNSUPPORTED:
630         $(call MSG_DESTDIR_FORBIDDEN,$(reject),$($(reject):${DESTDIR}%=%))
631
632 # The following macros, which rely heavily on GNU make's "call"
633 # function, define the diagnostics to be emitted, when the DESTDIR
634 # exception is triggered.
635 #
636 QUOTE = `$1'#'`
637 MSG_DESTDIR_FORBIDDEN = \
638   $(warning *** $(call MSG_DESTDIR_PATH_CONFLICT,$1,Win32,$2);) \
639   $(error try $(call QUOTE,$(call MSG_DESTDIR_ALTERNATIVE,$1,$2)) instead)
640 MSG_DESTDIR_BAD_PATH = DESTDIR is not supported when $1 contains $2 path $3
641 MSG_DESTDIR_PATH_CONFLICT = $(call MSG_DESTDIR_BAD_PATH,$1,$2,$(call QUOTE,$3))
642 MSG_DESTDIR_ALTERNATIVE = make install $1="$(call MSG_DESTDIR_TRANSFORM,$2)"
643 MSG_DESTDIR_TRANSFORM = ${DESTDIR}$(shell echo $1 | sed 's/^.://')
644
645 # Install everything.
646 #
647 install: install-mingwrt
648 install-stage-1-only: install-headers install-libdir-objects install-libs
649 install-stage-1-and-2: install-stage-1-only install-bin
650 install-gcc: install-stage-1-only
651
652 # Install licence files.
653 #
654 install-license: install-mingwrt-license
655 install-licence install-mingwrt-licence: %-licence: %-license
656
657 vpath DISCLAIMER ${mingwrt_srcdir}
658 vpath COPYING ${mingwrt_srcdir}/profile
659 vpath CYGWIN_LICENSE ${mingwrt_srcdir}/profile
660 mingwrt-license-files: COPYING CYGWIN_LICENSE DISCLAIMER
661
662 # FIXME: The following rule is generalized, such that it may accommodate
663 # both mingwrt and w32api, (and other packages); thus, it should ideally
664 # be relocated into a common (shared) Makefile fragment.
665 #
666 install-mingwrt-license install-w32api-license: install-%: docdir %-files
667 %-license-files:
668         $(mkinstalldirs) ${docdir}/$*/$(PACKAGE_VERSION)
669         $(INSTALL_DATA) $^ ${docdir}/$*/$(PACKAGE_VERSION)
670
671 # Install headers associated with the MinGW runtime libraries.
672 #
673 includedirs: mingwrt-includedirs
674 install-headers install-mingwrt: install-mingwrt-headers
675
676 ${includedir}/sys: includedir
677 mingwrt-includedirs: ${includedir}/sys
678         $(mkinstalldirs) $^
679
680 install-mingwrt-headers: mingwrt-includedirs
681         $(INSTALL_DATA) ${mingwrt_srcdir}/include/*.h ${includedir}
682         $(INSTALL_DATA) ${mingwrt_srcdir}/include/sys/*.h ${includedir}/sys
683         $(INSTALL_DATA) ${mingwrt_srcdir}/profile/*.h ${includedir}
684
685 # Install libraries, and supporting free standing object files.
686 #
687 install-libs install-mingwrt: install-mingwrt-libdir-libs
688 install-libdir-objects install-mingwrt: install-mingwrt-libdir-objects
689
690 install-mingwrt-libdir-libs: libdir $(call active_goals,install,mingwrt-libs)
691 install-mingwrt-libdir-objects: libdir $(call active_goals,install,crt-objects)
692
693 install-crt-objects install-deprecated-crt-objects \
694 install-mingwrt-libs install-deprecated-mingwrt-libs:
695         $(INSTALL_DATA) $^ ${libdir}
696
697 # Install DLLs.
698 #
699 install-mingwrt: install-mingwrt-dll
700 install-bin install-dll: install-mingwrt-dll 
701 install-mingwrt-bin install-w32api-bin: install-%-bin: install-%-dll
702 install-mingwrt-dll install-w32api-dll: install-%-dll: bindir install-%-dll-files
703 install-%-dll-files:
704         $(INSTALL_DATA) $^ ${bindir}
705
706 # Install manpages.
707 #
708 install-man install-manpages: install-mingwrt-manpages
709 format_manpage = sed "s/%PAGEREF%/`echo $1 | tr a-z A-Z` $2/"
710
711 vpath %.man ${mingwrt_srcdir}/man
712 basename.$(man3ext) dirname.$(man3ext): %.$(man3ext): dirname.man
713         $(call format_manpage,$*,$(man3ext)) $< > $@
714
715 mingwrt-man$(man3ext): basename.$(man3ext) dirname.$(man3ext)
716
717 install-mingwrt-manpages: mandir mingwrt-man3
718 mingwrt-man%:
719         $(mkinstalldirs) ${man$*dir}
720         $(INSTALL_DATA) $^ ${man$*dir}
721         $(RM) $^
722
723
724 # Distribution
725 # ------------
726 #
727 .PHONY: dist
728 dist: devdist dlldist licdist mandist srcdist
729         $(RM) -r dist/mingwrt dist/w32api
730
731 mingwrt-dist-staged w32api-dist-staged: %-dist-staged:
732         $(RM) -r dist/$*
733         $(MAKE) --no-print-directory prefix=`pwd`/dist/$* install-$*
734
735 devdist: mingwrt-devdist
736 mingwrt_devdist_objects = dist/mingwrt/lib/*.$(OBJEXT)
737 mingwrt-devdist w32api-devdist: %-devdist: %-dist-staged
738         $(STRIP) -g $($*_devdist_objects) dist/$*/lib/*.a
739         cd dist/$* && tar chf - --hard-dereference include lib | \
740           xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dev.tar.xz
741
742 dlldist: mingwrt-dlldist
743 mingwrt-dlldist: %-dlldist: %-dist-staged
744         $(STRIP) dist/$*/bin/*.dll
745         cd dist/$* && tar chf - --hard-dereference bin | \
746           xz -c > ../$*-$(PACKAGE_RELEASE_TAG)-dll.tar.xz
747
748 licdist: mingwrt-licdist
749 mingwrt-licdist w32api-licdist: %-licdist:
750         $(RM) -r tmp
751         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-licence
752         cd tmp && tar chf - --hard-dereference * | \
753           xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-lic.tar.xz
754         $(RM) -r tmp
755
756 mandist: mingwrt-mandist
757 mingwrt-mandist: %-mandist:
758         $(RM) -r tmp
759         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*-manpages
760         cd tmp && tar chf - --hard-dereference share | \
761           xz -c > ../dist/$*-$(PACKAGE_RELEASE_TAG)-man.tar.xz
762         $(RM) -r tmp
763
764 srcdist: mingwrt-srcdist
765 mingwrt-srcdist: mingwrt-srcdist-dir mingwrt-srcdist-files
766         cd dist && tar chf - $(PACKAGE_TARNAME)-$(PACKAGE_VERSION) | \
767           xz -c > $(PACKAGE_TARNAME)-$(PACKAGE_RELEASE_TAG)-src.tar.xz
768         $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
769
770 mingwrt-srcdist-dir:
771         $(RM) -r dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
772         $(mkinstalldirs) dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION)
773
774 mingwrt-srcdist-files:
775         (cd ${mingwrt_srcdir} && tar chf - --hard-dereference $(notdir $^)) | \
776           (cd dist/$(PACKAGE_TARNAME)-$(PACKAGE_VERSION) && tar xf -)
777
778 mingwrt-srcdist-files: $(wildcard ${mingwrt_srcdir}/*.[chs]) \
779   $(addprefix ${mingwrt_srcdir}/,ChangeLog CONTRIBUTORS DISCLAIMER README) \
780   $(wildcard ${mingwrt_srcdir}/*.def.in) $(wildcard ${mingwrt_srcdir}/config*) \
781   $(addprefix ${mingwrt_srcdir}/,aclocal.m4 install-sh Makefile.in TODO) \
782   $(addprefix ${mingwrt_srcdir}/,include man mingwex profile) \
783   $(addprefix ${mingwrt_srcdir}/,crtdll.def) \
784   $(wildcard ${mingwrt_srcdir}/*.txt)
785
786 install-html install-pdf: install-%: %dir mingwrt-man$(man3ext)
787         $(MAKE) --no-print-directory install-$*-files
788
789 install-html-files install-pdf-files: install-%-files: \
790   $(addsuffix .%,$(wildcard ${man3dir}/*.$(man3ext)))
791
792 %.$(man3ext).html: %.$(man3ext)
793         man2html $< | sed -e '1,/^<!DOCTYPE/{/^<!/p;d' -e '}' > ${htmldir}/$(notdir $@)
794         chmod 644 ${htmldir}/$(notdir $@)
795
796 %.$(man3ext).pdf: %.$(man3ext)
797         man -t $< | ps2pdf - > ${pdfdir}/$(notdir $@)
798         chmod 644 ${pdfdir}/$(notdir $@)
799
800 html-docdist pdf-docdist: %-docdist:
801         $(RM) -r tmp
802         $(MAKE) --no-print-directory prefix=`pwd`/tmp install-$*
803         $(RM) -r tmp/share/man
804         cd tmp && tar chf - --hard-dereference share | \
805           xz -c > ../dist/mingwrt-doc-$(PACKAGE_RELEASE_TAG)-$*.tar.xz
806         $(RM) -r tmp
807
808
809 # Clean-up Rules
810 # --------------
811 #
812 clean-local: mostlyclean-local
813         $(RM) msvcr*.def moldname*.def mingw*.def lib*.a *.dll
814
815 mostlyclean-local:
816         $(RM) *.d *.$(OBJEXT) Makefile.stub *.libimpl
817
818 distclean-local: clean-local
819         $(RM) config.log config.status libm_dummy.c
820
821 maintainer-clean-warning:
822         $(warning $(MAKE) $(@:%-warning=%))
823         $(warning This command should be used by package maintainers only;)
824         $(warning it deletes files which may require special tools to rebuild.)
825
826 maintainer-clean-local: maintainer-clean-warning distclean-local
827         $(RM) -r ${mingwrt_srcdir}/autom4te.cache
828
829 clean mostlyclean distclean maintainer-clean: %clean: %clean-local
830
831 # $RCSfile$: end of file