windows


Makefile compatible with both DOS/minw32 and cygwin


I'm working in a team of embedded firmware developers.
We all use make to build a lot of different targets - binaries, doxygen, release packages etc.
Some of the team builds under DOS/mingw32 and others under cygwin.
I don't want to / cannot force the whole team to choose only one side.
So we try to make our makefiles cross platform compatible and mostly we are successful, but the current solutions have their warts.
Specifically we are having a hard time writing cross platform rules for:
copy
dir exist
rmdir
rm
We use an os.mk file to choose solutions for current platform like this:
ifeq ($(OS),Windows_NT)
HASUNAME := $(if $(shell where uname 2> NUL),$(shell echo yes),$(shell echo no))
ifeq ($(HASUNAME),yes)
UNAME := $(shell uname)
else
UNAME := WIN32
endif
ifneq (,$(findstring CYGWIN,$(UNAME)))
$(shell rm NUL)
PATHSEP:=/
COPY:=cp
RM:=rm -f
RMDIR:=rm -rf
else
ifneq (,$(findstring MINGW,$(UNAME)))
PATHSEP:=/
COPY:=cp
RM:=rm -f
RMDIR:=rm -rf
else
PATHSEP:=\\
COPY:=copy
RM:=del /q 2>NUL
RMDIR:=rmdir /q /s 2>NUL
endif
endif
else
COPY=UNEXPECTED_OS_ERROR
RM=UNEXPECTED_OS_ERROR
RMDIR=UNEXPECTED_OS_ERROR
endif
The warts come because of the differences in the different platform implementations of the file functions. E.g. for copy I need to manipulate the arguments because one platform uses slash for path separator and the other uses backslash. Like this:
BOOTSRC:=$(subst /,$(PATHSEP),../boot/build/$(BOARD)/Bootloader.hex)
Bootloader.hex:
$(COPY) $(BOOTSRC) Bootloader.hex
And DOS has issues with doing rm and rmdir without writing on stderr.
I have implemented dir exist ( [ -d folder ] on cygwin/*nix) as a super short python script, but prefer to not mix python into it if I can avoid it.
import os
import sys
for arg in sys.argv[1:]:
if not os.path.isdir(arg):
sys.exit(1)
sys.exit()
It seems CMake was developed partly for this issue: Makefile for DOS/Windows and Cygwin
But I would prefer not to have to switch to CMake.
Can you help me find elegant solutions for the four file operations?

Related Links

How to log properly in windows library?
cygwin redirect append to network share fails on Windows 2008R
Return to outer loop in PowerShell when matching conditions
Reading NFC tag in Windows Phone 8.1 app at startup
Task Sheduler: How to run batch file through cmd instead of taskeng.exe?
Windows ImageMagick/bat remove part of the name
How do I control the WMP from command line/batch
Command line move files/folders up in the directory tree
Windows 7 File Permissions - Force directory permissions recursively to all current and future files
not able to run pig on windows 7 using cygwin
Can't update Meteor on Windows 8.1 machine
MPICH on windows - semaphore timeout period has expired
UNIX script to run on WINDOWS
programatically open 'system properties'
Get IP from MAC address. arp -a not showing device
2nd FOR statement won't work in batch file

Categories

HOME
grok
google-cloud-platform
codenvy
c99
pagination
alexa-skills-kit
google-spreadsheet
mysql-workbench
maxscript
tvos
code-coverage
joomla3.0
octave
java.util.logging
google-form
soci
googlebot
pagespeed
r-mice
react-toolbox
pchart
object-storage
zxing
gmock
dapper-extensions
pylons
jasmine-node
outliers
exchangewebservices
cppreference
sqlpackage
calculation
custom-controls
papaparse
contacts
carriage-return
getlasterror
numpy-broadcasting
protege4
apic
nohup
metaprogramming
resolution
plaintext
android-ibeacon
apollostack
clang++
getchar
openresty
jquery-ui-draggable
dbcontext
identification
x-ray
colorbar
excel-dna
lsyncd
rackspace-cloud
universal-analytics
structuremap4
renaming
rmongo
choice
stripe-connect
pytables
wso2developerstudio
tracker-enabled-dbcontext
project-organization
kendo-upload
qbxml
crouton-os
relativelayout
custom-errors
flock
haskell-warp
skspritenode
omnifaces
broadband
cross-join
deform
webfinger
device-tree
jama
jqmodal
rcaller
renderer
drupal-nodes
openargs
gd-graph
time.h
node-blade
jquery-1.9
onload-event
pdfviewer
tree-balancing
sentestingkit
boost-msm
zope.interface
koken
update-statement
google-ajax-api
mbeans
ie-compatibility-mode
cruisecontrol.rb
zend-rest
lxr
feasibility
fdf
java1.4
business-model

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App