OSDN Git Service

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