| # main make rules for Marvell telephony |
| # this file is for generic linux. for Adnroid just see Android.mk makefiles |
| |
| #version -0.1 |
| #author - Chen Reichbach |
| |
| #for debug, remove this to see all compiler outputs. |
| #MRVL_HIDE=@ |
| |
| #general make rules |
| #-------------------- |
| #include $(BUILDROOT)/.config |
| |
| #compiler definisions |
| ifneq "$(CROSS_COMPILE)" "" |
| AS := $(CROSS_COMPILE)as |
| CC := $(CROSS_COMPILE)gcc |
| CPP := $(CROSS_COMPILE)c++ |
| AR := $(CROSS_COMPILE)ar rv |
| LD := $(CROSS_COMPILE)ld |
| STRIP := $(CROSS_COMPILE)strip |
| RANLIB := $(CROSS_COMPILE)ranlib |
| else |
| #we do not have $(CROSS_COMPILE), assume compilers were passed by caller. |
| #echo "WARNING: did not get CROSS_COMPILE" |
| endif |
| |
| #define base path for build objects |
| ifeq "$(OBJ_DIR)" "" |
| OBJ_DIR := $(BUILDROOT)/obj |
| endif |
| SYMBOLS_DIR := $(OBJ_DIR)/symbol |
| #define base path for build outputs |
| ifeq "$(INSTALL_DIR)" "" |
| INSTALL_DIR := $(BUILDROOT)/out |
| endif |
| #usefull paths: |
| PXA_SRC_DIR := $(BUILDROOT) |
| PXA_APPS_DIR := $(BUILDROOT) |
| PXA_SCRIPTS_DIR := $(BUILDROOT)/scripts |
| PXA_CONFIG_DIR := $(BUILDROOT)/configuration |
| PXA_PREPASS_DIR := $(PXA_APPS_DIR)/prepass |
| PXA_TARGET_OLIB := $(OBJ_DIR)/olibs |
| PXA_GENERATED_FILES_DIR := $(OBJ_DIR)/gendir |
| |
| #start off with flags from user and then add spesific flags |
| COMMONCFLAGS := $(EXTRA_CFLAGS) |
| |
| #warnings flags |
| WARNINGFLAG += -Waggregate-return -Wmissing-noreturn -W -Wall -Wextra \ |
| -Winit-self -Wformat -Wformat-nonliteral -Wformat-security \ |
| -Wmissing-declarations -Wpointer-arith |
| |
| #set warnings as errors |
| #WARNINGFLAG += -Werror |
| |
| COMMONCFLAGS += $(WARNINGFLAG) |
| |
| #Other flags |
| SHAREDOBJFLAGS := -shared -Wl,-shared,-Bsymbolic -Wl,--no-undefined |
| |
| # Always generate debug info. This is stripped from the executable files |
| # in the final target image. The size of stripped image with and without -g |
| # is the same, so code generation is not affected. |
| COMMONCFLAGS += -g |
| |
| # Enable optimization: default is very inefficient. |
| #COMMONCFLAGS += -Os \ |
| # -fomit-frame-pointer \ |
| # -fno-strict-aliasing |
| |
| MRVL_COMMON_INCLUDE = -I$(PXA_APPS_DIR)/include \ |
| -I$(PXA_APPS_DIR)/common/pxa_dbg/inc |
| |
| PXA_LD_FLAGS = $(LD_FLAGS) |
| #PXA_LD_FLAGS += -L$(PXA_TARGET_OLIB) \ |
| # -L$(MRVLDIR)/services/android_wrapper/obj |
| |
| #start CFLAGS here |
| CFLAGS:= |
| CFLAGS += -DNOT_DROPPED_FLAGS_TEST |
| |
| not_droped_flags_test = \ |
| echo '$(CFLAGS)' | grep -q NOT_DROPPED_FLAGS_TEST || \ |
| (\ |
| echo "@@================================================@@"&&\ |
| echo NOT_DROPPED_FLAGS_TEST Failed &&\ |
| echo It means that $@ file compiled with broken CFLAGS &&\ |
| echo Please review related Makefile &&\ |
| echo Note that original CFLAGS come from telephony main Makefile &&\ |
| echo "@@================================================@@"&&\ |
| exit 2 ;\ |
| ) && |
| |
| CFLAGS += $(COMMONCFLAGS) |
| CFLAGS += $(MRVL_COMMON_INCLUDE) |
| #temp flags to pass build without android |
| CFLAGS += -DPROPERTY_VALUE_MAX=4 |
| |
| # Bellow test_cmd_line Rule required for testing compiler lines to always happen |
| # i.e. during every make run - we need to test per every object if his CMD line get changed |
| .PHONY: test_cmd_line |
| |
| # Special rules for forceing linker to always run |
| .PHONY: alwayslink |
| |
| # Rule for copy binary output and strip it from debug info. |
| # $(1) - file to be copied |
| # $(2) - relative path to output dir to copy to |
| # Usage: $(call copy_elf,file,dir) |
| # |
| # copies file to <out>/symbols/dir |
| # strips debug info from file and copies the product into <out>/dir |
| # note the --strip-unneeded --discard-locals options are required otherwise |
| # .ko produced have no symbols that are required for relocation and linkage with other .ko's |
| copy_elf = $(call __copy_elf__,$(strip $(1)),$(strip $(2))) |
| |
| __copy_elf__ = \ |
| $(MRVL_HIDE)echo '\033[1;35m'"Installing $(1)"'\033[0m' && \ |
| mkdir -p $(SYMBOLS_DIR)/$(2) $(INSTALL_DIR)/$(2) && \ |
| cp -f $(1) $(SYMBOLS_DIR)/$(2) && \ |
| cp -f $(1) $(INSTALL_DIR)/$(2) && \ |
| $(STRIP) --strip-unneeded --discard-locals $(INSTALL_DIR)/$(2)/$(notdir $(1)) ; |
| |
| #Rule for simple target clean |
| # $(1) - binary to clean (dtarget) |
| # $(2) - location in install dir |
| clean_target = $(call __clean_target__, $(notdir $(1)), $(strip $(2))) |
| |
| __clean_target__ = \ |
| $(MRVL_HIDE)echo '\033[1;35m'"cleaning $(1)"'\033[0m' && \ |
| rm -rf $(SYMBOLS_DIR)/$(2)/$(1) && \ |
| rm -rf $(INSTALL_DIR)/$(2)/$(1) && \ |
| rm -rf $(LOCAL_BUILD_DIR); |
| |
| # |
| ## create generic rule for generation a local build directory. |
| ## $(1) - name of the local build directory. |
| # |
| define define-local-build-dir |
| $(eval $(call __define-local-build-dir__,$(strip $(1)))) |
| endef |
| |
| define __define-local-build-dir__ |
| LOCAL_BUILD_DIR := $(OBJ_DIR)/$(1) |
| $(OBJ_DIR)/$(1): |
| $(MRVL_HIDE)mkdir -p $(OBJ_DIR)/$(1) |
| endef |
| |
| # Automatic Rules generator for any .c, .cpp, or .S files |
| # |
| # User required to define LOCAL_BUILD_DIR prior to calling this function |
| # As well as defining rule for constructing LOCAL_BUILD_DIR |
| # Input parameters: |
| # $(1) - base name of "all results" |
| # $(2) - Source file (.c|.cpp|.S) |
| # $(3) - Extra CFLAGS for this file compilation |
| # |
| # Example with explanation: |
| #### define directory where the compilation objects will be created |
| # $(eval $(call define-local-build-dir, obj)) |
| #### Define final result - e.g. executable test_app |
| # dtarget := test_app |
| # all: $(dtarget) |
| #### Call to virtual rule creator it will define per object |
| #### rules and also fill |
| #### test_app_oo with a list of $(LOCAL_BUILD_DIR)/<source_file_name>.o |
| #### test_app_ii with a list of $(LOCAL_BUILD_DIR)/<source_file_name>.i (needed for Diag aware applications) |
| #### test_app_dd with a list of $(LOCAL_BUILD_DIR)/<source_file_name>.d (for getting build dependencies) |
| # $(eval $(call add-many-objects-rule, test_app , <source files separated by space (' ')>, -D<specific flags>,)) |
| # $(dtarget): $(test_app_ii) $(test_app_oo) |
| # $(CC) -o $@ $(test_app_oo) |
| ### $(test_app_dd) is a dependency files which we include by Makefile |
| # ifeq "$(filter clean install,$(MAKECMDGOALS))" "" |
| # include $(test_app_dd) |
| # endif |
| # |
| define add-many-objects-rule |
| $(foreach i,$(strip $(2)),$(eval $(call __add-object-rule__,$(strip $(1)),$(i),$(strip $(3)),))) |
| endef |
| |
| define __add-object-rule__ |
| ifeq "$(suffix $(2))" ".c" |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) : $(2) test_cmd_line | $(LOCAL_BUILD_DIR) |
| @echo '$(CC) $(CFLAGS) $(3) -c -o $$(basename $$@).o $$<' | cmp -s - $$@ || \ |
| echo '$(CC) $(CFLAGS) $(3) -c -o $$(basename $$@).o $$<' > $$@; |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o) : $(2) $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) | $(LOCAL_BUILD_DIR) |
| @echo " CC $$< " |
| $(MRVL_HIDE)$(not_droped_flags_test)$(CC) $(CFLAGS) $(3) -c -o $$@ $$< |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i.cmd) : $(2) test_cmd_line | $(LOCAL_BUILD_DIR) |
| @echo '$(CC) $(CFLAGS) $(3) -C -E -o $$(basename $$@).i $$<' | cmp -s - $$@ || \ |
| echo '$(CC) $(CFLAGS) $(3) -C -E -o $$(basename $$@).i $$<' > $$@ |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i) : $(2) $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i.cmd) | $(LOCAL_BUILD_DIR) |
| @echo " II $$@" |
| $(MRVL_HIDE)$(not_droped_flags_test)$(CC) $(CFLAGS) -DDIAG_API_H $(3) -C -E -o $$@ $$< |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).d) : $(2) | $(LOCAL_BUILD_DIR) |
| @echo " DD $$@" |
| $(MRVL_HIDE)set -e; rm -f $$@ 2>&- || true ;\ |
| $(CC) -M $(CFLAGS) $(3) $$< > $$@.temp; \ |
| awk '{gsub(/([^:]*:)/,"$$(@:.d=.o) $$(@:.d=.i) $$@ : ",$$$$0); print $$$$0}' > $$@ < $$@.temp ;\ |
| rm $$@.temp 2>&- || true |
| |
| endif |
| ifeq "$(suffix $(2))" ".cpp" |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) : $(2) test_cmd_line | $(LOCAL_BUILD_DIR) |
| @echo '$(CPP) $(CFLAGS) $(3) -c -o $$(basename $$@).o $$<' | cmp -s - $$@ || \ |
| echo '$(CPP) $(CFLAGS) $(3) -c -o $$(basename $$@).o $$<' > $$@ |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o) : $(2) $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) | $(LOCAL_BUILD_DIR) |
| @echo " CPP $$<" |
| $(MRVL_HIDE)$(not_droped_flags_test)$(CPP) $(CFLAGS) $(3) -c -o $$@ $$< |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i.cmd) : $(2) test_cmd_line | $(LOCAL_BUILD_DIR) |
| @echo '$(CPP) $(CFLAGS) $(3) -C -E -o $$(basename $$@).i $$<' | cmp -s - $$@ || \ |
| echo '$(CPP) $(CFLAGS) $(3) -C -E -o $$(basename $$@).i $$<' > $$@ |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i) : $(2) $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i.cmd) | $(LOCAL_BUILD_DIR) |
| @echo " II $$@" |
| $(MRVL_HIDE)$(not_droped_flags_test)$(CPP) $(CFLAGS) -DDIAG_API_H $(3) -C -E -o $$@ $$< |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).d) : $(2) | $(LOCAL_BUILD_DIR) |
| @echo " DD $$@" |
| $(MRVL_HIDE)set -e; rm -f $$@ 2>&- || true ;\ |
| $(CPP) -M $(CFLAGS) $(3) $$< > $$@.temp; \ |
| awk '{gsub(/([^:]*:)/,"$$(@:.d=.o) $$(@:.d=.i) $$@ : ",$$$$0); print $$$$0}' > $$@ < $$@.temp ;\ |
| rm $$@.temp 2>&- || true |
| endif |
| ifeq "$(suffix $(2))" ".S" |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) : $(2) test_cmd_line | $(LOCAL_BUILD_DIR) |
| @echo '$(AS) $(AFLAGS) -o $$(basename $$@).i $$<' | cmp -s - $$@ || \ |
| echo '$(AS) $(AFLAGS) -o $$(basename $$@).i $$<' > $$@ |
| |
| $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o) : $(2) $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o.cmd) | $(LOCAL_BUILD_DIR) |
| @echo " AS $$<" |
| $(MRVL_HIDE)$(AS) $(AFLAGS) -o $$@ $$< |
| endif |
| |
| $(1)_oo += $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).o) |
| ## |
| ## No need to accumulate .i or .d files for assembler input |
| ## |
| ifneq "$(suffix $(2))" ".S" |
| $(1)_ii += $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).i) |
| $(1)_dd += $(LOCAL_BUILD_DIR)/$(notdir $(basename $(2)).d) |
| endif |
| |
| endef |
| #end Automatic Rules generator |