Skip to content

Instantly share code, notes, and snippets.

@ErichDonGubler
Created May 17, 2015 00:04
Show Gist options
  • Save ErichDonGubler/212f6ef4f694a2068d00 to your computer and use it in GitHub Desktop.
Save ErichDonGubler/212f6ef4f694a2068d00 to your computer and use it in GitHub Desktop.
Starter makefile for cross-platform projects
# This script assumes you're using a GNU-compliant Make implementation.
# It is required that the following in your path:
# - bash
# Otherwise, this script attempts to use native commands.
# Help from [here](http://stackoverflow.com/questions/4555120/obtaining-directory-makefile-resides-in)
THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
POSIX_DIR="$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd)"
UNAME=$(shell uname -o)
ifeq ($(OS),Windows_NT)
ifeq ($(UNAME),Cygwin)
THIS_DIR:="$(shell cygpath -w $(POSIX_DIR))"
else
THIS_DIR:="$(shell cd $(dir $(THIS_MAKEFILE_PATH)) & echo %cd%)"
MKDIR_CMD:=mkdir # XXX: Untested
RMDIR_CMD:=rmdir /Q /S
endif
endif
# Defaults
THIS_DIR?=$(POSIX_DIR)
MKDIR_CMD?=mkdir -p
RMDIR_CMD?=rm -rf
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment