Home | History | Annotate | Download | only in make
      1 #
      2 #  Copyright 2001-2009 Texas Instruments - http://www.ti.com/
      3 # 
      4 #  Licensed under the Apache License, Version 2.0 (the "License");
      5 #  you may not use this file except in compliance with the License.
      6 #  You may obtain a copy of the License at
      7 # 
      8 #     http://www.apache.org/licenses/LICENSE-2.0
      9 # 
     10 #  Unless required by applicable law or agreed to in writing, software
     11 #  distributed under the License is distributed on an "AS IS" BASIS,
     12 #  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13 #  See the License for the specific language governing permissions and
     14 #  limitations under the License.
     15 
     16 #
     17 #  dspbridge/mpu_api/make/build.mk
     18 #
     19 #  DSP-BIOS Bridge build rules.
     20 
     21 # ALL PATHS IN MAKEFILE MUST BE RELATIVE TO ITS DIRECTORY
     22 
     23 CDEFS       += $(CMDDEFS) # Add command line definitions
     24 CDEFS       += $(PROCFAMILY) # Processor Family e.g. 3430
     25 CDEFS	    += $(CMDDEFS_START) # Definitions from start.mk
     26 #   ----------------------------------------------------------
     27 #   REMOVE LEADING AND TRAILING SPACES FROM MAKEFILE MACROS
     28 #   ----------------------------------------------------------
     29 
     30 TARGETNAME  := $(strip $(TARGETNAME))
     31 TARGETTYPE  := $(strip $(TARGETTYPE))
     32 SUBMODULES  := $(strip $(SUBMODULES))
     33 SOURCES     := $(strip $(SOURCES))
     34 INCLUDES    := $(strip $(INCLUDES))
     35 LIBINCLUDES := $(strip $(LIBINCLUDES))
     36 
     37 SH_SONAME   := $(strip $(SH_SONAME))
     38 ST_LIBS     := $(strip $(ST_LIBS))
     39 SH_LIBS     := $(strip $(SH_LIBS))
     40 
     41 CFLAGS      := $(strip $(CFLAGS))
     42 CDEFS       := $(strip $(CDEFS))
     43 EXEC_ARGS   := $(strip $(EXEC_ARGS))
     44 ST_LIB_ARGS := $(strip $(ST_LIB_ARGS))
     45 SH_LIB_ARGS := $(strip $(SH_LIB_ARGS))
     46 
     47 #   ----------------------------------------------------------
     48 #   COMPILER OPTIONS
     49 #   ----------------------------------------------------------
     50 
     51 # Preprocessor : dependency file generation
     52 ifndef NODEPENDS
     53 ifndef nodepends
     54 CFLAGS += -MD
     55 endif
     56 endif
     57 
     58 #   Overall
     59 CFLAGS += -pipe
     60 #   Preprocessor
     61 CFLAGS +=
     62 #   Debugging
     63 ifeq ($(BUILD),deb)
     64 CFLAGS += -g
     65 else
     66 CFLAGS += -fomit-frame-pointer
     67 endif
     68 #   Warnings
     69 CFLAGS += -Wall  -Wno-trigraphs -Werror-implicit-function-declaration #-Wno-format
     70 #   Optimizations
     71 #CFLAGS += -O2 -fno-strict-aliasing
     72 #CFLAGS += -Os -fno-strict-aliasing
     73 CFLAGS += -fno-strict-aliasing
     74 #   Machine dependent
     75 
     76 ifeq ($(PROCFAMILY),OMAP_3430)
     77 CFLAGS += -mapcs -mno-sched-prolog -mabi=aapcs-linux -mno-thumb-interwork -march=armv7-a -msoft-float -Uarm -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR($(basename $(TARGETNAME)))" -D"KBUILD_MODNAME=KBUILD_STR($(basename $(TARGETNAME)))"  -DMODULE -D__LINUX_ARM_ARCH__=7 
     78 endif
     79 
     80 ifeq ($(PROCFAMILY),OMAP_4430)
     81 CFLAGS += -mapcs -mno-sched-prolog -mabi=aapcs-linux -mno-thumb-interwork -march=armv7-a -msoft-float -Uarm -D"KBUILD_STR(s)=\#s" -D"KBUILD_BASENAME=KBUILD_STR($(basename $(TARGETNAME)))" -D"KBUILD_MODNAME=KBUILD_STR($(basename $(TARGETNAME)))"  -DMODULE -D__LINUX_ARM_ARCH__=7
     82 endif
     83 
     84 #   Code generation
     85 CFLAGS += -fno-common
     86 #   Macros
     87 CFLAGS += -DLINUX $(addprefix -D, $(CDEFS))
     88 
     89 ifdef __KERNEL__
     90 CFLAGS      += -D__KERNEL__  -fno-builtin
     91 endif
     92 
     93 #   ----------------------------------------------------------
     94 #   OBJECTS
     95 #   ----------------------------------------------------------
     96 
     97 BUILDDIR    = .obj/
     98 
     99 # setup the target - check the given type - make sure we have the
    100 # correct suffix on it
    101 # TARGETNAME should not have a suffix on it - give an error if it does
    102 #ifneq ($(suffix $(TARGETNAME)),)
    103 #   $(error TARGETNAME can not have a suffix)
    104 #endif
    105 ifeq ($(TARGETTYPE),SH_LIB)
    106    TARGET      := $(basename $(TARGETNAME)).so
    107 else
    108 ifeq ($(TARGETTYPE),MODULE)
    109    TARGET      := $(basename $(TARGETNAME)).o
    110    TARGETKO    := $(addsuffix .ko,$(basename $(TARGET)))
    111    TARGETMOD   := $(addsuffix .mod,$(basename $(TARGET)))
    112 else
    113 ifeq ($(TARGETTYPE),ST_LIB)
    114    TARGET      := $(basename $(TARGETNAME)).a
    115 else
    116 ifeq ($(TARGETTYPE),EXEC)
    117    TARGET      := $(basename $(TARGETNAME)).out
    118 else
    119 ifneq ($(TARGETTYPE),)
    120 TARGET         := $(error Invalid TARGETTYPE)
    121 endif
    122 endif
    123 endif
    124 endif
    125 endif
    126 
    127 #LIBINCLUDES += $(TARGETDIR) $(TGTROOT)/lib $(TGTROOT)/usr/lib
    128 LIBINCLUDES += $(TARGETDIR)/lib $(TARGETDIR)/usr/lib 
    129 SRCDIRS :=  $(sort $(dir $(SOURCES)))
    130 OBJDIRS :=  $(addprefix $(BUILDDIR),$(SRCDIRS)) $(BUILDDIR)
    131 
    132 BASEOBJ := $(addsuffix .o,$(basename $(SOURCES)))
    133 OBJECTS := $(addprefix $(BUILDDIR), $(BASEOBJ))
    134 
    135 ST_LIBNAMES := $(addsuffix .a, $(addprefix lib, $(ST_LIBS)))
    136 DL_LIBNAMES := $(addsuffix .so, $(addprefix lib, $(SH_LIBS)))
    137 
    138 vpath %.a $(LIBINCLUDES) $(TGTROOT)/lib $(TGTROOT)/usr/lib
    139 vpath %.so $(LIBINCLUDES) $(TGTROOT)/lib $(TGTROOT)/usr/lib
    140 
    141 #   ----------------------------------------------------------
    142 #   BUILD ARGUMENTS
    143 #   ----------------------------------------------------------
    144 
    145 MAPFILE := -Wl,-Map,$(TARGET).map
    146 INCPATH := $(addprefix -I, . $(INCLUDES)) $(LINUXINCLUDE)
    147 LIBPATH := $(addprefix -L, $(LIBINCLUDES))
    148 LIBFILE := $(addprefix -l, $(ST_LIBS) $(SH_LIBS)) $(LIB_OBJS)
    149 
    150 ifeq ($(TARGETTYPE),SH_LIB)
    151 CFLAGS += -fpic
    152 TARGETARGS := $(SH_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -shared -Wl
    153 ifneq ($(SH_SONAME),)
    154 TARGETARGS += -Wl,-soname,$(SH_SONAME)
    155 endif
    156 endif
    157 
    158 ifeq ($(TARGETTYPE),MODULE)
    159 TARGETARGS := $(SH_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -Wl,-r
    160 ifneq ($(SH_SONAME),)
    161 TARGETARGS += -Wl,-soname,$(SH_SONAME)
    162 endif
    163 endif
    164 
    165 ifeq ($(TARGETTYPE),ST_LIB)
    166 TARGETARGS := $(ST_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -Wl,-r
    167 endif
    168 
    169 ifeq ($(TARGETTYPE),EXEC)
    170 TARGETARGS := $(EXEC_ARGS)
    171 endif
    172 
    173 .PHONY  :   all $(SUBMODULES) clean cleantrg SHELLERR Debug
    174 
    175 #   ==========================================================
    176 #   all
    177 #   ==========================================================
    178 all :  $(CHECKSHELL) $(SUBMODULES)
    179 
    180 #   ==========================================================
    181 #   Make submodules
    182 #   ==========================================================
    183 $(SUBMODULES):
    184 ifndef NORECURSE
    185 ifndef norecurse
    186 	$(MAKE) -C $@ $(filter-out $(SUBMODULES),$(MAKECMDGOALS))
    187 endif
    188 endif
    189 
    190 ifneq ($(TARGETTYPE),)
    191 
    192 # if this is driver module level , build KO file too
    193 ifneq ($(TOPLEVEL),)
    194 all :  $(OBJDIRS) $(TARGETKO)
    195 else
    196 all :  $(OBJDIRS) $(TARGET)
    197 endif
    198 
    199 #   ==========================================================
    200 #   Create directories
    201 #   ==========================================================
    202 $(OBJDIRS) $(TARGETDIR) :
    203 	@$(call MKDIR, $@)
    204 
    205 #   ==========================================================
    206 #   Product 2.6.x kernel module based on target
    207 #   ==========================================================
    208 
    209 # Link module .o with vermagic .o
    210 $(TARGETKO): $(TARGETMOD).o $(TARGET) 
    211 	$(LD) -EL -r -o $@ $^ 
    212 
    213 # Compile vermagic
    214 $(TARGETMOD).o: $(TARGETMOD).c 
    215 	$(CC) -c $(TARGETARGS) $(CFLAGS) $(INCPATH) -o $@ $<
    216 
    217 # Generate Module vermagic
    218 $(TARGETMOD).c: $(TARGET) 
    219 	$(MODPOST) $(TARGET)
    220 # removed - need to be done as a pre-step to building
    221 #	$(MAKE) -C $(KRNLSRC) modules	
    222 
    223 #   ==========================================================
    224 #   Build target
    225 #   ==========================================================
    226 $(TARGET):$(OBJECTS) $(ST_LIBNAMES) $(DL_LIBNAMES)
    227 #   @$(SHELLCMD) echo Building $@
    228 #	$(CC) $(TARGETARGS) $(CFLAGS) $(LIBPATH) $(MAPFILE) -o $@ $(BASEOBJ) $(LIBFILE)
    229 #	$(CC) $(TARGETARGS) $(CFLAGS) $(LIBPATH) $(MAPFILE) -o $@ $(OBJECTS) $(LIBFILE)
    230 ifeq ($(TARGETTYPE),ST_LIB)
    231 	$(AR) r $@ $(OBJECTS)
    232 else
    233 	$(CC) $(TARGETARGS) $(CFLAGS) $(LIBPATH) $(MAPFILE) -o $@ $(OBJECTS) $(LIBFILE)
    234 endif
    235 
    236 #   ==========================================================
    237 #   Compile .c file
    238 #   ==========================================================
    239 $(BUILDDIR)%.o:%.c
    240 #   echo Compiling $(patsubst $(BUILDDIR)%.o,%.c, $@)
    241 	$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $(patsubst $(BUILDDIR)%.o,%.c, $@)
    242 
    243 #   ==========================================================
    244 #   Compile .S file
    245 #   ==========================================================
    246 $(BUILDDIR)%.o:%.S
    247 #   echo Compiling $(patsubst $(BUILDDIR)%.o,%.S, $@)
    248 	$(CC) -c $(CFLAGS) $(INCPATH) -o $@ $(patsubst $(BUILDDIR)%.o,%.S, $@)
    249 
    250 endif   # ifneq ($(TARGETTYPE),)
    251 
    252 #   ----------------------------------------------------------
    253 #   install - install the files
    254 #   ----------------------------------------------------------
    255 install:: $(TARGETDIR) $(SUBMODULES) $(TARGET)
    256 ifdef HOSTRELEASE
    257 ifdef SH_SONAME
    258 	$(INSTALL) -D $(TARGET) $(TARGETDIR)/$(HOSTRELEASE)/$(SH_SONAME)
    259 	$(RM) -f $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
    260 	ln -s $(SH_SONAME) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
    261 else
    262 ifneq ($(TOPLEVEL),)
    263 	$(INSTALL) -D $(TARGETKO) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGETKO)
    264 else
    265 	$(INSTALL) -D $(TARGET) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
    266 endif
    267 endif
    268 endif
    269 ifdef 0 # removed - components shouldn't put things in the production fs
    270 ifdef ROOTFSRELEASE
    271 	$(call MKDIR, $(ROOTFSDIR)/$(ROOTFSRELEASE))
    272 ifdef SH_SONAME
    273 	$(STRIP) --strip-unneeded -xgo $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(SH_SONAME) $(TARGET)
    274 	$(RM) -f $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGET)
    275 	ln -s $(SH_SONAME) $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGET)
    276 else
    277 ifneq ($(TOPLEVEL),)
    278 	$(STRIP) --strip-unneeded -xgo $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGETKO) $(TARGETKO)
    279 else
    280 	$(STRIP) --strip-unneeded -xgo $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGET) $(TARGET)
    281 endif
    282 endif
    283 endif
    284 endif
    285 
    286 #   ----------------------------------------------------------
    287 #   clean - Remove build directory and target files
    288 #   Linux : Removes object and dependency files in build folder
    289 #   DOS   : Removes object dirs in build folder
    290 #   ----------------------------------------------------------
    291 clean : $(SUBMODULES)
    292 ifneq ($(TARGETTYPE),)
    293 ifneq ($(OBJECTS),)
    294 	- $(call RM,-f $(OBJECTS))
    295 	- $(call RM,-f $(OBJECTS:.o=.d))
    296 	- $(call RMDIR,-f $(BUILDDIR))
    297 endif
    298 	- $(call RM,-f $(TARGET))
    299 	- $(call RM,-f $(TARGET).map)
    300 	- $(call RM,-f $(TARGETKO))
    301 	- $(call RM,-f $(TARGETMOD).c)
    302 	- $(call RM,-f $(TARGETMOD).o)
    303 	- $(call RM,-f $(TARGETMOD).d)
    304 ifneq ($(TOPLEVEL),)
    305 	- @$(call RM,-f $(TARGETKO))
    306 	- @$(call RM,-f $(TARGETMOD).c)
    307 	- @$(call RM,-f $(TARGETMOD).o)
    308 	- @$(call RM,-f $(TARGETMOD).d)
    309 endif
    310 endif
    311 
    312 cleantrg : $(SUBMODULES)
    313 ifneq ($(TARGETTYPE),)
    314 	- @$(call RM, $(TARGET))
    315 	- @$(call RM, $(TARGET).map)
    316 ifneq ($(TOPLEVEL),)
    317 	- @$(call RM, $(TARGETKO))
    318 	- @$(call RM, $(TARGETMOD).c)
    319 	- @$(call RM, $(TARGETMOD).o)
    320 	- @$(call RM, $(TARGETMOD).d)
    321 endif
    322 endif
    323 
    324 #   ----------------------------------------------------------
    325 #   Include dependency files generated by preprocessor.
    326 #
    327 #   Dependency files are placed in main object directory because
    328 #   dependent files' paths for same source file varies with the
    329 #   directory from where gmake is run
    330 #   ----------------------------------------------------------
    331 ifndef NODEPENDS
    332 ifndef nodepends
    333 ifneq ($(OBJECTS),)
    334 -include $(OBJECTS:.o=.d)
    335 endif
    336 endif
    337 endif
    338 
    339 #   ----------------------------------------------------------
    340 #   Generate fatal error if make variable SHELL is incorrect
    341 #   ----------------------------------------------------------
    342 SHELLERR::
    343 	@$(SHELLCMD) echo Fatal error: SHELL set to $(SHELL) instead of $(MYSHELL)
    344 	@$(SHELLCMD) echo set $(MYSHELL) to correct path and CASE SENSITIVE FILE NAME and EXTENSTION
    345 	@$(SHELLCMD) echo of your command shell
    346 	$(ERR)
    347 
    348 
    349 #   ----------------------------------------------------------
    350 #   For debugging script
    351 #   ----------------------------------------------------------
    352 Debug::$(SUBMODULES)
    353 	@$(SHELLCMD) echo SHELL: $(SHELL)
    354 	@$(SHELLCMD) echo
    355 	@$(SHELLCMD) echo CDEFS: $(CDEFS)
    356 	@$(SHELLCMD) echo
    357 	@$(SHELLCMD) echo CONFIG_SHELL: $(CONFIG_SHELL)
    358 	@$(SHELLCMD) echo
    359 	@$(SHELLCMD) echo CURDIR: $(CURDIR)
    360 	@$(SHELLCMD) echo
    361 	@$(SHELLCMD) echo SRCDIRS: $(SRCDIRS)
    362 	@$(SHELLCMD) echo
    363 	@$(SHELLCMD) echo OBJDIRS: $(OBJDIRS)
    364 	@$(SHELLCMD) echo
    365 	@$(SHELLCMD) echo OBJECTS: $(OBJECTS)
    366 	@$(SHELLCMD) echo
    367 	@$(SHELLCMD) echo BUILDDIR: $(BUILDDIR)
    368 	@$(SHELLCMD) echo
    369 	@$(SHELLCMD) echo TARGETDIR TARGETNAME: $(TARGET)
    370 	@$(SHELLCMD) echo
    371 	@$(SHELLCMD) echo MAKEDIR: $(MAKEDIR)
    372 	@$(SHELLCMD) echo
    373 	@$(SHELLCMD) echo INCLUDES: $(INCLUDES)
    374 	@$(SHELLCMD) echo
    375 	@$(SHELLCMD) echo DL_LIBNAMES: $(DL_LIBNAMES)
    376 	@$(SHELLCMD) echo
    377 	@$(SHELLCMD) echo LIBFILE: $(LIBFILE)
    378 	@$(SHELLCMD) echo
    379 
    380