integrated the configuration file system and generate only one configuration

This commit is contained in:
Edouard Dupin 2012-08-31 16:47:49 +02:00
parent d606d2a42f
commit cd149be3fd
4 changed files with 98 additions and 248 deletions

View File

@ -11,12 +11,7 @@
CONF := KCONFIG_NOTIMESTAMP=1 $(call fullpath,$(BUILD_SYSTEM)/conf)
QCONF := KCONFIG_NOTIMESTAMP=1 $(call fullpath,$(BUILD_SYSTEM)/qconf)
# Directory where original configurations are stored
CONFIG_ORIG_DIR := $(TARGET_CONFIG_DIR)
# File where global configuration is stored
CONFIG_GLOBAL_FILE := $(CONFIG_ORIG_DIR)/global.config
-include $(CONFIG_GLOBAL_FILE)
###############################################################################
## Begin conf/qconf by copying configuration file to a temp .config file.
@ -47,11 +42,9 @@ __end-conf = \
__exec-conf = (cd $$(dirname $${__tmpconf}) && $(CONF) $2 $1);
__exec-qconf = (cd $$(dirname $${__tmpconf}) && $(QCONF) $2 $1);
###############################################################################
## Get the name of the configuration file of a module.
## $1 : module name.
###############################################################################
__get_module-config = $(CONFIG_ORIG_DIR)/$1.config
#TODO : REMOVED
#__get_module-config = $(CONFIG_ORIG_DIR)/$1.config
###############################################################################
## Get the list of path to Config.in files of a module.
@ -82,10 +75,10 @@ __end-diff = \
fi;
###############################################################################
## Generate Config.in for global configuration.
## Generate Config configuration for all librairies.
## $1 : destination file.
###############################################################################
define __generate-config-in-global
define __generate-config
rm -f $1; \
mkdir -p $(dir $1); \
touch $1; \
@ -98,26 +91,20 @@ define __generate-config-in-global
echo " help" >> $1; \
echo " Build $(__mod)" >> $1; \
) \
echo "endmenu" >> $1;
endef
###############################################################################
## Generate Config.in for one module.
## $1 : destination file.
## $2 : module name.
## $3 : list of path to Config.in files.
###############################################################################
define __generate-config-in-module
rm -f $1; \
mkdir -p $(dir $1); \
touch $1; \
echo "menu $2" >> $1; \
$(if $(strip $3), \
$(foreach __f,$3, \
echo "source $(call fullpath,$(__f))" >> $1; \
) \
) \
echo "endmenu" >> $1;
echo "endmenu" >> $1; \
$(foreach __mod,$(__modules), \
$(eval __build := BUILD_$(call get-define,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" != "" ]; then \
echo "if $(__build)" >> $1; \
echo " menu $(__mod)" >> $1; \
$(foreach __f,$(__files), \
echo " source $(call fullpath,$(__f))" >> $1; \
) \
echo " endmenu" >> $1; \
echo "endif" >> $1; \
fi; \
)
endef
###############################################################################
@ -167,43 +154,46 @@ define __check-config
endef
###############################################################################
## Load configuration of a module.
## Generate autoconf.h file from config file.
## $1 : input config file.
## $2 : output autoconf.h file.
##
## Remove CONFIG_ prefix.
## Remove CONFIG_ in commented lines.
## Put lines begining with '#' between '/*' '*/'.
## Replace 'key=value' by '#define key value'.
## Replace leading ' y' by ' 1'.
## Remove leading and trailing quotes from string.
## Replace '\"' by '"'.
###############################################################################
# Do NOT check the config if a config is explicitely requested
define __load-config-internal
$(eval __config := $(call __get_module-config,$1))
-include $(__config)
ifeq ("$(findstring config,$(MAKECMDGOALS))","")
$(__config): __config-modules-check-$1
endif
define generate-autoconf-file
echo "Generating $(call path-from-top,$2) from $(call path-from-top,$1)"; \
mkdir -p $(dir $2); \
sed \
-e 's/^CONFIG_//' \
-e 's/^\# CONFIG_/\# /' \
-e 's/^\#\(.*\)/\/*\1 *\//' \
-e 's/\(.*\)=\(.*\)/\#define \1 \2/' \
-e 's/ y$$/ 1/' \
-e 's/\"\(.*\)\"/\1/' \
-e 's/\\\"/\"/g' \
$1 > $2;
endef
###############################################################################
## Load configuration of a module.
## Simply evaluate a call to simplify job of caller.
###############################################################################
load-config = $(eval $(call __load-config-internal,$(LOCAL_MODULE)))
###############################################################################
## Rules.
###############################################################################
# Update everything
.PHONY: config-update
config-update: config-global-update config-modules-update
# Check everything
.PHONY: config-check
config-check: config-global-check config-modules-check
# File where global configuration is stored
CONFIG_GLOBAL_FOLDER := $(shell pwd)/config
CONFIG_GLOBAL_FILE := $(CONFIG_GLOBAL_FOLDER)/$(TARGET_OS)_$(BUILD_DIRECTORY_MODE).config
# Display the global configuration
.PHONY: config-global
config-global:
.PHONY: config
config:
@( \
__tmpconfigin=$$(mktemp); \
$(eval __config := $(CONFIG_GLOBAL_FILE)) \
$(call __generate-config-in-global,$${__tmpconfigin}) \
$(call __generate-config,$${__tmpconfigin}) \
$(call __begin-conf,$(__config)) \
$(call __exec-qconf,$${__tmpconfigin}) \
$(call __end-conf,$(__config)) \
@ -211,122 +201,39 @@ config-global:
)
# Update the global configuration by selecting new option at their default value
.PHONY: config-global-update
config-global-update:
.PHONY: config-update
config-update:
@( \
__tmpconfigin=$$(mktemp); \
$(eval __config := $(CONFIG_GLOBAL_FILE)) \
$(call __generate-config-in-global,$${__tmpconfigin}) \
$(call __generate-config,$${__tmpconfigin}) \
$(call __update-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
)
# Check the global configuration
.PHONY: config-global-check
config-global-check:
.PHONY: config-check
config-check:
@( \
__tmpconfigin=$$(mktemp); \
$(eval __config := $(CONFIG_GLOBAL_FILE)) \
$(call __generate-config-in-global,$${__tmpconfigin}) \
$(call __generate-config,$${__tmpconfigin}) \
$(call __check-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
)
@echo "Global configuration is up to date";
# Update all module configurations by selecting new option at their default value
.PHONY: config-modules-update
config-modules-update:
@( \
$(foreach __mod,$(__modules), \
$(eval __config := $(call __get_module-config,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" != "" ]; then \
__tmpconfigin=$$(mktemp); \
$(call __generate-config-in-module,$${__tmpconfigin},$(__mod),$(__files)) \
$(call __update-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
fi; \
) \
)
# create basic folder :
$(shell mkdir -p $(CONFIG_GLOBAL_FOLDER))
# check if config exist :
# TODO ...
-include $(CONFIG_GLOBAL_FILE)
# Update a specific module configuration by selecting new option at their default value
.PHONY: config-modules-update-%
config-modules-update-%:
@( \
$(eval __mod := $*) \
$(eval __config := $(call __get_module-config,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" != "" ]; then \
__tmpconfigin=$$(mktemp); \
$(call __generate-config-in-module,$${__tmpconfigin},$(__mod),$(__files)) \
$(call __update-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
fi; \
)
#automatic generation of the config file when not existed (default case):
#.PHONY: $(CONFIG_GLOBAL_FILE)
#$(CONFIG_GLOBAL_FILE): config-update
# echo "generating basic confing .. please restart"
# Check if module configurations are OK
.PHONY: config-modules-check
config-modules-check: __config-modules-check
@echo "Modules configuration are up to date";
# Internal version with no message
.PHONY: __config-modules-check
__config-modules-check:
@( \
$(call __begin-diff) \
$(foreach __mod,$(__modules), \
$(eval __config := $(call __get_module-config,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" != "" ]; then \
__tmpconfigin=$$(mktemp); \
$(call __generate-config-in-module,$${__tmpconfigin},$(__mod),$(__files)) \
$(call __check-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
fi; \
) \
$(call __end-diff,1) \
)
# Check if a specific module configuration is OK
.PHONY: config-modules-check-%
config-modules-check-%: __config-modules-check-%
$(eval __mod := $*)
@echo "Configuration of $(__mod) is up to date";
# Internal version with no message
.PHONY: __config-modules-check-%
__config-modules-check-%:
@( \
$(call __begin-diff) \
$(eval __mod := $*) \
$(eval __config := $(call __get_module-config,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" != "" ]; then \
__tmpconfigin=$$(mktemp); \
$(call __generate-config-in-module,$${__tmpconfigin},$(__mod),$(__files)) \
$(call __check-config,$${__tmpconfigin},$(__config)) \
rm -f $${__tmpconfigin}; \
fi; \
$(call __end-diff,1) \
)
# Configure a module specifically
.PHONY: config-modules-%
config-modules-%:
@( \
$(eval __mod := $*) \
$(eval __config := $(call __get_module-config,$(__mod))) \
$(eval __files := $(call __get_module-config-in-files,$(__mod))) \
if [ "$(__files)" == "" ]; then \
echo "Nothing to configure for $(__mod)"; \
else \
__tmpconfigin=$$(mktemp); \
$(call __generate-config-in-module,$${__tmpconfigin},$(__mod),$(__files)) \
$(call __begin-conf,$(__config)) \
$(call __exec-qconf,$${__tmpconfigin}) \
$(call __end-conf,$(__config)) \
rm -f $${__tmpconfigin}; \
echo "Configuration of $(__mod) saved in $(__config)"; \
fi; \
)
$(CONFIG_GLOBAL_FILE):
@#$(e rror "need to generate config : make ... config")

View File

@ -398,18 +398,6 @@ module-get-listed-export = \
$(call module-get-export,$(__mod),$2) \
))
# Return the autoconf.h file, if any, for module $1.
# $1 : module name.
module-get-autoconf = \
$(if $(__modules.$1.CONFIG_FILES),$(TARGET_OUT_BUILD)/$1/autoconf-$1.h)
# Return the autoconf.h files, if any, for modules listed in $1.
# $1 : list of module names.
module-get-listed-autoconf = \
$(strip $(foreach __mod,$1, \
$(call module-get-autoconf,$(__mod)) \
))
###############################################################################
## Dependency management
###############################################################################
@ -468,34 +456,6 @@ module-get-build-filename = \
module-get-staging-filename = \
$(if $(__modules.$1.MODULE_FILENAME), $(TARGET_OUT_STAGING)/$(__modules.$1.DESTDIR)/$(__modules.$1.MODULE_FILENAME) )
###############################################################################
## Generate autoconf.h file from config file.
## $1 : input config file.
## $2 : output autoconf.h file.
##
## Remove CONFIG_ prefix.
## Remove CONFIG_ in commented lines.
## Put lines begining with '#' between '/*' '*/'.
## Replace 'key=value' by '#define key value'.
## Replace leading ' y' by ' 1'.
## Remove leading and trailing quotes from string.
## Replace '\"' by '"'.
###############################################################################
define generate-autoconf-file
echo "Generating $(call path-from-top,$2) from $(call path-from-top,$1)"; \
mkdir -p $(dir $2); \
sed \
-e 's/^CONFIG_//' \
-e 's/^\# CONFIG_/\# /' \
-e 's/^\#\(.*\)/\/*\1 *\//' \
-e 's/\(.*\)=\(.*\)/\#define \1 \2/' \
-e 's/ y$$/ 1/' \
-e 's/\"\(.*\)\"/\1/' \
-e 's/\\\"/\"/g' \
$1 > $2;
endef
###############################################################################
## Normalize a list of includes. It adds -I if needed.
## $1 : list of includes

View File

@ -27,8 +27,6 @@ W := 0
DEBUG := 0
# compilation done with Clang system instead of gcc
CLANG := 0
# for openGL : enable the open GL ES 2 or the Shader system for normal system
SHADER := 0
# Quiet command if V is 0
ifeq ("$(V)","0")
@ -57,6 +55,12 @@ my-dir = $(call fullpath,$(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))))
TOP_DIR := $(shell pwd)
BUILD_SYSTEM := $(call my-dir)
ifeq ("$(DEBUG)","1")
BUILD_DIRECTORY_MODE := debug
else
BUILD_DIRECTORY_MODE := release
endif
# Setup configuration
include $(BUILD_SYSTEM)/setup-host.mk
include $(BUILD_SYSTEM)/setup-target.mk
@ -79,19 +83,10 @@ BUILD_RULES := $(BUILD_SYSTEM)/rules.mk
###############################################################################
## Makefile scan and includes.
###############################################################################
ifeq ("$(DEBUG)","1")
BUILD_DIRECTORY_MODE := debug
else
BUILD_DIRECTORY_MODE := release
endif
ifeq ("$(SHADER)","1")
BUILD_DIRECTORY_SHADER := ogl2
else
BUILD_DIRECTORY_SHADER := ogl1
endif
TARGET_OUT_BUILD ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/$(BUILD_DIRECTORY_SHADER)/obj
TARGET_OUT_STAGING ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/$(BUILD_DIRECTORY_SHADER)/staging
TARGET_OUT_FINAL ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/$(BUILD_DIRECTORY_SHADER)/final
TARGET_OUT_BUILD ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/obj
TARGET_OUT_STAGING ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/staging
TARGET_OUT_FINAL ?= $(shell pwd)/out/$(TARGET_OS)/$(BUILD_DIRECTORY_MODE)/final
# Makefile with the list of all makefiles available and include them
SCAN_TARGET := scan
@ -134,6 +129,19 @@ $(call modules-check-depends)
# Check variables of modules
$(call modules-check-variables)
###############################################################################
# Rule to merge autoconf.h files.
###############################################################################
# Concatenate all in one
AUTOCONF_FILE := $(TARGET_OUT_BUILD)/autoconf.h
$(AUTOCONF_FILE): $(CONFIG_GLOBAL_FILE)
@echo "Generating autoconf-merge.h"
@mkdir -p $(dir $@)
@rm -f $@
@$(call generate-autoconf-file,$^,$@)
# Now, really generate rules for modules.
# This second pass allows to deal with exported values.
$(foreach __mod,$(__modules), \
@ -141,21 +149,6 @@ $(foreach __mod,$(__modules), \
$(eval include $(BUILD_SYSTEM)/module.mk) \
)
###############################################################################
# Rule to merge autoconf.h files.
###############################################################################
# List of all available autoconf.h files
__autoconf-list := $(foreach __mod,$(__modules),$(call module-get-autoconf,$(__mod)))
# Concatenate all in one
AUTOCONF_MERGE_FILE := $(TARGET_OUT_BUILD)/autoconf-merge.h
$(AUTOCONF_MERGE_FILE): $(__autoconf-list)
@echo "Generating autoconf-merge.h"
@mkdir -p $(dir $@)
@rm -f $@
@for f in $^; do cat $$f >> $@; done
###############################################################################
# Main rules.
###############################################################################
@ -164,6 +157,8 @@ $(AUTOCONF_MERGE_FILE): $(__autoconf-list)
ALL_MODULES := \
$(foreach __mod,$(__modules),$(__mod))
#TODO check this ...
# All module to actually build
ALL_BUILD_MODULES := \
$(foreach __mod,$(__modules), \
@ -171,7 +166,7 @@ ALL_BUILD_MODULES := \
# TODO : Set ALL_BUILD_MODULES ==> find the end point module (SHARED/BINARY)
.PHONY: all
all: $(ALL_MODULES) $(AUTOCONF_MERGE_FILE)
all: $(ALL_MODULES)
.PHONY: clean
clean: $(foreach __mod,$(ALL_MODULES),clean-$(__mod))

View File

@ -143,13 +143,14 @@ LOCAL_C_INCLUDES := $(sort $(strip $(subst -I-I,-I,$(addprefix -I,$(LOCAL_C_INCL
# dependees on final link command).
LOCAL_LDLIBS := $(strip $(LOCAL_LDLIBS) $(LOCAL_EXPORT_LDLIBS) $(imported_LDLIBS))
# Get all autoconf files that we depend on, don't forget to add ourself
all_autoconf := \
$(call module-get-listed-autoconf,$(all_depends)) \
$(call module-get-autoconf,$(LOCAL_MODULE))
# Get autoconf files only if we depend oursef or dependent librairies does ...
#TODO
has_autoconf := $(AUTOCONF_FILE)
# $(call module-get-listed-autoconf,$(all_depends)) \
# $(call module-get-autoconf,$(LOCAL_MODULE))
# Force their inclusion (space after -include and before comma is important)
LOCAL_CFLAGS += $(addprefix -include ,$(all_autoconf))
LOCAL_CFLAGS += $(addprefix -include ,$(has_autoconf))
# List of all prerequisites (ours + dependencies)
all_prerequisites := \
@ -158,7 +159,7 @@ all_prerequisites := \
$(imported_PREREQUISITES)
# All autoconf files are prerequisites
all_prerequisites += $(all_autoconf)
all_prerequisites += $(has_autoconf)
# User makefile is also a prerequisite
all_prerequisites += $(LOCAL_PATH)/$(USER_MAKEFILE_NAME)
@ -222,19 +223,6 @@ ifneq ("$(all_prerequisites)","")
$(all_objects): $(all_prerequisites)
endif
###############################################################################
## autoconf.h file generation.
###############################################################################
autoconf_file := $(call module-get-autoconf,$(LOCAL_MODULE))
ifneq ("$(autoconf_file)","")
# autoconf.h file depends on module config
$(autoconf_file): $(call __get_module-config,$(LOCAL_MODULE))
@$(call generate-autoconf-file,$<,$@)
endif
###############################################################################
## Precompiled headers.
###############################################################################