changeset 530:9b79261d2b00

Add cross-compilation support.
author Oleksandr Gavenko <gavenkoa@gmail.com>
date Sat, 27 Oct 2012 14:54:12 +0300
parents d2ae002787b7
children 857d8ecc26be
files printarg/Makefile
diffstat 1 files changed, 31 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/printarg/Makefile	Sat Oct 27 14:05:48 2012 +0300
+++ b/printarg/Makefile	Sat Oct 27 14:54:12 2012 +0300
@@ -32,21 +32,43 @@
 mandir = $(prefix)/share/man
 man1dir = $(mandir)/man1
 
-host_os = unix
+build_os = unix
 ifneq '' '$(COMSPEC)'
-  host_os = windows
+  build_os = windows
 endif
 
 UNAME := $(shell uname -s)
 ifneq '' '$(filter MINGW%,$(UNAME))'
-  host_os_emu = mingw
+  build_os_emu = mingw
 endif
 ifneq '' '$(filter CYGWIN%,$(UNAME))'
-  host_os_emu = cygwin
+  build_os_emu = cygwin
+endif
+ifeq '' '$(host)'
+  host_os := $(build_os)
+  host_vendor := $(build_vendor)
+  host_cpu := $(build_cpu)
+else
+  host_ := $(subst -, ,$(host))
+  ifeq '2' '$(words $(host_))'
+    host_cpu := $(word 1,$(host_))
+    host_vendor :=
+    host_os := $(word 2,$(host_))
+  endif
+  ifeq '3' '$(words $(host_))'
+    host_cpu := $(word 1,$(host_))
+    host_vendor := $(word 2,$(host_))
+    host_os := $(word 3,$(host_))
+  endif
 endif
 
-CC=gcc
-LD=gcc
+CC := gcc
+STRIP := strip
+ifneq '$(build)' '$(host)'
+  CC := $(host)-gcc
+  STRIP := $(host)-strip
+endif
+LD=$(CC)
 # CC=i686-pc-cygwin-gcc-3 -mno-cygwin
 # LD=i686-pc-cygwin-gcc-3 -mno-cygwin
 
@@ -55,12 +77,12 @@
   CFLAGS += -g
 endif
 LDFLAGS =
-ifeq 'windows' '$(host_os)'
+ifneq '' '$(filter $(host_os),windows mingw32 cygwin)'
   CFLAGS += -mwindows
 endif
 
 EXE_SUFFIX =
-ifeq 'windows' '$(host_os)'
+ifneq '' '$(filter $(host_os),windows mingw32 cygwin)'
   EXE_SUFFIX = .exe
 endif
 
@@ -75,7 +97,7 @@
 ${B}$(APP): $(O_FILES)
 	$(LD) $(LDFLAGS) -o $@ $^
 ifneq 'yes' '$(DEBUG)'
-	strip $@
+	$(STRIP) $@
 endif
 
 $(O_FILES): ${B}%.o: ${S}%.c $(MAKEFILE_LIST)