abcminiuser / dmbs

Dean's Makefile Build System - making MAKE easier.
51 stars 18 forks source link

Add Module Template/Sample #20

Closed NicoHood closed 7 years ago

NicoHood commented 7 years ago

This text is quite informative, but still not enough if you ask me: https://github.com/abcminiuser/dmbs/blob/master/DMBS/WritingYourOwnModules.md

I am currently working on a whole DMBS setup for libraries etc. My template looks like this:

# Include Guard
ifeq ($(findstring TEMPLATE, $(DMBS_BUILD_MODULES)),)

# Sanity check user supplied DMBS path
ifndef DMBS_PATH
$(error Makefile DMBS_PATH option cannot be blank)
endif

# Location of the current module
TEMPLATE_MODULE_PATH := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST))))

# Import the CORE module of DMBS
include $(DMBS_PATH)/core.mk

# This module needs to be included before gcc.mk
ifneq ($(findstring GCC, $(DMBS_BUILD_MODULES)),)
$(error Include this module before gcc.mk)
endif

# Help settings
DMBS_BUILD_MODULES         += TEMPLATE
DMBS_BUILD_TARGETS         +=
DMBS_BUILD_MANDATORY_VARS  += DMBS_PATH
DMBS_BUILD_OPTIONAL_VARS   +=
DMBS_BUILD_PROVIDED_VARS   += TEMPLATE_SRC
DMBS_BUILD_PROVIDED_MACROS +=

# Sanity check user supplied values
$(foreach MANDATORY_VAR, $(DMBS_BUILD_MANDATORY_VARS), $(call ERROR_IF_UNSET, $(MANDATORY_VAR)))

# TEMPLATE Library and stream cipher modes
TEMPLATE_SRC := $(TEMPLATE_MODULE_PATH)/src/lib.c

# Compiler flags and sources
SRC           += $(TEMPLATE_SRC)
CC_FLAGS      += -I$(TEMPLATE_MODULE_PATH)/include/

# Phony build targets for this module
.PHONY: $(DMBS_BUILD_TARGETS)

endif