bz2lib_build:=$(bupdir)/bz2lib
w32api_source:=$(updir)/w32api
w32api_build:=$(bupdir)/w32api
-ifeq (,${findstring $(w32api_source),$(CFLAGS) $(CXXFLAGS) $(CXX) $(CC)})
-w32api_include:=-I$(w32api_source)/include
-endif
w32api_lib:=$(w32api_build)/lib
newlib_source:=$(updir1)/newlib
newlib_build:=$(bupdir1)/newlib
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 -nostdinc++"}
+ifneq (,$(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_sys_include) $(newlib_include) $(newlib_sys_include_include) $(w32api_include)
ifdef CONFIG_DIR
INCLUDES+=-I$(CONFIG_DIR)
endif
-MINGW_INCLUDES:=-I$(updir)/mingw/include $(w32api_include)
+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:=-B${mingw_build} -B${mingw_build}/mingwex
GCC_INCLUDE:=${subst //,/,-I$(gcc_libdir)/include}
endif
-nostdinc:=${shell [ -d "$(updir)/w32api" ] && echo "-nostdinc -nostdinc++"}
-ifeq (,$(nostdinc))
-override w32api_lib:=${subst //,/,${shell $(CC) -print-search-dirs | awk -F: '/^librar/{for (i = 1; i <= NF; i++) if ($$i ~ /\/lib\/*$$/) foo=$$i} END{print foo}'}/w32api}
-endif
-
COMPILE_CXX=$(CXX) $c $(nostdinc) $(ALL_CXXFLAGS) $(GCC_INCLUDE) \
-fno-rtti -fno-exceptions
COMPILE_CC=$(CC) $c $(nostdinc) $(ALL_CFLAGS) $(GCC_INCLUDE)