Skip to content

Instantly share code, notes, and snippets.

@pokehanai
Created February 10, 2017 02:19
Show Gist options
  • Save pokehanai/bf8188a49bcc6e6bb94e963a26a9c9ae to your computer and use it in GitHub Desktop.
Save pokehanai/bf8188a49bcc6e6bb94e963a26a9c9ae to your computer and use it in GitHub Desktop.
Makefile for building Unity3d C# managed DLL on Mac
# Boilarplate: Makefile for building Unity3d C# managed DLL on Mac
#
# [Usage]
# If Unity is installed in the default directory /Applications/Unity/Unity.app, simply:
# $ make
# Or either:
# $ UNITY_NAME=UnityXXX make
# $ UNITY_DIR=/Applications/UnityXXX/UnityYYY.app make
#
# [library directory layout]
# +-- (library dir)
# |
# +---src (contains source files)
# | |
# | +-- ...
# |
# +---bin (built module goes here)
UNITY_NAME = Unity544
UNITY_DIR = /Applications/$(UNITY_NAME)/$(UNITY_NAME).app
# -- Unity provided files
# mono compiler
SMCS = $(shell find $(UNITY_DIR)/Contents -type f -name smcs | grep /bin/smcs)
# UnityEngine.dll
UNITY_ENGINE_DLL = $(UNITY_DIR)/Contents/Managed/UnityEngine.dll
# UnityEditor.dll
UNITY_EDITOR_DLL = $(UNITY_DIR)/Contents/Managed/UnityEditor.dll
# directories
SRC_DIR = src
BUILD_DIR = bin
TARGET_NAME = MyLibrary.dll
# Target DLL path
BUILD_TARGET = $(BUILD_DIR)/$(TARGET_NAME)
# source files
SRC = $(shell find $(SRC_DIR) -name '*.cs')
# build flags
SMCS_FLAGS = -define:UNITY_5_3_OR_NEWER;RELEASE
# -- check existance of required files
ifeq ($(SMCS),)
$(error Mono compiler 'smcs' is not found in $(UNITY_DIR))
endif
ifeq ($(wildcard $(UNITY_ENGINE_DLL)),)
$(error UnityEngine.dll is not found as $(UNITY_DIR)/Managed/UnityEngine.dll)
endif
ifeq ($(wildcard $(UNITY_EDITOR_DLL)),)
$(error UnityEditor.dll is not found as $(UNITY_DIR)/Managed/UnityEditor.dll)
endif
.PHONY: all build
all: build
build: $(BUILD_TARGET)
$(BUILD_TARGET): $(SRC)
# create the build target directory
$(shell install -d $(BUILD_DIR))
# build
$(SMCS) -r:$(UNITY_ENGINE_DLL) -r:$(UNITY_EDITOR_DLL) -define:$(SMCS_FLAGS) -target:library -out:$(BUILD_TARGET) $(SRC)
@echo built: $@
@pokehanai
Copy link
Author

If you have error like Makefile:66: *** multiple target patterns. Stop., check the code file that indents are made with TAB(SPC is wrong in Makefile).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment