win32 driver guicondigdata work comments.
[sdk] / crossplatform.mk
index 0e507a8..8f829d6 100644 (file)
@@ -1,18 +1,42 @@
 # HOST PLATFORM DETECTION
-ifeq "$(OS)" "Windows_NT"
+ifeq ($(OS),Windows_NT)
    HOST_PLATFORM := win32
    WINDOWS_HOST := defined
+   # IA64 / AMD64 / x86   #HKEY_LOCAL_MACHINE
+   #_PROCESSOR_ARCHITECTURE := $(shell reg Query "HKLM\System\CurrentControlSet\Control\Session Manager\Environment" /v PROCESSOR_ARCHITECTURE)
+   #ifneq ($(findstring AMD64,$(_PROCESSOR_ARCHITECTURE)),)
+   #   HOST_ARCH := amd64
+   #   HOST_BITS := 64
+   #else
+   #   ifneq ($(findstring IA64,$(_PROCESSOR_ARCHITECTURE)),)
+   #      HOST_ARCH := ia64
+   #      HOST_BITS := 64
+   #   else
+   #      ifneq ($(findstring x86,$(_PROCESSOR_ARCHITECTURE)),)
+   #         HOST_ARCH := x86
+   #         HOST_BITS := 32
+   #      else
+   #         HOST_ARCH := unknown
+   #         HOST_BITS := unknown
+   #      endif
+   #   endif
+   #endif
+   #ifdef ProgramFiles(x86)
+   #   HOST_BITS := 64
+   #else
+   #   HOST_BITS := 32
+   #endif
 else
  _UNAME := $(shell uname)
  UNAME_P := $(shell uname -p)
- ifeq "$(_UNAME)" "FreeBSD"
+ ifeq ($(_UNAME),FreeBSD)
  # Using Linux platform for Unix OSes for now 
  #   HOST_PLATFORM := bsd
     BSD_HOST := defined
     HOST_PLATFORM := linux
     LINUX_HOST := defined
  else
-  ifeq "$(_UNAME)" "Darwin"
+  ifeq ($(_UNAME),Darwin)
      HOST_PLATFORM := apple
      OSX_HOST := defined
   else
@@ -50,44 +74,52 @@ endif
 ifndef PLATFORM
    PLATFORM := $(TARGET_PLATFORM)
 endif
-ifeq "$(TARGET_PLATFORM)" "win32"
+ifeq ($(TARGET_PLATFORM),win32)
    WINDOWS_TARGET := defined
 else
-ifeq "$(TARGET_PLATFORM)" "apple"
+ifeq ($(TARGET_PLATFORM),apple)
    OSX_TARGET := defined
 else
-#ifeq "$(TARGET_PLATFORM)" "bsd"
+ifeq ($(TARGET_PLATFORM),emscripten)
+   EMSCRIPTEN_TARGET := defined
+else
+ifeq ($(TARGET_PLATFORM),pnacl)
+   PNACL_TARGET := defined
+else
+#ifeq ($(TARGET_PLATFORM),bsd)
 #   BSD_TARGET := defined
 #else
    LINUX_TARGET := defined
 #endif
 endif
 endif
+endif
+endif
 
 # CROSS_TARGET
-ifneq "$(TARGET_PLATFORM)" "$(HOST_PLATFORM)"
+ifneq ($(TARGET_PLATFORM),$(HOST_PLATFORM))
    CROSS_TARGET := defined
 endif
 
 # TARGET_TYPE
-ifeq "$(TARGET_TYPE)" "staticlib"
+ifeq ($(TARGET_TYPE),staticlib)
    STATIC_LIBRARY_TARGET := defined
 else
-ifeq "$(TARGET_TYPE)" "sharedlib"
+ifeq ($(TARGET_TYPE),sharedlib)
    SHARED_LIBRARY_TARGET := defined
 else
-ifeq "$(TARGET_TYPE)" "executable"
+ifeq ($(TARGET_TYPE),executable)
    EXECUTABLE_TARGET := defined
 endif
 endif
 endif
 
-ifeq "$(GCC_PREFIX)" "i586-mingw32msvc-"
+ifeq ($(GCC_PREFIX),i586-mingw32msvc-)
 export ARCH
 ARCH := x32
 endif
 
-ifeq "$(GCC_PREFIX)" "i686-w64-mingw32-"
+ifeq ($(GCC_PREFIX),i686-w64-mingw32-)
 export ARCH
 ARCH := x32
 endif
@@ -95,34 +127,34 @@ endif
 # Accept different things for ARCH but standardize on x32/x64
 # This will be used for object directories
 ifdef ARCH
- ifeq "$(ARCH)" "32"
+ ifeq ($(ARCH),32)
   override ARCH := x32
  endif
- ifeq "$(ARCH)" "x86"
+ ifeq ($(ARCH),x86)
   override ARCH := x32
  endif
- ifeq "$(ARCH)" "i386"
+ ifeq ($(ARCH),i386)
   override ARCH := x32
  endif
- ifeq "$(ARCH)" "i686"
+ ifeq ($(ARCH),i686)
   override ARCH := x32
  endif
- ifeq "$(ARCH)" "64"
+ ifeq ($(ARCH),64)
   override ARCH := x64
  endif
- ifeq "$(ARCH)" "amd64"
+ ifeq ($(ARCH),amd64)
   override ARCH := x64
  endif
- ifeq "$(ARCH)" "x86_64"
+ ifeq ($(ARCH),x86_64)
   override ARCH := x64
  endif
 
  # Set ARCH_FLAGS only if ARCH is set
- ifeq "$(ARCH)" "x64"
+ ifeq ($(ARCH),x64)
   TARGET_ARCH := x86_64
   ARCH_FLAGS := -m64
  endif
- ifeq "$(ARCH)" "x32"
+ ifeq ($(ARCH),x32)
   TARGET_ARCH := i386
   ARCH_FLAGS := -m32
  endif
@@ -138,8 +170,9 @@ endif
 # On Windows/32 bit systems, pass -m32 as TDM-GCC packaged with the installer produces 64 bit executables by default
 # Disable this if your compiler does not accept -m32
 ifndef ARCH
- ifeq "$(HOST_PLATFORM)" "win32"
-  ifeq "$(TARGET_PLATFORM)" "win32"
+ ifeq ($(HOST_PLATFORM),win32)
+  ifeq ($(TARGET_PLATFORM),win32)
+   #ifeq ($(HOST_BITS),32)
    ifndef ProgramFiles(x86)
     ARCH := x32
     TARGET_ARCH := i386
@@ -157,7 +190,7 @@ endif
 # COMPILER SUFFIX
 COMPILER_SUFFIX = $(ARCH_SUFFIX)
 ifdef COMPILER
-ifneq "$(COMPILER)" "default"
+ifneq ($(COMPILER),default)
 COMPILER_SUFFIX = .$(COMPILER)$(ARCH_SUFFIX)
 endif
 endif
@@ -167,12 +200,18 @@ empty :=
 esc := $(empty)\7f$(empty)
 space := $(empty) $(empty)
 comma := ,
+openpar := (
+clospar := )
 slash := $(empty)/$(empty)
 backslash := $(empty)\$(empty)
 escspace = $(subst $(space),$(backslash)$(space),$(subst $(backslash)$(space),$(space),$(1)))
 hidspace = $(subst $(space),$(esc),$(subst $(backslash)$(space),$(esc),$(1)))
+hidescspace = $(subst $(backslash)$(space),$(esc),$(1))
 shwspace = $(subst $(esc),$(backslash)$(space),$(1))
+shwspacequoted = $(subst $(esc),"$(space)",$(subst \$(space),$(esc),$(1)))
 unescp_all = $(subst $(esc),$(backslash),$(subst $(backslash),,$(subst $(backslash)$(backslash),$(esc),$(1))))
+for_list = $(call sys_path,$(call unescp_all,$(call shwspacequoted,$(subst $(space),$(comma),$(subst $(space)$(space),$(space),$(call hidescspace,$(1)))))))
+lc = $(subst A,a,$(subst B,b,$(subst C,c,$(subst D,d,$(subst E,e,$(subst F,f,$(subst G,g,$(subst H,h,$(subst I,i,$(subst J,j,$(subst K,k,$(subst L,l,$(subst M,m,$(subst N,n,$(subst O,o,$(subst P,p,$(subst Q,q,$(subst R,r,$(subst S,s,$(subst T,t,$(subst U,u,$(subst V,v,$(subst W,w,$(subst X,x,$(subst Y,y,$(subst Z,z,$1))))))))))))))))))))))))))
 
 # PATH SEPARATOR STRING TOOLS
 ifdef WINDOWS_HOST
@@ -183,9 +222,13 @@ endif
 ifdef WIN_PS_TOOLS
    psep := $(backslash)
    slash_path = $(subst $(backslash),$(slash),$(1))
-   sys_path = $(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1)))
+   esc_ampersand = $(subst &,^&,$(subst ^&,&,$(1)))
+   sys_path = $(call esc_ampersand,$(subst $(backslash)$(backslash),$(slash),$(subst $(slash),$(backslash),$(1))))
+   each_quote_path = $(call quote_path,$(path))
    quote_path = "$(call sys_path,$(call unescp_all,$(1)))"
+#   each_path_quote = $(if $(findstring $(esc),$(path)),"$(call sys_path,$(call unescp_all,$(call shwspace,$(path))))",$(call sys_path,$(call unescp_all,$(path))))
    each_path_quote = $(if $(findstring $(esc),$(path)),"$(call unescp_all,$(call shwspace,$(path)))",$(call unescp_all,$(path)))
+#   sys_path_list
    sys_path_list = $(foreach path,$(1),$(each_path_quote))
 else
    psep := $(slash)
@@ -239,17 +282,24 @@ endif
 endif
 ifdef WIN_SHELL_COMMANDS
    nullerror = 2>NUL
-   echo = $(if $(1),echo $(1))
+   echo = $(if $(1),echo $(1),echo.)
+   cat = $(if $(1),type $(1))
    touch = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do @(cd %%~pI && type nul >> %%~nxI && copy /by %%~nxI+,, > nul 2>&1 && cd %%cd%%)")
-   cpq = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
-   cpv = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))")
+#   cpq = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
+   cpq = $(if $(1),@cmd /c "for %%I in ($(call for_list,$(1))) do copy /by %%I $(call sys_path,$(2))" > nul 2>&1)
+#   cpv = $(if $(1),@cmd /c "for %%I in ($(call sys_path,$(1))) do copy /by %%I $(call sys_path,$(2))")
+   cpv = $(if $(1),@cmd /c "for %%I in ($(call for_list,$(1))) do copy /by %%I $(call sys_path,$(2))")
+#   rmq = $(if $(1),-del /f /q $(1) > nul 2>&1)
+#   rmq = $(if $(1),-del /f /q $(call sys_path,$(1)) > nul 2>&1)
    rmq = $(if $(1),-del /f /q $(call sys_path,$(call sys_path_list,$(1))) > nul 2>&1)
+#   rmq = $(if $(1),-del /f /q $(foreach path,$(1),$(each_quote_path)) $(call sys_path,$(1)) > nul 2>&1)
    rmrq = $(if $(1),-rmdir /q /s $(call sys_path,$(1)) > nul 2>&1)
    mkdirq = $(if $(1),-mkdir $(call sys_path,$(1)) > nul 2>&1)
    rmdirq = $(if $(1),-rmdir /q $(call sys_path,$(1)) > nul 2>&1)
 else
    nullerror = 2>/dev/null
-   echo = $(if $(1),echo "$(1)")
+   echo = $(if $(1),echo "$(1)",echo)
+   cat = $(if $(1),cat $(1))
    touch = $(if $(1),touch $(1))
    cpq = $(if $(1),cp $(1) $(2))
    cpv = cp $(1) $(2)