This is the mail archive of the cygwin-patches mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch]: Decouple cygwin building from in-tree mingw/w32api building


Hello everybody,

This patch modifies the bits of build-process so that cygwin and mingw
building is decoupled from each other.
Additionally the patch decouples cygwin's build from the w32api of mingw.org.
By this change it is now possible to build cygwin (and utilities) with
mingw.org's and mingw-w64's psdk and compilers.  Later are necessary
to build cygwin's native utils, which have not to depend on
cygwin1.dll.
These changes are also necessary for having 64-bit build support in
future. By this reason the mingw-script in utils/ had to learn about
the host's architecture and about how to search for an installed
mingw-toolchain for given architecture.  As Corinna told me that
cygwin wants to use in question the -w64- mingw-environment, this
script is searching first for -w64- based toolchain.  On second
attempt it searches for any mingw triplet for given architecture.


ChangeLog winsup/

2012-10-17  Kai Tietz

	* Makefile.common: Remove w32api specific internal
	configure.
	(nostdincxx): Always turn off default libraries.
	* Makefile.in: Remove for cygwin build dependencies
	to w32api and mingw.
	* configure.in: Make test for w32api directory optional.

ChangeLog lsaauth/

2012-10-17  Kai Tietz

	* Makefile.in (WIN32_INCLUDES): Remove use of
	w32api_include and w32api_include.

ChangeLog utils/

2012-10-17  Kai Tietz

	* Makefile.in (HOST_CPU): New variable.
	(MINGW_CXX): Inster HOST_CPU argument on call of the mingw script.
	(ALL_LDFLAGS, ALL_DEP_LDLIBS): Remove w32api dependencies.
	(MINGW_BINS): Change dependency from MINGW_DEP_LDLIBS to ALL_DEP_LDLIBS.
	(MINGW_LIB): Removed.
	* configure.in (HOST_CPU): Set Makefile.in's HOST_CPU variable.
	* mingw: Extend script to handle architecture dependent cross-compiler
	  setup.

Tested for i686-pc-cygwin build.  Ok for apply?

Regards,
Kai


