[IMPROVE] new Kbuild for swap_energy module
authorVyacheslav Cherkashin <v.cherkashin@samsung.com>
Fri, 8 Nov 2013 11:20:57 +0000 (15:20 +0400)
committerGerrit Code Review <gerrit@gerrit.vlan144.tizendev.org>
Tue, 12 Nov 2013 08:38:45 +0000 (08:38 +0000)
implement generation defines
Signed-off-by: Vyacheslav Cherkashin <v.cherkashin@samsung.com>
Change-Id: I800e3557c54fc1ea09834c29cc26547b71820c91

energy/Kbuild

index b59abb3..4ead3e7 100644 (file)
@@ -3,6 +3,13 @@ KBUILD_EXTRA_SYMBOLS = $(src)/../kprobe/Module.symvers \
                        $(src)/../us_manager/Module.symvers \
                        $(src)/../driver/Module.symvers
 
+
+
+
+
+###############################################################################
+###                      swap energy module description                     ###
+###############################################################################
 obj-m := swap_energy.o
 swap_energy-y := energy_module.o \
                  energy.o \
@@ -10,15 +17,126 @@ swap_energy-y := energy_module.o \
                  lcd/lcd_base.o
 
 
+
+
+
+###############################################################################
+###                      description register functions                     ###
+###############################################################################
+REG_ARGS := void
+REG_RET := void
+
+
+
+
+
+###############################################################################
+###                     description unregister functions                    ###
+###############################################################################
+UNREG_ARGS := void
+UNREG_RET := void
+
+
+
+
+
+###############################################################################
+###                               math support                              ###
+###############################################################################
 # S6E8AA0:
 ifeq ($(CONFIG_LCD_S6E8AA0), y)
        swap_energy-y += lcd/s6e8aa0.o
-       EXTRA_CFLAGS += -DCONFIG_ENEGRGY_LCD
+
+       REG_FUNC_LIST += s6e8aa0_register
+       UNREG_FUNC_LIST += s6e8aa0_unregister
 endif
 
 
 # MARU:
 ifeq ($(CONFIG_MARU_BACKLIGHT), y)
        swap_energy-y += lcd/maru.o
-       EXTRA_CFLAGS += -DCONFIG_ENEGRGY_LCD
+
+       REG_FUNC_LIST += maru_register
+       UNREG_FUNC_LIST += maru_unregister
 endif
+
+
+
+
+
+###############################################################################
+###               generate defines for un/register functions                ###
+###############################################################################
+EMPTY :=
+SPACE := $(EMPTY) $(EMPTY)
+COMMA := ,
+
+
+
+
+
+###############################################################################
+###                generate defines for register functions                  ###
+###############################################################################
+TMP := ($(REG_ARGS));
+DEFINITION_REG_FUNC := DEFINITION_REG_FUNC=$(foreach it, $(REG_FUNC_LIST), "extern" $(REG_RET) $(it)$(TMP))
+
+ifeq (void,$(REG_ARGS))
+       REG_ARGS :=
+endif
+
+TMP := $(subst $(SPACE),$(EMPTY),$(REG_ARGS))   # remove space
+TMP := $(subst $(COMMA), ,$(TMP))               # replace ',' --> ' '
+LAST := $(words $(TMP))
+
+TMP := $(shell seq 1 $(LAST))
+TMP := $(foreach it, $(TMP), "X"$(it))
+TMP := $(strip $(TMP))
+TMP := $(subst $(SPACE),$(COMMA),$(TMP))        # replace ' ' --> ','
+TMP := $(strip $(TMP))
+
+REG_ARG_LIST := $(TMP)
+TMP := ($(REG_ARG_LIST));
+
+CALL_REG_FUNC := REGISTER_ALL_FUNC($(REG_ARG_LIST))={$(foreach it, $(REG_FUNC_LIST), $(it)$(TMP))}
+
+
+
+
+
+###############################################################################
+###               generate defines for unregister functions                 ###
+###############################################################################
+TMP := ($(UNREG_ARGS));
+DEFINITION_UNREG_FUNC := DEFINITION_UNREG_FUNC=$(foreach it, $(UNREG_FUNC_LIST), "extern" $(UNREG_RET) $(it)$(TMP))
+
+ifeq (void, $(UNREG_ARGS))
+       UNREG_ARGS :=
+endif
+
+TMP := $(subst $(SPACE),$(EMPTY),$(UNREG_ARGS)) # remove space
+TMP := $(subst $(COMMA), ,$(TMP))               # replace ',' --> ' '
+LAST := $(words $(TMP))
+
+TMP := $(shell seq 1 $(LAST))
+TMP := $(foreach it, $(TMP), "X"$(it))
+TMP := $(strip $(TMP))
+TMP := $(subst $(SPACE),$(COMMA),$(TMP))        # replace ' ' --> ','
+TMP := $(strip $(TMP))
+
+UNREG_ARG_LIST := $(TMP)
+TMP := ($(UNREG_ARG_LIST));
+
+CALL_UNREG_FUNC := UNREGISTER_ALL_FUNC($(UNREG_ARG_LIST))={$(foreach it, $(UNREG_FUNC_LIST), $(it)$(TMP))}
+
+
+
+
+
+###############################################################################
+###                  add generate defines to EXTRA_CFLAGS                   ###
+###############################################################################
+EXTRA_CFLAGS += -D"$(DEFINITION_REG_FUNC)" \
+                -D"$(CALL_REG_FUNC)" \
+                -D"$(DEFINITION_UNREG_FUNC)" \
+                -D"$(CALL_UNREG_FUNC)"