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

Search and replace in file on windows using win_lineinfile
Why does file owner depends on schedulig options of windows task? (Win Server 2012)
Batch Rename Script
Does the font displayed in the web mail client come from the provider or our OS?
Cmake not changing permission of file installed
How to give interactive inputs in a single line for .exe windows
Get the Full Process path from the prefetch file (offset address).
FFMPEG -F Concat Video, Audio Sycn Issue
Getting exit code of a process NOT started by powershell (exit code from get-process cmdlet)
How to share easily files between Mac OS X and Windows 10
Invoking remote command/script with specific credentials
WEVTUtil export certain event
Reading file content using windows batch file and executing a command
Move redirection instructions to variable?
Windows Command Line: how to loop over a list?
Windows - LAMP running on CentOS

Categories

HOME
android
windows
search
hyperlink
merge
wakanda
camera
google-cloud-functions
alsa
limit
maxscript
zip
mapbox
tvos
nuget-package
android-json
accessibility
g++
endeca
openpyxl
gource
http-post
internationalization
chargify
template-engine
nodemcu
gmm
solrcloud
database-connection
rubymotion
squashfs
gulp-watch
visual-studio-extensions
pic32
amazon-quicksight
has-and-belongs-to-many
mql
sqlpackage
panoramas
jbutton
r-grid
catch-unit-test
code-snippets
hreflang
mnist
sharepoint-workflow
playframework-2.1
apns-php
css-position
demo
cin
jvmti
magento-1.9.3
apache-spark-dataset
magento-2.0.7
vugen
bluez
amq
java-bytecode-asm
yii2-user
janus
template-toolkit
universal-analytics
objectscript
mathcad
renaming
autosar
preprocessor
uicolor
resourcemanager
tooleap
pushbots
httpruntime.cache
flock
zen-cart
opserver
.bash-profile
rpart
node-serialport
entity-framework-4.3
osc
document-repository
primitive-types
imagefilter
wcm
gnumeric
menubar
git-repo
multitasking
scrypt
inputmismatchexception
dtmf
flex++
kaleidoscope
android-icons
pagedown
swfobject
resource-management
pyunit
subgraph
isa-swizzling
pinch
filemerge
http-daemon
delimited-text
sun
information-management
wcf-proxy
great-circle

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