Index: winsup/Makefile.common
===================================================================
RCS file: /cvs/src/src/winsup/Makefile.common,v
retrieving revision 1.59
diff -p -u -3 -r1.59 Makefile.common
--- winsup/Makefile.common	30 Jul 2012 04:43:21 -0000	1.59
+++ winsup/Makefile.common	17 Oct 2012 15:21:32 -0000
@@ -72,38 +72,22 @@ ifeq (,${findstring $(cygwin_source)/inc
 cygwin_include:=-I$(cygwin_source)/include
 endif

-# Try to determine what directories are available in winsup.
-# Attempt to properly detect missing mingw or w32api and adjust command
-# line parameters appropriately
-
-# nostdinc:=${shell [ -d "$(updir)/w32api" ] && echo "-nostdinc"}
-# ifneq (,$(nostdinc))
 nostdincxx:=-nostdinc++
-# ifeq (,${findstring $(w32api_source),$(CFLAGS) $(CXXFLAGS) $(CXX) $(CC)})
-w32api_include:=-I$(w32api_source)/include
-# endif
-# endif

-mingw_include:=${shell [ -d "$(mingw_source)/include" ] && echo
"-I$(mingw_source)/include"}
-ifneq (,$(mingw_include))
 nostdlib:=-nostdlib
-else
-nostdlib:=
-endif

 ifeq (,${nostdlib})
 nostdinc:=
 endif

-INCLUDES:=-I. $(cygwin_include) -I$(cygwin_source) $(newlib_include)
$(w32api_include)
+INCLUDES:=-I. $(cygwin_include) -I$(cygwin_source) $(newlib_include)
 ifdef CONFIG_DIR
 INCLUDES+=-I$(CONFIG_DIR)
 endif

-MINGW_INCLUDES:=${mingw_include} $(w32api_include)
-MINGW_CFLAGS:=-mno-cygwin $(MINGW_INCLUDES)
-MINGW_CXXFLAGS:=${filter-out $(newlib_source)/%,$(CXXFLAGS)}
-mno-cygwin $(MINGW_INCLUDES)
-MINGW_LDFLAGS:=-L${mingw_build} -L${mingw_build}/mingwex
+MINGW_LDFLAGS:=
+MINGW_CFLAGS:=
+MINGW_CXXFLAGS:=${filter-out $(newlib_source)/%,$(CXXFLAGS)}

 GCC_DEFAULT_OPTIONS:=$(CFLAGS_COMMON) $(CFLAGS_CONFIG) $(INCLUDES)

@@ -134,7 +118,7 @@ COMPILE_CXX=$(CXX) $c $(if $($(*F)_STDIN
 	     $(ALL_CXXFLAGS) $(GCC_INCLUDE) -fno-rtti -fno-exceptions
 COMPILE_CC=$(CC) $c $(if $($(*F)_STDINCFLAGS),,$(nostdinc))
$(ALL_CFLAGS) $(GCC_INCLUDE)

-vpath %.a	$(cygwin_build):$(w32api_lib):$(newlib_build)/libc:$(newlib_build)/libm
+vpath %.a	$(cygwin_build):$(newlib_build)/libc:$(newlib_build)/libm

 MAKEOVERRIDES_WORKAROUND=${wordlist 2,1,a b c}

Index: winsup/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/Makefile.in,v
retrieving revision 1.33
diff -p -u -3 -r1.33 Makefile.in
--- winsup/Makefile.in	24 Feb 2009 02:11:13 -0000	1.33
+++ winsup/Makefile.in	17 Oct 2012 15:21:32 -0000
@@ -121,20 +121,20 @@ check: cygwin
 	fi; \
 	$(MAKE) check

-utils: cygwin mingw
+utils: cygwin

 mingw: w32api

-cygwin: w32api
+cygwin:

 cygserver: cygwin

-install_utils: cygwin mingw
+install_utils: cygwin

 install_mingw: w32api

-install_cygwin: w32api
+install_cygwin:

 install_cygserver: cygwin

-lsaauth: mingw cygwin
+lsaauth: cygwin
Index: winsup/configure.in
===================================================================
RCS file: /cvs/src/src/winsup/configure.in,v
retrieving revision 1.33
diff -p -u -3 -r1.33 configure.in
--- winsup/configure.in	29 Jan 2011 06:41:28 -0000	1.33
+++ winsup/configure.in	17 Oct 2012 15:21:32 -0000
@@ -45,7 +45,10 @@ esac
 if test -d $srcdir/mingw; then
   AC_CONFIG_SUBDIRS(mingw)
 fi
-AC_CONFIG_SUBDIRS(w32api cygserver)
+if test -d $srcdir/w32api; then
+  AC_CONFIG_SUBDIRS(w32api)
+fi
+AC_CONFIG_SUBDIRS(cygserver)

 case "$with_cross_host" in
   ""|*cygwin*)
Index: winsup/lsaauth/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/lsaauth/Makefile.in,v
retrieving revision 1.6
diff -p -u -3 -r1.6 Makefile.in
--- winsup/lsaauth/Makefile.in	29 May 2012 12:46:01 -0000	1.6
+++ winsup/lsaauth/Makefile.in	17 Oct 2012 15:21:33 -0000
@@ -33,7 +33,7 @@ CFLAGS          := @CFLAGS@

 include $(srcdir)/../Makefile.common

-WIN32_INCLUDES  := -I. -I$(srcdir) $(w32api_include) $(w32api_include)/ddk
+WIN32_INCLUDES  := -I. -I$(srcdir)
 WIN32_CFLAGS    := $(CFLAGS) $(WIN32_COMMON) $(WIN32_INCLUDES)
 WIN32_LDFLAGS	:= $(CFLAGS) $(WIN32_COMMON) -nostdlib -Wl,-shared

Index: winsup/utils/Makefile.in
===================================================================
RCS file: /cvs/src/src/winsup/utils/Makefile.in,v
retrieving revision 1.100
diff -p -u -3 -r1.100 Makefile.in
--- winsup/utils/Makefile.in	11 Jul 2012 16:41:51 -0000	1.100
+++ winsup/utils/Makefile.in	17 Oct 2012 15:21:33 -0000
@@ -28,6 +28,7 @@ EXEEXT_FOR_BUILD:=@EXEEXT_FOR_BUILD@
 CC:=@CC@
 CC_FOR_TARGET:=$(CC)
 CXX:=@CXX@
+HOST_CPU=@HOST_CPU@
 CXX_FOR_TARGET:=$(CXX)

 CFLAGS:=@CFLAGS@
@@ -40,15 +41,11 @@ include $(srcdir)/../Makefile.common
 .NOEXPORT:
 .PHONY: all install clean realclean warn_dumper warn_cygcheck_zlib

-ALL_LDLIBS     := -lnetapi32 -ladvapi32
-ALL_LDFLAGS    := -static-libgcc -Wl,--enable-auto-import
-B$(newlib_build)/libc -B$(w32api_lib) $(LDFLAGS) $(ALL_LDLIBS)
-ALL_DEP_LDLIBS := $(cygwin_build)/libcygwin.a ${patsubst -l%,\
-                    $(w32api_lib)/lib%.a,$(ALL_LDLIBS) -lkernel32 -luser32}
-
-MINGW_LIB        := $(mingw_build)/libmingw32.a
-MINGW_LDLIBS     := $(ALL_LDLIBS) $(MINGW_LIB)
-MINGW_DEP_LDLIBS := $(ALL_DEP_LDLIBS) $(MINGW_LIB)
-MINGW_CXX        := ${srcdir}/mingw ${CXX} -I${updir}
+ALL_LDLIBS     := -lnetapi32 -ladvapi32 -lkernel32 -luser32
+ALL_LDFLAGS    := -static-libgcc -Wl,--enable-auto-import
-B$(newlib_build)/libc $(LDFLAGS) $(ALL_LDLIBS)
+ALL_DEP_LDLIBS := $(cygwin_build)/libcygwin.a
+
+MINGW_CXX        := ${srcdir}/mingw ${HOST_CPU} ${CXX} -I${updir}

 # List all binaries to be linked in Cygwin mode.  Each binary on this list
 # must have a corresponding .o of the same name.
@@ -83,7 +80,6 @@ strace.exe: MINGW_LDFLAGS += -lntdll
 ldd.exe: ALL_LDFLAGS += -lpsapi
 pldd.exe: ALL_LDFLAGS += -lpsapi

-ldh.exe: MINGW_LDLIBS :=
 ldh.exe: MINGW_LDFLAGS := -nostdlib -lkernel32

 # Check for dumper's requirements and enable it if found.
@@ -142,10 +138,10 @@ endif
 # how to link a MinGW binary
 $(MINGW_BINS): %.exe: %.o
 ifdef VERBOSE
-	$(MINGW_CXX) $(MINGW_CXXFLAGS) -o $@ ${filter %.o,$^}
-B$(mingw_build)/ $(MINGW_LDFLAGS)
+	$(MINGW_CXX) $(MINGW_CXXFLAGS) -o $@ ${filter %.o,$^} $(MINGW_LDFLAGS)
 else
 	@echo $(MINGW_CXX) -o $@ ${filter %.o,$^} ${filter-out -B%,
$(MINGW_CXXFLAGS) $(MINGW_LDFLAGS)};\
-	$(MINGW_CXX) $(MINGW_CXXFLAGS) -o $@ ${filter %.o,$^}
-B$(mingw_build)/ $(MINGW_LDFLAGS)
+	$(MINGW_CXX) $(MINGW_CXXFLAGS) -o $@ ${filter %.o,$^} $(MINGW_LDFLAGS)
 endif

 # how to link a Cygwin binary
@@ -160,7 +156,7 @@ endif
 # note: how to compile a Cygwin object is covered by the pattern rule
in Makefile.common

 # these dependencies ensure that the required in-tree libs are built first
-$(MINGW_BINS): $(MINGW_DEP_LDLIBS)
+$(MINGW_BINS): $(ALL_DEP_LDLIBS)
 $(CYGWIN_BINS): $(ALL_DEP_LDLIBS)

 clean:
@@ -179,9 +175,6 @@ install: all
 $(cygwin_build)/libcygwin.a: $(cygwin_build)/Makefile
 	@$(MAKE) -C $(@D) $(@F)

-$(MINGW_LIB): $(mingw_build)/Makefile
-	@$(MAKE) -C $(@D) $(@F)
-
 warn_dumper:
 	@echo '*** Not building dumper.exe since some required libraries or'
 	@echo '*** or headers are missing.  Potential candidates are:'
Index: winsup/utils/configure.in
===================================================================
RCS file: /cvs/src/src/winsup/utils/configure.in,v
retrieving revision 1.9
diff -p -u -3 -r1.9 configure.in
--- winsup/utils/configure.in	25 Jul 2008 15:03:25 -0000	1.9
+++ winsup/utils/configure.in	17 Oct 2012 15:21:33 -0000
@@ -23,6 +23,9 @@ AC_ARG_PROGRAM
 AC_CHECK_LIB(iconv, libiconv, libiconv=-liconv)
 AC_SUBST(libiconv)

+HOST_CPU="$host_cpu"
+AC_SUBST(HOST_CPU)
+
 INSTALL="/bin/sh "`cd $srcdir/../..; echo $(pwd)/install-sh -c`

 AC_PROG_INSTALL
Index: winsup/utils/mingw
===================================================================
RCS file: /cvs/src/src/winsup/utils/mingw,v
retrieving revision 1.8
diff -p -u -3 -r1.8 mingw
--- winsup/utils/mingw	14 Jun 2011 15:04:04 -0000	1.8
+++ winsup/utils/mingw	17 Oct 2012 15:21:33 -0000
@@ -5,17 +5,82 @@
 #
 # Find the path to the compiler.
 #
+cpu=$1; shift
 compiler=$1; shift
 dir=$(cd $(dirname $("$compiler" -print-prog-name=ld))/../..; pwd)

 #
+# Find the tool's name without the target-prefix
+#
+case $compiler in
+*-*-*-*)
+tool=`echo "$compiler" | sed 's/^\([^-]*\)-\([^-]*\)-\([^-]*\)-\(.*\)$/\4/'` ;;
+*) tool=compiler ;;
+esac
+
+#
 # The mingw32 directory should live somewhere close by to the
 # compiler.  Search for it.
 #
-[ "$dir" = '/' ] && dir=''
+[ "$dir" = '/' ] && dir='';
+
+mingw_compiler=''
+
+#
+# We search first for installed *-w64-mingw* toolchain with adequate
+# architecture.  We don't consider to check secondary target for
+# multilib toolchains here.
+#
+for d in "$dir"/bin/"$cpu"-w64-mingw*-"$tool"* \
+        "$dir"/usr/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /bin/"$cpu"-w64-mingw*-"$tool"* /usr/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /usr/local/bin/"$cpu"-w64-mingw*-"$tool"* \
+        "$dir"/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        "$dir"/usr/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /usr/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"*; do
+    case "$d" in
+        *\**) continue ;;
+        *)
+           if test -f "$d"; then
+             mingw_compiler=$d;
+             break;
+           fi
+    esac
+done
+
+#
+# If we didn't found an installed *-w64-mingw* toolchain for architecture
+# cpu, we search for a *-mingw* toolchain.
+#
+if [ -z "$mingw_compiler" ]; then
+  for d in "$dir"/bin/"$cpu"-*-mingw*--"$tool"* \
+        "$dir"/usr/bin/"$cpu"-*-mingw*-"$tool"* \
+        /bin/"$cpu"-w64-mingw*-"$tool"* /usr/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /usr/local/bin/"$cpu"-w64-mingw*-"$tool"* \
+        "$dir"/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        "$dir"/usr/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"* \
+        /usr/"$cpu"-w64-mingw*/sys-root/bin/"$cpu"-w64-mingw*-"$tool"*; do
+    case "$d" in
+        *\**) continue ;;
+        *)
+           if test -f "$d"; then
+             mingw_compiler=$d;
+             break;
+           fi
+    esac
+  done
+fi
+
+#
+# Search for mingw's sys-root.  Again, first for -w64-mingw* toolchain ...
+#
 mingw_dir=''
