OSDN Git Service

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