1 # Makefile.am for Cygwin.
3 # This file is part of Cygwin.
5 # This software is a copyrighted work licensed under the terms of the
6 # Cygwin license. Please consult the file "CYGWIN_LICENSE" for
9 # This makefile requires GNU make.
11 AUTOMAKE_OPTIONS=-Wno-override
13 include $(top_srcdir)/Makefile.am.common
15 COMMON_CFLAGS=-Wimplicit-fallthrough=5 -Werror -fmerge-constants -ftracer
17 COMMON_CFLAGS+=-mcmodel=small
20 AM_CFLAGS=$(cflags_common) $(COMMON_CFLAGS)
21 AM_CXXFLAGS=$(cxxflags_common) $(COMMON_CFLAGS) -fno-threadsafe-statics
24 # Needed by mcountFunc.S to choose the right code path and symbol names
28 target_builddir=@target_builddir@
29 newlib_build=$(target_builddir)/newlib
32 # Specialize libdir and includedir to use tooldir prefixed paths (containing
33 # target_alias) as used by newlib, because we overwrite library and header files
34 # installed there by newlib.
37 toollibdir=$(tooldir)/lib
38 toolincludedir=$(tooldir)/include
40 # Parameters used in building the cygwin.dll.
43 NEW_DLL_NAME=new-cygwin1.dll
51 # These objects are included directly into the import library
67 lib/_cygwin_crt0_common.cc \
69 lib/cygwin_attach_dll.c \
79 lib/pseudo-reloc-dummy.c
83 fhandler/clipboard.cc \
85 fhandler/cygdrive.cc \
87 fhandler/dev_disk.cc \
89 fhandler/disk_file.cc \
95 fhandler/netdrive.cc \
96 fhandler/nodevice.cc \
100 fhandler/process.cc \
101 fhandler/process_fd.cc \
102 fhandler/procnet.cc \
103 fhandler/procsys.cc \
104 fhandler/procsysvipc.cc \
107 fhandler/registry.cc \
109 fhandler/signalfd.cc \
111 fhandler/socket_inet.cc \
112 fhandler/socket_local.cc \
113 fhandler/socket_unix.cc \
115 fhandler/termios.cc \
116 fhandler/timerfd.cc \
118 fhandler/virtual.cc \
119 fhandler/windows.cc \
123 libc/arc4random_stir.c \
134 libc/inet_network.c \
135 libc/minires-os-if.c \
164 math/cephes_emath.c \
173 math/cosl_internal.S \
197 math/internal_logl.S \
237 math/sinl_internal.S \
248 mm/malloc_wrapper.cc \
267 tzcode/localtime_wrapper.c
275 create_posix_thread.cc \
309 libstdcxx_wrapper.cc \
364 GMON_TARGET_FILES = \
369 $(GMON_TARGET_FILES) \
397 shared_info_magic.h: scripts/cygmagic local_includes/shared_info.h
398 $(AM_V_GEN)$(srcdir)/scripts/cygmagic $@ "$(CC) $(INCLUDES) $(CPPFLAGS) -E -x c++" $(word 2,$^) SHARED_MAGIC 'class shared_info' USER_MAGIC 'class user_info'
400 child_info_magic.h: scripts/cygmagic local_includes/child_info.h
401 $(AM_V_GEN)$(srcdir)/scripts/cygmagic $@ "$(CC) $(INCLUDES) $(CPPFLAGS) -E -x c++" $(word 2,$^) CHILD_INFO_MAGIC 'class child_info'
403 globals.h: scripts/mkglobals_h globals.cc
406 localtime.patched.c: tzcode/localtime.c tzcode/localtime.c.patch
407 $(AM_V_GEN)patch -u -o localtime.patched.c \
408 $(srcdir)/tzcode/localtime.c \
409 $(srcdir)/tzcode/localtime.c.patch
411 $(srcdir)/devices.cc: scripts/gendevices devices.in local_includes/devices.h
412 $(wordlist 1,2,$^) $@
414 tlsoffsets: scripts/gentls_offsets local_includes/cygtls.h
415 $(AM_V_GEN)CXXCOMPILE="$(CXXCOMPILE)" $^ $@
419 shared_info_magic.h \
423 # Every time we touch a source file, the version info has to be rebuilt
424 # to maintain a correct build date, especially in uname release output
425 dirs = $(srcdir) $(srcdir)/fhandler $(srcdir)/lib $(srcdir)/libc $(srcdir)/math $(srcdir)/mm $(srcdir)/regex $(srcdir)/sec $(srcdir)/tzcode
426 find_src_files = $(wildcard $(dir)/*.[chS]) $(wildcard $(dir)/*.cc)
427 src_files := $(foreach dir,$(dirs),$(find_src_files))
429 # Regenerate uname_version.c only if it doesn't exist or if it differs
430 # from the former uname_version.c
431 uname_version.c: .FORCE
432 $(AM_V_GEN)cd $(srcdir) && \
433 echo "const char *uname_dev_version = \
434 \"$$(git rev-parse --git-dir >/dev/null 2>&1 && \
435 git describe --abbrev=12 --long --match 'cygwin*' --dirty | \
436 sed -e 's/cygwin-//')\";" \
437 > $(abs_builddir)/uname_version-pre.c && \
438 if [ -f $(abs_builddir)/uname_version.c ] && \
439 cmp $(abs_builddir)/uname_version.c \
440 $(abs_builddir)/uname_version-pre.c >/dev/null 2>&1 ; \
442 mv $(abs_builddir)/uname_version-pre.c \
443 $(abs_builddir)/uname_version.c; fi
446 # mkvers.sh creates version.cc in the first place, winver.o always
447 # second, so version.cc is always older than winver.o
448 version.cc: scripts/mkvers.sh include/cygwin/version.h winver.rc $(src_files)
449 @echo "Making version.cc and winver.o";\
451 /bin/sh $(word 1,$^) $(word 2,$^) $(word 3,$^) $(WINDRES) $(CFLAGS)
455 VERSION_OFILES = version.o winver.o
458 # export renames for mkimport
461 NEW_FUNCTIONS=$(addprefix --replace=,\
466 __xdrrec_setnonblock= \
510 xdrrec_endofrecord= \
517 # per-file compilation flags
519 # (these come after, and thus override, the user-supplied CXXFLAGS, as they need
520 # to be able to fiddle with the optimization level)
523 override CFLAGS += $($(*F)_CFLAGS)
524 override CXXFLAGS += $($(*F)_CFLAGS)
525 AM_CXXFLAGS += $(CFLAGS)
527 localtime_wrapper_CFLAGS=-I$(srcdir)/tzcode -fwrapv
529 # required since gcc 9.x
530 exec_CFLAGS=-fno-builtin-execve
532 proc_CFLAGS=-DUSERNAME="\"$(USER)\"" -DHOSTNAME="\"$(HOSTNAME)\"" \
533 -DGCC_VERSION="\"`$(CC) -v 2>&1 | tail -n 1`\""
535 dtable_CFLAGS=-fcheck-new
538 # libraries and installed objects
540 # (Don't ever try to use automake's shared library support via libtool to build
541 # Cygwin. Instead we have explicit rules to build it.)
559 toollib_LIBRARIES = \
564 INSTOBJS=automode.o binmode.o textmode.o textreadmode.o
573 libgmon_a_SOURCES = $(GMON_FILES)
576 # Enable deterministic archives for reproducible builds.
577 ARFLAGS = cr$${SOURCE_DATE_EPOCH:+D}
578 override RANLIB := $(RANLIB)$${SOURCE_DATE_EPOCH:+ -D}
581 cygserver_blddir = ${target_builddir}/winsup/cygserver
582 LIBSERVER = $(cygserver_blddir)/libcygserver.a
585 $(MAKE) -C $(cygserver_blddir) libcygserver.a
587 # We build as new-cygwin1.dll and rename at install time to overcome native
588 # rebuilding issues (we don't want the build tools to see a partially built
589 # cygwin1.dll and attempt to use it instead of the old one).
593 $(LDSCRIPT): $(LDSCRIPT).in
594 $(AM_V_GEN)$(CC) -E - -P < $^ -o $@
597 # Set PE and export table header timestamps to zero for reproducible builds.
598 $(NEW_DLL_NAME): $(LDSCRIPT) libdll.a $(VERSION_OFILES) $(LIBSERVER)\
599 $(newlib_build)/libm.a $(newlib_build)/libc.a
600 $(AM_V_CXXLD)$(CXX) $(CXXFLAGS) \
601 -mno-use-libstdc-wrappers \
602 -Wl,--gc-sections -nostdlib -Wl,-T$(LDSCRIPT) \
603 -Wl,--dynamicbase -static \
604 $${SOURCE_DATE_EPOCH:+-Wl,--no-insert-timestamp} \
605 -Wl,--heap=0 -Wl,--out-implib,cygdll.a -shared -o $@ \
606 -e @DLL_ENTRY@ $(DEF_FILE) \
607 -Wl,-whole-archive libdll.a -Wl,-no-whole-archive \
610 $(newlib_build)/libm.a \
611 $(newlib_build)/libc.a \
612 -lgcc -lkernel32 -lntdll -Wl,-Map,cygwin.map
613 @$(MKDIR_P) ${target_builddir}/winsup/testsuite/testinst/bin/
614 $(AM_V_at)$(INSTALL_PROGRAM) $(NEW_DLL_NAME) ${target_builddir}/winsup/testsuite/testinst/bin/$(DLL_NAME)
616 # cygwin import library
617 toolopts=--cpu=@target_cpu@ --ar=@AR@ --as=@AS@ --nm=@NM@ --objcopy=@OBJCOPY@
619 $(DEF_FILE): scripts/gendef cygwin.din
620 $(AM_V_GEN)$(srcdir)/scripts/gendef --cpu=@target_cpu@ --output-def=$(DEF_FILE) $(srcdir)/cygwin.din
622 sigfe.s: $(DEF_FILE) tlsoffsets
624 { rm -f $(DEF_FILE); $(MAKE) -s -j1 $(DEF_FILE); }; \
625 [ -s $@ ] && touch $@
627 LIBCOS=$(addsuffix .o,$(basename $(LIB_FILES)))
628 $(LIB_NAME): $(DEF_FILE) $(LIBCOS) | $(NEW_DLL_NAME)
629 $(AM_V_GEN)$(srcdir)/scripts/mkimport $(toolopts) $(NEW_FUNCTIONS) $@ cygdll.a $(wordlist 2,99,$^)
632 # import libraries for some subset of symbols indicated by given objects
634 $(srcdir)/scripts/speclib $(toolopts) \
636 --exclude='(?i:dll)' \
638 --exclude='^main$$' \
641 libc.a: $(LIB_NAME) libm.a libpthread.a libutil.a
642 $(AM_V_GEN)$(speclib) $^ -v $(@F)
644 libm.a: $(LIB_NAME) $(newlib_build)/libm.a $(addsuffix .o,$(basename $(MATH_FILES)))
645 $(AM_V_GEN)$(speclib) $^ $(@F)
647 libpthread.a: $(LIB_NAME) thread.o libc/call_once.o libc/cnd.o \
648 libc/mtx.o libc/thrd.o libc/tss.o
649 $(AM_V_GEN)$(speclib) $^ $(@F)
651 libutil.a: $(LIB_NAME) libc/bsdlib.o
652 $(AM_V_GEN)$(speclib) $^ $(@F)
654 libdl.a: $(LIB_NAME) dlfcn.o
655 $(AM_V_GEN)$(speclib) $^ $(@F)
657 libresolv.a: $(LIB_NAME) libc/minires.o
658 $(AM_V_GEN)$(speclib) $^ $(@F)
660 librt.a: $(LIB_NAME) posix_ipc.o
661 $(AM_V_GEN)$(speclib) $^ $(@F)
663 libacl.a: $(LIB_NAME) sec/posixacl.o
664 $(AM_V_GEN)$(speclib) $^ $(@F)
666 libssp.a: $(LIB_NAME) $(wildcard $(newlib_build)/libc/ssp/*.o)
667 $(AM_V_GEN)$(speclib) $^ $(@F)
673 all-local: $(LIB_NAME) $(SUBLIBS)
680 -rm -f $(BUILT_SOURCES)
681 -rm -f $(DEF_FILE) sigfe.s
682 -rm -f cygwin.sc cygdll.a cygwin.map
683 -rm -f $(NEW_DLL_NAME)
684 -rm -f $(LIB_NAME) $(SUBLIBS)
688 maintainer-clean-local:
689 -rm -f $(srcdir)/devices.cc
695 man_MANS = regex/regex.3 regex/regex.7
697 install-exec-hook: install-libs
698 install-data-local: install-headers install-ldif
701 @$(MKDIR_P) $(DESTDIR)$(bindir)
702 $(INSTALL_PROGRAM) $(NEW_DLL_NAME) $(DESTDIR)$(bindir)/$(DLL_NAME)
703 @$(MKDIR_P) $(DESTDIR)$(toollibdir)
704 (cd $(DESTDIR)$(toollibdir) && ln -sf $(LIB_NAME) libg.a)
707 cd $(srcdir)/include; \
708 for sub in `find . -type d -print | sort`; do \
709 $(MKDIR_P) $(DESTDIR)$(toolincludedir)/$$sub; \
710 for i in $$sub/*.h ; do \
711 $(INSTALL_DATA) $$i $(DESTDIR)$(toolincludedir)/$$sub/`basename $$i` ; \
716 @$(MKDIR_P) $(DESTDIR)$(datarootdir)/cygwin
717 $(INSTALL_DATA) $(srcdir)/cygwin.ldif $(DESTDIR)$(datarootdir)/cygwin
723 uninstall-hook: uninstall-headers uninstall-ldif uninstall-libs
726 rm -f $(DESTDIR)$(bindir)/$(DLL_NAME)
727 rm -f $(DESTDIR)$(toollibdir)/libg.a
730 cd $(srcdir)/include; \
731 for sub in `find . -type d -print | sort`; do \
732 for i in $$sub/*.h ; do \
733 rm -f $(DESTDIR)$(toolincludedir)/$$sub/`basename $$i` ; \
738 rm -f $(DESTDIR)$(datarootdir)/cygwin/cygwin.ldif
744 ctags -R --c++-kinds=+p --fields=+iaS --extras=+q \
745 --regex-C++='/EXPORT_ALIAS *\([a-zA-Z0-9_]*, *([a-zA-Z0-9_]*)\)/\1/' \
746 --regex-C++='/__ASMNAME *\("([a-zA-Z0-9_]+)"\)/\1/' \