-for d in "$dir"/*-mingw32 "$dir"/usr/*-mingw32 "$dir"/*-mingw*
"$dir"/usr/*-mingw* \
-         /*-mingw32 /usr/*-mingw32 /*-mingw* /usr/*-mingw*; do
+for d in "$dir"/"$cpu"-w64-mingw* "$dir"/usr/"$cpu"-w64-mingw* \
+        "$dir"/"$cpu"-w64-mingw* "$dir"/usr/"$cpu"-w64-mingw* \
+        /"$cpu"-w64-mingw* /usr/"$cpu"-w64-mingw* /"$cpu"-w64-mingw* \
+        /usr/"$cpu"-w64-mingw*; do
     case "$d" in
 	*\**)	continue ;;
 	*)	if [ -d "$d"/sys-root/mingw ]; then
@@ -26,8 +91,33 @@ for d in "$dir"/*-mingw32 "$dir"/usr/*-m
     esac
 done

+#
+# ... else for *-mingw* toolchain.
+if [ -z "$mingw_dir" ]; then
+  for d in "$dir"/"$cpu"-*-mingw* "$dir"/usr/"$cpu"-*-mingw* \
+        "$dir"/"$cpu"-*-mingw* "$dir"/usr/"$cpu"-*-mingw* \
+        /"$cpu"-*-mingw* /usr/"$cpu"-*-mingw* /"$cpu"-*-mingw* \
+        /usr/"$cpu"-*-mingw*; do
+    case "$d" in
+        *\**)   continue ;;
+        *)      if [ -d "$d"/sys-root/mingw ]; then
+                    mingw_dir=$d/sys-root/mingw
+                else
+                    mingw_dir=$d;
+                fi; break;
+    esac
+  done
+fi
+
+if [ -z "$mingw_compiler" ]; then
+  mingw_compiler=$compiler
+fi
+
+#
+# Check if mingw's sys-root directory could be detected
+#
 if [ -z "$mingw_dir" ]; then
-    echo "$0: couldn't find i686-pc-mingw32 directory" 1>&2
+    echo "$0: couldn't find $cpu-*-mingw32 directory" 1>&2
     exit 1
 fi

@@ -90,10 +180,10 @@ fi
 if sawofile || ! sawcfile || ! sawcomp; then
     w32api=$($compiler -print-file-name=libc.a)
     w32api=$(cd $(dirname "$w32api")/w32api; pwd)
-    set -- -Wl,-nostdlib -L"${w32api}" "$@"
+    set -- -Wl,-nostdlib -B"${w32api}" "$@"
     ! sawnostdlib && set -- -nostdlib "$@" -lmingw32 -lgcc -lmoldname
-lmingwex -lmsvcrt -lmingw32 -luser32 -lkernel32 -ladvapi32 -lshell32
-lmingw32 -lgcc -lmoldname -lmingwex -lmsvcrt
     ! sawnostdlib && ! sawshared && { sawofile || sawcfile; } && set
-- "$mingw_dir"/lib/crt2.o "$@"
 fi

 # Execute the compiler with new mingw-specific options.
-exec $compiler "$@"
+exec $mingw_compiler "$@"

Attachment: build_patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]