2016-08-29 00:20:40 +03:00
|
|
|
TARGET := source
|
|
|
|
SRCDIR := source
|
|
|
|
|
|
|
|
CC ?= gcc
|
|
|
|
|
2017-03-09 23:47:39 +03:00
|
|
|
# ARGS
|
|
|
|
#
|
|
|
|
# MODEST_OPTIMIZATION_LEVEL, default -O2
|
2017-03-12 21:49:39 +03:00
|
|
|
# MyCORE_BUILD_WITHOUT_THREADS, YES or (NO or undefined), default undefined
|
|
|
|
# MyCORE_BUILD_DEBUG, default undefined
|
2017-03-09 23:47:39 +03:00
|
|
|
#
|
|
|
|
|
|
|
|
.DEFAULT_GOAL := all
|
2016-08-29 00:20:40 +03:00
|
|
|
|
2017-03-09 23:47:39 +03:00
|
|
|
#********************
|
|
|
|
# other Makefile
|
|
|
|
#***************
|
|
|
|
include Makefile.cfg
|
|
|
|
|
|
|
|
#********************
|
|
|
|
# Build
|
|
|
|
#***************
|
|
|
|
MODEST_BUILD_MODULES ?= $(dir $(wildcard $(SRCDIR)/*/))
|
|
|
|
MODEST_BUILD_MODULES := $(patsubst %myport/,%myport/$(strip $(MODEST_PORT_NAME))/,$(MODEST_BUILD_MODULES))
|
|
|
|
MODEST_BUILD_MODULES_LIST := $(foreach dir,$(MODEST_BUILD_MODULES),$(word 2, $(subst $(MODEST_DIR_SEPARATOR), , $(dir))) )
|
|
|
|
MODEST_BUILD_MODULES_MAKEFILES_LIST := $(foreach dir,$(MODEST_BUILD_MODULES),$(dir)Makefile.mk)
|
|
|
|
|
|
|
|
#********************
|
|
|
|
# Targets
|
|
|
|
#***************
|
|
|
|
MODEST_BUILD_MODULES_TARGET := $(MODEST_BUILD_MODULES_LIST)
|
|
|
|
MODEST_BUILD_MODULES_TARGET_ALL := $(foreach dir,$(MODEST_BUILD_MODULES_TARGET),$(dir)_all)
|
2017-03-11 22:53:26 +03:00
|
|
|
MODEST_BUILD_MODULES_TARGET_CLEAN := $(foreach dir,$(MODEST_BUILD_MODULES_TARGET),$(dir)_clean) $(myport_clean)
|
2017-03-09 23:47:39 +03:00
|
|
|
MODEST_BUILD_MODULES_TARGET_CLONE := $(foreach dir,$(MODEST_BUILD_MODULES_TARGET),$(dir)_clone)
|
|
|
|
|
|
|
|
#********************
|
|
|
|
# Utils
|
|
|
|
#***************
|
|
|
|
MODEST_UTILS_HDRS = $(foreach dir,$2,$(wildcard $(SRCDIR)/$1/$(dir)/*.h))
|
|
|
|
MODEST_UTILS_OBJS = $(patsubst %.c,%.o,$(foreach dir,$2,$(wildcard $(SRCDIR)/$1/$(dir)/*.c)))
|
|
|
|
MODEST_UTILS_HDRS_CLONE_CMND = $(foreach path,$(foreach dir,$2,$(wildcard $(SRCDIR)/$1/$(dir)/*.h)), cp $(path) $(patsubst $(SRCDIR)%,$(INCLUDE_DIR_API)%,$(path)) $(MODEST_UTILS_NEW_LINE))
|
|
|
|
MODEST_UTILS_HDRS_CLONE_GDIR = $(foreach dir,$2,$(INCLUDE_DIR_API)/$1/$(dir)/)
|
|
|
|
MODEST_UTILS_HDRS_CLONE_DIRS = $(foreach dir,$(strip $(patsubst %./,%,$(foreach path,$(call MODEST_UTILS_HDRS_CLONE_GDIR,$1,$2),$(dir $(path))))),mkdir -p $(dir) $(MODEST_UTILS_NEW_LINE))
|
|
|
|
MODEST_UTILS_HDRS_CLONE = $(info Clone for $1) $(call MODEST_UTILS_HDRS_CLONE_DIRS,$1,$2) $(MODEST_UTILS_NEW_LINE) $(call MODEST_UTILS_HDRS_CLONE_CMND,$1,$2)
|
|
|
|
|
|
|
|
#********************
|
|
|
|
# Include all modules Makefile.mk
|
|
|
|
#***************
|
|
|
|
include $(MODEST_BUILD_MODULES_MAKEFILES_LIST)
|
|
|
|
|
|
|
|
#********************
|
|
|
|
# Set ARGS for flags
|
|
|
|
#***************
|
2017-03-12 21:49:39 +03:00
|
|
|
MODEST_CFLAGS += -DMODEST_BUILD_OS=$(MODEST_BUILD_OS)
|
|
|
|
MODEST_CFLAGS += -DMODEST_PORT_NAME=$(MODEST_PORT_NAME)
|
2017-03-15 18:36:30 +03:00
|
|
|
MODEST_CFLAGS += $(call MODEST_UTILS_TO_UPCASE,-DMyCORE_OS_$(MODEST_BUILD_OS))
|
2017-03-12 21:49:39 +03:00
|
|
|
|
2017-03-12 20:23:04 +03:00
|
|
|
override CFLAGS += $(MODEST_CFLAGS)
|
2017-03-13 21:11:34 +03:00
|
|
|
override LDFLAGS += $(MODEST_LDFLAGS)
|
2017-03-09 23:47:39 +03:00
|
|
|
|
|
|
|
#********************
|
|
|
|
# Objects
|
|
|
|
#***************
|
2017-03-10 10:36:54 +03:00
|
|
|
MODEST_BUILD_OBJECT_SHARED ?= $(CC) -shared $(LDFLAGS) $(MODEST_LDFLAGS) $1 -o $2
|
|
|
|
MODEST_BUILD_OBJECT_STATIC ?= $(AR) crus $2 $1
|
2017-03-09 23:47:39 +03:00
|
|
|
MODEST_BUILD_OBJECT_MODULES := $(foreach dir,$(MODEST_BUILD_MODULES_TARGET),$($(dir)_objs))
|
2017-03-15 18:36:30 +03:00
|
|
|
MODEST_BUILD_OBJECT_MODULES := $(foreach dir,$(MODEST_BUILD_MODULES_TARGET),$($(dir)_objs))
|
2017-03-09 23:47:39 +03:00
|
|
|
|
2017-03-13 17:52:50 +03:00
|
|
|
#********************
|
|
|
|
# Sub Directories
|
|
|
|
#***************
|
|
|
|
BUILD_SUB_DIRS := examples $(TEST_DIR)
|
|
|
|
|
2017-03-15 18:36:30 +03:00
|
|
|
#********************
|
|
|
|
# Install
|
|
|
|
#***************
|
|
|
|
MODEST_INSTALL_LIB ?= lib
|
|
|
|
MODEST_INSTALL_HEADER ?= include
|
|
|
|
MODEST_INSTALL_CREATE_DIR := mkdir -p $(PREFIX)/$(MODEST_INSTALL_HEADER) $(PREFIX)/$(MODEST_INSTALL_LIB)
|
|
|
|
MODEST_INSTALL_COMMAND := $(MODEST_INSTALL_CREATE_DIR) $(MODEST_UTILS_NEW_LINE) cp -av $(LIB_DIR_BASE)/* $(PREFIX)/$(MODEST_INSTALL_LIB) $(MODEST_UTILS_NEW_LINE) cp -r $(INCLUDE_DIR_API)/* $(PREFIX)/$(MODEST_INSTALL_HEADER)
|
|
|
|
|
2017-03-09 23:47:39 +03:00
|
|
|
#********************
|
|
|
|
# Target options
|
|
|
|
#***************
|
2017-03-13 17:52:50 +03:00
|
|
|
all: library
|
|
|
|
for f in $(BUILD_SUB_DIRS); do $(MAKE) -C $$f all; done
|
|
|
|
|
|
|
|
library: shared static
|
2017-03-10 10:36:54 +03:00
|
|
|
|
|
|
|
shared: create $(MODEST_BUILD_MODULES_TARGET_ALL)
|
|
|
|
$(call MODEST_BUILD_OBJECT_SHARED,$(MODEST_BUILD_OBJECT_MODULES),$(call MODEST_LIBRARY_WITH_VERSION))
|
2017-03-12 21:04:09 +03:00
|
|
|
$(call MODEST_BUILD_SHARED_AFTER)
|
2017-03-10 10:36:54 +03:00
|
|
|
|
|
|
|
static: create $(MODEST_BUILD_MODULES_TARGET_ALL)
|
2017-03-11 22:53:26 +03:00
|
|
|
$(call MODEST_BUILD_OBJECT_STATIC,$(MODEST_BUILD_OBJECT_MODULES),$(call MODEST_LIBRARY_STATIC))
|
2017-03-12 21:04:09 +03:00
|
|
|
$(call MODEST_BUILD_STATIC_AFTER)
|
2017-03-09 23:47:39 +03:00
|
|
|
|
|
|
|
clean: $(MODEST_BUILD_MODULES_TARGET_CLEAN)
|
2017-03-11 22:53:26 +03:00
|
|
|
rm -f $(call MODEST_LIBRARY_WITH_VERSION) && rm -f $(call MODEST_LIBRARY_STATIC)
|
2017-03-13 17:52:50 +03:00
|
|
|
rm -rf $(TEST_DIR_BASE)
|
2017-03-12 21:04:09 +03:00
|
|
|
$(call MODEST_BUILD_CLEAN_AFTER)
|
2017-03-13 17:52:50 +03:00
|
|
|
for f in $(BUILD_SUB_DIRS); do $(MAKE) -C $$f clean; done
|
2017-03-10 10:36:54 +03:00
|
|
|
|
2017-03-12 21:22:47 +03:00
|
|
|
clone: clean_api $(MODEST_BUILD_MODULES_TARGET_CLONE)
|
2017-03-10 10:36:54 +03:00
|
|
|
find $(INCLUDE_DIR_API) -name "*.h" -exec sed -i '.bak' -E 's/^[ \t]*#[ \t]*include[ \t]*"([^"]+)"/#include <\1>/g' {} \;
|
|
|
|
find $(INCLUDE_DIR_API) -name "*.h.bak" -exec rm -f {} \;
|
2017-03-09 23:47:39 +03:00
|
|
|
|
2017-03-12 21:22:47 +03:00
|
|
|
clean_api:
|
|
|
|
rm -rf $(INCLUDE_DIR_API)
|
|
|
|
|
2017-03-09 23:59:56 +03:00
|
|
|
create:
|
2017-03-13 17:52:50 +03:00
|
|
|
mkdir -p $(BINARY_DIR_BASE) $(LIB_DIR_BASE) $(TEST_DIR_BASE)
|
|
|
|
|
2017-03-15 18:36:30 +03:00
|
|
|
install:
|
|
|
|
$(MODEST_INSTALL_COMMAND)
|
|
|
|
|
|
|
|
test: library
|
2017-03-13 17:52:50 +03:00
|
|
|
$(MAKE) -C $(TEST_DIR) run
|
2017-03-09 23:59:56 +03:00
|
|
|
|
2017-03-13 17:52:50 +03:00
|
|
|
.PHONY: all clean clone test $(MODEST_BUILD_MODULES_TARGET_ALL)
|