• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
23CDEFS       += $(CMDDEFS) # Add command line definitions
24CDEFS       += $(PROCFAMILY) # Processor Family e.g. 3430
25CDEFS	    += $(CMDDEFS_START) # Definitions from start.mk
26#   ----------------------------------------------------------
27#   REMOVE LEADING AND TRAILING SPACES FROM MAKEFILE MACROS
28#   ----------------------------------------------------------
29
30TARGETNAME  := $(strip $(TARGETNAME))
31TARGETTYPE  := $(strip $(TARGETTYPE))
32SUBMODULES  := $(strip $(SUBMODULES))
33SOURCES     := $(strip $(SOURCES))
34INCLUDES    := $(strip $(INCLUDES))
35LIBINCLUDES := $(strip $(LIBINCLUDES))
36
37SH_SONAME   := $(strip $(SH_SONAME))
38ST_LIBS     := $(strip $(ST_LIBS))
39SH_LIBS     := $(strip $(SH_LIBS))
40
41CFLAGS      := $(strip $(CFLAGS))
42CDEFS       := $(strip $(CDEFS))
43EXEC_ARGS   := $(strip $(EXEC_ARGS))
44ST_LIB_ARGS := $(strip $(ST_LIB_ARGS))
45SH_LIB_ARGS := $(strip $(SH_LIB_ARGS))
46
47#   ----------------------------------------------------------
48#   COMPILER OPTIONS
49#   ----------------------------------------------------------
50
51# Preprocessor : dependency file generation
52ifndef NODEPENDS
53ifndef nodepends
54CFLAGS += -MD
55endif
56endif
57
58#   Overall
59CFLAGS += -pipe
60#   Preprocessor
61CFLAGS +=
62#   Debugging
63ifeq ($(BUILD),deb)
64CFLAGS += -g
65else
66CFLAGS += -fomit-frame-pointer
67endif
68#   Warnings
69CFLAGS += -Wall  -Wno-trigraphs -Werror-implicit-function-declaration #-Wno-format
70#   Optimizations
71#CFLAGS += -O2 -fno-strict-aliasing
72#CFLAGS += -Os -fno-strict-aliasing
73CFLAGS += -fno-strict-aliasing
74#   Machine dependent
75
76ifeq ($(PROCFAMILY),OMAP_3430)
77CFLAGS += -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
78endif
79
80ifeq ($(PROCFAMILY),OMAP_4430)
81CFLAGS += -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
82endif
83
84#   Code generation
85CFLAGS += -fno-common
86#   Macros
87CFLAGS += -DLINUX $(addprefix -D, $(CDEFS))
88
89ifdef __KERNEL__
90CFLAGS      += -D__KERNEL__  -fno-builtin
91endif
92
93#   ----------------------------------------------------------
94#   OBJECTS
95#   ----------------------------------------------------------
96
97BUILDDIR    = .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
105ifeq ($(TARGETTYPE),SH_LIB)
106   TARGET      := $(basename $(TARGETNAME)).so
107else
108ifeq ($(TARGETTYPE),MODULE)
109   TARGET      := $(basename $(TARGETNAME)).o
110   TARGETKO    := $(addsuffix .ko,$(basename $(TARGET)))
111   TARGETMOD   := $(addsuffix .mod,$(basename $(TARGET)))
112else
113ifeq ($(TARGETTYPE),ST_LIB)
114   TARGET      := $(basename $(TARGETNAME)).a
115else
116ifeq ($(TARGETTYPE),EXEC)
117   TARGET      := $(basename $(TARGETNAME)).out
118else
119ifneq ($(TARGETTYPE),)
120TARGET         := $(error Invalid TARGETTYPE)
121endif
122endif
123endif
124endif
125endif
126
127#LIBINCLUDES += $(TARGETDIR) $(TGTROOT)/lib $(TGTROOT)/usr/lib
128LIBINCLUDES += $(TARGETDIR)/lib $(TARGETDIR)/usr/lib
129SRCDIRS :=  $(sort $(dir $(SOURCES)))
130OBJDIRS :=  $(addprefix $(BUILDDIR),$(SRCDIRS)) $(BUILDDIR)
131
132BASEOBJ := $(addsuffix .o,$(basename $(SOURCES)))
133OBJECTS := $(addprefix $(BUILDDIR), $(BASEOBJ))
134
135ST_LIBNAMES := $(addsuffix .a, $(addprefix lib, $(ST_LIBS)))
136DL_LIBNAMES := $(addsuffix .so, $(addprefix lib, $(SH_LIBS)))
137
138vpath %.a $(LIBINCLUDES) $(TGTROOT)/lib $(TGTROOT)/usr/lib
139vpath %.so $(LIBINCLUDES) $(TGTROOT)/lib $(TGTROOT)/usr/lib
140
141#   ----------------------------------------------------------
142#   BUILD ARGUMENTS
143#   ----------------------------------------------------------
144
145MAPFILE := -Wl,-Map,$(TARGET).map
146INCPATH := $(addprefix -I, . $(INCLUDES)) $(LINUXINCLUDE)
147LIBPATH := $(addprefix -L, $(LIBINCLUDES))
148LIBFILE := $(addprefix -l, $(ST_LIBS) $(SH_LIBS)) $(LIB_OBJS)
149
150ifeq ($(TARGETTYPE),SH_LIB)
151CFLAGS += -fpic
152TARGETARGS := $(SH_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -shared -Wl
153ifneq ($(SH_SONAME),)
154TARGETARGS += -Wl,-soname,$(SH_SONAME)
155endif
156endif
157
158ifeq ($(TARGETTYPE),MODULE)
159TARGETARGS := $(SH_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -Wl,-r
160ifneq ($(SH_SONAME),)
161TARGETARGS += -Wl,-soname,$(SH_SONAME)
162endif
163endif
164
165ifeq ($(TARGETTYPE),ST_LIB)
166TARGETARGS := $(ST_LIB_ARGS) -nostartfiles -nodefaultlibs -nostdlib -Wl,-r
167endif
168
169ifeq ($(TARGETTYPE),EXEC)
170TARGETARGS := $(EXEC_ARGS)
171endif
172
173.PHONY  :   all $(SUBMODULES) clean cleantrg SHELLERR Debug
174
175#   ==========================================================
176#   all
177#   ==========================================================
178all :  $(CHECKSHELL) $(SUBMODULES)
179
180#   ==========================================================
181#   Make submodules
182#   ==========================================================
183$(SUBMODULES):
184ifndef NORECURSE
185ifndef norecurse
186	$(MAKE) -C $@ $(filter-out $(SUBMODULES),$(MAKECMDGOALS))
187endif
188endif
189
190ifneq ($(TARGETTYPE),)
191
192# if this is driver module level , build KO file too
193ifneq ($(TOPLEVEL),)
194all :  $(OBJDIRS) $(TARGETKO)
195else
196all :  $(OBJDIRS) $(TARGET)
197endif
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)
230ifeq ($(TARGETTYPE),ST_LIB)
231	$(AR) r $@ $(OBJECTS)
232else
233	$(CC) $(TARGETARGS) $(CFLAGS) $(LIBPATH) $(MAPFILE) -o $@ $(OBJECTS) $(LIBFILE)
234endif
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
250endif   # ifneq ($(TARGETTYPE),)
251
252#   ----------------------------------------------------------
253#   install - install the files
254#   ----------------------------------------------------------
255install:: $(TARGETDIR) $(SUBMODULES) $(TARGET)
256ifdef HOSTRELEASE
257ifdef SH_SONAME
258	$(INSTALL) -D $(TARGET) $(TARGETDIR)/$(HOSTRELEASE)/$(SH_SONAME)
259	$(RM) -f $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
260	ln -s $(SH_SONAME) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
261else
262ifneq ($(TOPLEVEL),)
263	$(INSTALL) -D $(TARGETKO) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGETKO)
264else
265	$(INSTALL) -D $(TARGET) $(TARGETDIR)/$(HOSTRELEASE)/$(TARGET)
266endif
267endif
268endif
269ifdef 0 # removed - components shouldn't put things in the production fs
270ifdef ROOTFSRELEASE
271	$(call MKDIR, $(ROOTFSDIR)/$(ROOTFSRELEASE))
272ifdef 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)
276else
277ifneq ($(TOPLEVEL),)
278	$(STRIP) --strip-unneeded -xgo $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGETKO) $(TARGETKO)
279else
280	$(STRIP) --strip-unneeded -xgo $(ROOTFSDIR)/$(ROOTFSRELEASE)/$(TARGET) $(TARGET)
281endif
282endif
283endif
284endif
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#   ----------------------------------------------------------
291clean : $(SUBMODULES)
292ifneq ($(TARGETTYPE),)
293ifneq ($(OBJECTS),)
294	- $(call RM,-f $(OBJECTS))
295	- $(call RM,-f $(OBJECTS:.o=.d))
296	- $(call RMDIR,-f $(BUILDDIR))
297endif
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)
304ifneq ($(TOPLEVEL),)
305	- @$(call RM,-f $(TARGETKO))
306	- @$(call RM,-f $(TARGETMOD).c)
307	- @$(call RM,-f $(TARGETMOD).o)
308	- @$(call RM,-f $(TARGETMOD).d)
309endif
310endif
311
312cleantrg : $(SUBMODULES)
313ifneq ($(TARGETTYPE),)
314	- @$(call RM, $(TARGET))
315	- @$(call RM, $(TARGET).map)
316ifneq ($(TOPLEVEL),)
317	- @$(call RM, $(TARGETKO))
318	- @$(call RM, $(TARGETMOD).c)
319	- @$(call RM, $(TARGETMOD).o)
320	- @$(call RM, $(TARGETMOD).d)
321endif
322endif
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#   ----------------------------------------------------------
331ifndef NODEPENDS
332ifndef nodepends
333ifneq ($(OBJECTS),)
334-include $(OBJECTS:.o=.d)
335endif
336endif
337endif
338
339#   ----------------------------------------------------------
340#   Generate fatal error if make variable SHELL is incorrect
341#   ----------------------------------------------------------
342SHELLERR::
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#   ----------------------------------------------------------
352Debug::$(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