From 9c99d46e24ac79e96b62eddbd9877be2a5273aa6 Mon Sep 17 00:00:00 2001 From: Ilya Dmitrichenko Date: Tue, 21 Feb 2012 23:57:22 +0000 Subject: [PATCH] Simplified host OS platform detection in Makefiles --- Makefile.include | 9 +++++ cpu/avr/Makefile.avr | 10 ----- cpu/mc1322x/Makefile.mc1322x | 3 +- cpu/stm32w108/Makefile.stm32w108 | 6 +-- doc/Makefile | 12 +++--- platform/cooja/Makefile.cooja | 8 ---- platform/esb/Makefile.esb | 24 ++++------- platform/iris/Makefile.iris | 14 ++----- platform/mb851/Makefile.mb851 | 6 +-- platform/mbxxx/Makefile.mbxxx | 6 +-- platform/micaz/Makefile.micaz | 14 ++----- platform/minimal-net/Makefile.minimal-net | 4 +- platform/msb430/Makefile.msb430 | 24 ++++------- platform/native/Makefile.native | 2 +- platform/sky/Makefile.common | 40 +++++++++---------- platform/stepper-robot/Makefile.stepper-robot | 9 ----- platform/stm32test/Makefile.stm32test | 9 ----- 17 files changed, 66 insertions(+), 134 deletions(-) diff --git a/Makefile.include b/Makefile.include index 0c2988548..e00c804d2 100644 --- a/Makefile.include +++ b/Makefile.include @@ -21,6 +21,15 @@ ifeq ($(DEFINES),) endif endif +ifndef HOST_OS + ifeq ($(OS),Windows_NT) + $(warning Windows (NT) deteced.) + HOST_OS := Windows + else + HOST_OS := $(shell uname) + endif +endif + usage: @echo "make MAKETARGETS... [TARGET=(TARGET)] [savetarget] [targets]" diff --git a/cpu/avr/Makefile.avr b/cpu/avr/Makefile.avr index 8a94b9eb0..611c8d1a1 100644 --- a/cpu/avr/Makefile.avr +++ b/cpu/avr/Makefile.avr @@ -1,15 +1,5 @@ # $Id: Makefile.avr,v 1.27 2010/12/22 21:13:09 dak664 Exp $ -### Check if we are running under Windows - -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - .SUFFIXES: ### Optimization setting. $make OPTI=0 for easier debugging of changed source file(s) diff --git a/cpu/mc1322x/Makefile.mc1322x b/cpu/mc1322x/Makefile.mc1322x index 389185b05..c0a95b009 100644 --- a/cpu/mc1322x/Makefile.mc1322x +++ b/cpu/mc1322x/Makefile.mc1322x @@ -72,8 +72,7 @@ CUSTOM_RULE_C_TO_O=yes CFLAGS += -I$(OBJECTDIR) -I$(CONTIKI_CPU)/board -DBOARD=$(TARGET) $(OBJECTDIR)/board.h: $(OBJECTDIR) -ifneq (,$(findstring Windows,$(OS))) - ${info Cygwin detected.} +ifeq ($(HOST_OS),Windows) ln -f $(CONTIKI_CPU)/board/board.h $(OBJECTDIR)/board.h else ln -sf ../$(CONTIKI_CPU)/board/board.h $(OBJECTDIR)/board.h diff --git a/cpu/stm32w108/Makefile.stm32w108 b/cpu/stm32w108/Makefile.stm32w108 index 494de3a31..7eae06d4c 100644 --- a/cpu/stm32w108/Makefile.stm32w108 +++ b/cpu/stm32w108/Makefile.stm32w108 @@ -166,10 +166,8 @@ endif FLASHER = $(CONTIKI)/tools/stm32w/stm32w_flasher/stm32w_flasher # Check if we are running under Windows -ifdef OS - ifneq (,$(findstring Windows,$(OS))) - FLASHER = $(CONTIKI)/tools/stm32w/stm32w_flasher/stm32w_flasher.exe - endif +ifeq ($(HOST_OS),Windows) + FLASHER = $(CONTIKI)/tools/stm32w/stm32w_flasher/stm32w_flasher.exe endif diff --git a/doc/Makefile b/doc/Makefile index 36f37491e..5e1591985 100644 --- a/doc/Makefile +++ b/doc/Makefile @@ -13,12 +13,12 @@ export doclatex := NO export docroot := ../ # Get appropriate root for doxygen path cutoff -ifneq (,$(findstring Windows,$(OS))) -# on windows need to convert cygwin path to windows path for doxygen -ifneq (,$(findstring cygdrive,$(pwd))) - cygroot = $(subst /,$(space),$(patsubst /cygdrive/%,%,$(pwd))) - export docroot = $(firstword $(cygroot)):/$(subst $(space),/,$(wordlist 2,$(words $(cygroot)),$(cygroot))) -endif +ifeq ($(HOST_OS),Windows) + # on windows need to convert cygwin path to windows path for doxygen + ifneq (,$(findstring cygdrive,$(pwd))) + cygroot = $(subst /,$(space),$(patsubst /cygdrive/%,%,$(pwd))) + export docroot = $(firstword $(cygroot)):/$(subst $(space),/,$(wordlist 2,$(words $(cygroot)),$(cygroot))) + endif endif .PHONY: clean html pdf upload diff --git a/platform/cooja/Makefile.cooja b/platform/cooja/Makefile.cooja index 61c958735..e79fdbf1b 100644 --- a/platform/cooja/Makefile.cooja +++ b/platform/cooja/Makefile.cooja @@ -11,14 +11,6 @@ ifndef CONTIKI $(error CONTIKI not defined!) endif -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - ### Assuming simulator quickstart if no JNI library name set from Cooja ifndef LIBNAME QUICKSTART=1 diff --git a/platform/esb/Makefile.esb b/platform/esb/Makefile.esb index 91759f980..8aaf31edd 100644 --- a/platform/esb/Makefile.esb +++ b/platform/esb/Makefile.esb @@ -68,23 +68,15 @@ send: $(CONTIKI)/tools/codeprop.c ### System dependent Makefile -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - -ifeq (${HOSTTYPE},FreeBSD) +ifeq ($(HOST_OS),FreeBSD) # settings for FreeBSD -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.freebsd else -ifndef WINDIR - # settings for unix - -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix -else - # settings for windows - -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win -endif + ifeq ($(HOST_OS),Windows) + # settings for Windows + -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win + else + # settings for an arbitary unix-like platform + -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix + endif endif diff --git a/platform/iris/Makefile.iris b/platform/iris/Makefile.iris index 8d58e24d5..d7ce508bb 100644 --- a/platform/iris/Makefile.iris +++ b/platform/iris/Makefile.iris @@ -31,23 +31,15 @@ include $(CONTIKIAVR)/Makefile.avr avr-objdump -zhD $< > $@ -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - ifeq ($(PRGBOARD), ) PRGBOARD = mib510 endif ifeq ($(PORT), ) - ifndef WINDIR - PORT = /dev/ttyUSB0 - else + ifeq ($(HOST_OS), Windows) PORT = COM1 + else + PORT = /dev/ttyUSB0 endif endif diff --git a/platform/mb851/Makefile.mb851 b/platform/mb851/Makefile.mb851 index f1b127fde..ba3ac91a2 100644 --- a/platform/mb851/Makefile.mb851 +++ b/platform/mb851/Makefile.mb851 @@ -19,10 +19,8 @@ include $(CONTIKI)/cpu/stm32w108/Makefile.stm32w108 SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-linux -ifdef OS - ifneq (,$(findstring Windows,$(OS))) - SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows - endif +ifeq ($(HOST_OS),Windows) + SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows endif diff --git a/platform/mbxxx/Makefile.mbxxx b/platform/mbxxx/Makefile.mbxxx index e100e2991..6925a231f 100644 --- a/platform/mbxxx/Makefile.mbxxx +++ b/platform/mbxxx/Makefile.mbxxx @@ -18,10 +18,8 @@ include $(CONTIKI)/cpu/stm32w108/Makefile.stm32w108 SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-linux -ifdef OS - ifneq (,$(findstring Windows,$(OS))) - SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows - endif +ifeq ($(HOST_OS),Windows) + SERIALDUMP = $(CONTIKI)/tools/stm32w/serialdump-windows endif diff --git a/platform/micaz/Makefile.micaz b/platform/micaz/Makefile.micaz index 021444e14..49499cf1a 100644 --- a/platform/micaz/Makefile.micaz +++ b/platform/micaz/Makefile.micaz @@ -26,23 +26,15 @@ include $(CONTIKIAVR)/Makefile.avr avr-objdump -zhD $< > $@ -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - ifeq ($(PRGBOARD), ) PRGBOARD = mib510 endif ifeq ($(PORT), ) - ifndef WINDIR - PORT = /dev/ttyS0 - else + ifeq ($(HOST_OS),Windows) PORT = COM1 + else + PORT = /dev/ttyS0 endif endif diff --git a/platform/minimal-net/Makefile.minimal-net b/platform/minimal-net/Makefile.minimal-net index 37e487cbc..dd35c8880 100644 --- a/platform/minimal-net/Makefile.minimal-net +++ b/platform/minimal-net/Makefile.minimal-net @@ -7,7 +7,7 @@ CONTIKI_TARGET_MAIN = ${addprefix $(OBJECTDIR)/,contiki-main.o} CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c cfs-posix.c cfs-posix-dir.c dlloader.c -ifeq ($(OS),Windows_NT) +ifeq ($(HOST_OS),Windows) CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c else CONTIKI_TARGET_SOURCEFILES += tapdev-drv.c @@ -21,7 +21,7 @@ endif CONTIKI_SOURCEFILES += $(CONTIKI_TARGET_SOURCEFILES) -ifeq ($(OS),Windows_NT) +ifeq ($(HOST_OS),Windows) TARGET_LIBFILES = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a endif diff --git a/platform/msb430/Makefile.msb430 b/platform/msb430/Makefile.msb430 index f74ce49bf..af5c95caa 100644 --- a/platform/msb430/Makefile.msb430 +++ b/platform/msb430/Makefile.msb430 @@ -24,25 +24,17 @@ endif ### System dependent Makefile -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif - -ifeq (${HOSTTYPE},FreeBSD) +ifeq ($(HOST_OS),FreeBSD) # settings for FreeBSD -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.freebsd else -ifndef WINDIR - # settings for unix - -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix -else - # settings for windows - -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win -endif + ifeq ($(HOST_OS),Windows) + # settings for Windows + -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.win + else + # settings for an arbitary unix-like platform + -include $(CONTIKI)/platform/$(TARGET)/buildscripts/Makefile.unix + endif endif # If we are not running under Windows, we assume Linux diff --git a/platform/native/Makefile.native b/platform/native/Makefile.native index eade2e7a4..63ba12e9d 100644 --- a/platform/native/Makefile.native +++ b/platform/native/Makefile.native @@ -13,7 +13,7 @@ CONTIKI_TARGET_SOURCEFILES = contiki-main.c clock.c leds.c leds-arch.c \ button-sensor.c pir-sensor.c vib-sensor.c xmem.c \ sensors.c irq.c cfs-posix.c cfs-posix-dir.c -ifeq ($(OS),Windows_NT) +ifeq ($(HOST_OS),Windows) CONTIKI_TARGET_SOURCEFILES += wpcap-drv.c wpcap.c TARGET_LIBFILES = /lib/w32api/libws2_32.a /lib/w32api/libiphlpapi.a else diff --git a/platform/sky/Makefile.common b/platform/sky/Makefile.common index 066cad86b..e922d61c7 100644 --- a/platform/sky/Makefile.common +++ b/platform/sky/Makefile.common @@ -43,29 +43,27 @@ NUMPAR=20 IHEXFILE=tmpimage.ihex # Check if we are running under Windows -ifdef OS - ifneq (,$(findstring Windows,$(OS))) - USBDEVPREFIX=/dev/com - SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-windows - MOTELIST = $(CONTIKI)/tools/sky/motelist-windows - TMOTE_BSL_FILE = tmote-bsl - TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE).exe),1,0) - ifeq ($(TMOTE_BSL), 1) - NUMPAR = 1 - BSL = $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE) - MOTES = $(shell $(MOTELIST) | grep COM | \ - cut -f 4 -d \ ) - else - BSL = $(CONTIKI)/tools/sky/msp430-bsl-windows --telosb - BSL_FILETYPE = -I - MOTES = $(shell $(MOTELIST) | grep COM | \ - cut -f 4 -d \ | \ - perl -ne 'print $$1 - 1 . " " if(/COM(\d+)/);') - endif - CMOTES = $(shell $(MOTELIST) | grep COM | \ + + USBDEVPREFIX=/dev/com + SERIALDUMP = $(CONTIKI)/tools/sky/serialdump-windows + MOTELIST = $(CONTIKI)/tools/sky/motelist-windows + TMOTE_BSL_FILE = tmote-bsl + TMOTE_BSL=$(if $(wildcard $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE).exe),1,0) + ifeq ($(TMOTE_BSL), 1) + NUMPAR = 1 + BSL = $(CONTIKI)/tools/sky/$(TMOTE_BSL_FILE) + MOTES = $(shell $(MOTELIST) | grep COM | \ + cut -f 4 -d \ ) + else + BSL = $(CONTIKI)/tools/sky/msp430-bsl-windows --telosb + BSL_FILETYPE = -I + MOTES = $(shell $(MOTELIST) | grep COM | \ cut -f 4 -d \ | \ - perl -ne 'print $$1 . " " if(/COM(\d+)/);') + perl -ne 'print $$1 - 1 . " " if(/COM(\d+)/);') endif + CMOTES = $(shell $(MOTELIST) | grep COM | \ + cut -f 4 -d \ | \ + perl -ne 'print $$1 . " " if(/COM(\d+)/);') endif # If we are not running under Windows, we assume Linux diff --git a/platform/stepper-robot/Makefile.stepper-robot b/platform/stepper-robot/Makefile.stepper-robot index 6ad4065c8..b74e6180d 100644 --- a/platform/stepper-robot/Makefile.stepper-robot +++ b/platform/stepper-robot/Makefile.stepper-robot @@ -27,12 +27,3 @@ ifndef BASE_IP BASE_IP := 172.16.1.1 endif -### System dependent Makefile - -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif diff --git a/platform/stm32test/Makefile.stm32test b/platform/stm32test/Makefile.stm32test index 8f003a200..4c7cf90c9 100644 --- a/platform/stm32test/Makefile.stm32test +++ b/platform/stm32test/Makefile.stm32test @@ -24,12 +24,3 @@ ifndef BASE_IP BASE_IP := 172.16.1.1 endif -### System dependent Makefile - -ifndef WINDIR - ifdef OS - ifneq (,$(findstring Windows,$(OS))) - WINDIR := Windows - endif - endif -endif