Modest/examples/Makefile

84 lines
2.6 KiB
Makefile
Raw Normal View History

2016-08-29 00:20:40 +03:00
TARGET := examples
2017-03-11 22:53:26 +03:00
SRCDIR := .
2016-08-29 00:20:40 +03:00
CC ?= gcc
2017-03-11 22:53:26 +03:00
# ARGS
#
# BINARY_OPTIMIZATION_LEVEL, default -O2
# MODEST_BUILD_WITHOUT_THREADS, YES or (NO or undefined), default undefined
#
.DEFAULT_GOAL := all
#********************
# other Makefile
#***************
BINARY_PATH_RELATIVE := ..
include $(BINARY_PATH_RELATIVE)/Makefile.bin.cfg
BINARY_TO_DIR := $(BINARY_PATH_RELATIVE)/$(BINARY_DIR_BASE)
#********************
# Build
#***************
BINARY_BUILD_MODULES ?= $(dir $(wildcard $(SRCDIR)/*/))
BINARY_BUILD_MODULES_LIST := $(strip $(foreach dir,$(BINARY_BUILD_MODULES),$(word 2, $(subst $(MODEST_DIR_SEPARATOR), , $(dir))) ))
BINARY_BUILD_MODULES_MAKEFILES_LIST := $(foreach dir,$(BINARY_BUILD_MODULES_LIST),$(dir)/Makefile.mk)
#********************
# Targets
#***************
BINARY_BUILD_MODULES_TARGET := $(BINARY_BUILD_MODULES_LIST)
BINARY_BUILD_MODULES_TARGET_ALL := $(foreach dir,$(BINARY_BUILD_MODULES_TARGET),$(dir)_all)
BINARY_BUILD_MODULES_TARGET_CLEAN := $(foreach dir,$(BINARY_BUILD_MODULES_TARGET),$(dir)_clean)
#********************
# Utils
#***************
define BYNARY_UTILS_NEW_LINE
endef
BINARY_UTILS_OBJS = $(patsubst %.c,%,$(foreach dir,$2,$(wildcard $(SRCDIR)/$1/$(dir)/*.c)))
BINARY_UTILS_CREATE_DIRS = $(foreach dir,$(BINARY_BUILD_MODULES_LIST),mkdir -p $(BINARY_TO_DIR)/$(dir) $(BYNARY_UTILS_NEW_LINE))
#********************
# Include all modules Makefile.mk
#***************
include $(BINARY_BUILD_MODULES_MAKEFILES_LIST)
#********************
# Set ARGS for flags
#***************
2017-03-12 20:23:04 +03:00
override CFLAGS += $(BINARY_CFLAGS)
override LDFLAGS += $(BINARY_LDFLAGS)
override LDLIBS += $(BINARY_LIBRARIES)
2017-03-11 22:53:26 +03:00
#********************
# Objects
#***************
BINARY_BUILD_EXECUTE ?= $(foreach dir,$(BINARY_BUILD_MODULES_TARGET),$($(dir)_objs))
BINARY_BUILD_EXECUTE_CLEAN := $(foreach path,$(BINARY_BUILD_EXECUTE),$(subst ./,,$(path)))
BINARY_BUILD_EXECUTE_TO_CLEAN := $(foreach path,$(BINARY_BUILD_EXECUTE_CLEAN),rm -f $(BINARY_TO_DIR)/$(path) $(BYNARY_UTILS_NEW_LINE))
BINARY_BUILD_DIRS_TO_CLEAN := $(foreach path,$(BINARY_BUILD_MODULES_LIST),rm -rf $(BINARY_TO_DIR)/$(path) $(BYNARY_UTILS_NEW_LINE))
BINARY_BUILD_EXECUTE_COPY := $(foreach path,$(BINARY_BUILD_EXECUTE_CLEAN),cp $(path) $(BINARY_TO_DIR)/$(dir $(path)) $(BYNARY_UTILS_NEW_LINE))
BINARY_BUILD_EXECUTE_COPY_ALL := $(BINARY_UTILS_CREATE_DIRS) $(BINARY_BUILD_EXECUTE_COPY)
2017-03-11 22:53:26 +03:00
#********************
# Target options
#***************
all: build
$(BINARY_BUILD_EXECUTE_COPY_ALL)
build: $(BINARY_BUILD_EXECUTE_CLEAN)
clean: $(BINARY_BUILD_MODULES_TARGET_CLEAN)
$(BINARY_BUILD_EXECUTE_TO_CLEAN)
$(BINARY_BUILD_DIRS_TO_CLEAN)
copy:
$(BINARY_BUILD_EXECUTE_COPY_ALL)
.PHONY: all copy clean $(BINARY_BUILD_MODULES_TARGET_ALL)