blob: ef4429ea50fc6ccc3b49c682e2b7a833b83f65da [file] [log] [blame]
Steve Muckle0a9c0872022-02-16 05:58:07 +00001#
2# Copyright (C) 2018 Cadence Design Systems, Inc.
3#
4# Permission is hereby granted, free of charge, to any person obtaining
5# a copy of this software and associated documentation files (the
6# "Software"), to use this Software with Cadence processor cores only and
7# not with any other processors and platforms, subject to
8# the following conditions:
9#
10# The above copyright notice and this permission notice shall be included
11# in all copies or substantial portions of the Software.
12#
13# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
17# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
19# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20#
21
22QUIET =
23MAPFILE = map_$(CODEC_NAME).txt
24LDSCRIPT = ldscript_$(CODEC_NAME).txt
25SYMFILE = symbols_$(CODEC_NAME).txt
26ELFTOBIN = $(ROOTDIR)/build_hikey/tools/elftobin.sh
27
28ifeq ($(CPU), gcc)
29 S = /
30 AR = ar
31 OBJCOPY = objcopy
32 CC = gcc
33 CXX = g++
34 CFLAGS += -fno-exceptions -DCSTUB=1
35 CFLAGS += -ffloat-store
36 CFLAGS += -DHIFI3_CSTUB
37 RM = rm -f
38 RM_R = rm -rf
39 MKPATH = mkdir -p
40 CP = cp -f
41 INCLUDES += \
42 -I$(ROOTDIR)/test/include
43else
44 AR = xt-ar $(XTCORE)
45 OBJCOPY = xt-objcopy $(XTCORE)
46 CC = xt-xcc $(XTCORE)
47 CXX = xt-xc++ $(XTCORE)
48 ISS = xt-run $(XTCORE)
49 CONFIGDIR := $(shell $(ISS) --show-config=config)
50 include $(CONFIGDIR)/misc/hostenv.mk
51 #CFLAGS += -Wall
52 #CFLAGS += -Werror
53 #CFLAGS += -mno-mul16 -mno-mul32 -mno-div32 -fsigned-char -fno-exceptions -mlongcalls -INLINE:requested -mcoproc -fno-zero-initialized-in-bss
54 CFLAGS += -mlongcalls -mtext-section-literals
55 ASMFLAGS += -mlongcalls
56endif
57
58OBJDIR = objs$(S)$(CODEC_NAME)
59LIBDIR = $(ROOTDIR)$(S)lib
60
61OBJ_LIBO2OBJS = $(addprefix $(OBJDIR)/,$(LIBO2OBJS))
62OBJ_LIBOSOBJS = $(addprefix $(OBJDIR)/,$(LIBOSOBJS))
63OBJ_LIBO2CPPOBJS = $(addprefix $(OBJDIR)/,$(LIBO2CPPOBJS))
64OBJ_LIBOSCPPOBJS = $(addprefix $(OBJDIR)/,$(LIBOSCPPOBJS))
65OBJ_LIBASMOBJS = $(addprefix $(OBJDIR)/,$(LIBASMOBJS))
66
67TEMPOBJ = temp.o
68
69ifeq ($(CPU), gcc)
70 LIBOBJ = $(OBJDIR)/xgcc_$(CODEC_NAME).o
71 LIB = xgcc_$(CODEC_NAME).img
72else
73 LIBOBJ = $(OBJDIR)/xa_$(CODEC_NAME).o
74 LIB = xa_$(CODEC_NAME).img
75endif
76
77CFLAGS += \
78 $(EXTRA_CFLAGS) $(EXTRA_CFLAGS2)
79
80
81ifeq ($(DEBUG),1)
82 NOSTRIP = 1
83 OPT_O2 = -O0 -g
84 OPT_OS = -O0 -g
85 CFLAGS += -DDEBUG
86else
87ifeq ($(CPU), gcc)
88 OPT_O2 = -O2 -g
89 OPT_OS = -O2 -g
90else
91 #OPT_O2 = -O3 -LNO:simd
92 OPT_O2 = -g -O2
93 OPT_OS = -Os
94endif
95endif
96
97OPT_ASM = -g -Wa,--gdwarf-2
98
99
100all: $(OBJDIR) $(LIB)
101$(CODEC_NAME): $(OBJDIR) $(LIB)
102
103install: $(LIB)
104 @echo "Installing $(LIB)"
105 $(QUIET) -$(MKPATH) "$(LIBDIR)"
106 $(QUIET) $(CP) $(LIB) "$(LIBDIR)"
107
108$(OBJDIR):
109 $(QUIET) -$(MKPATH) $@
110
111ifeq ($(NOSTRIP), 1)
112$(LIBOBJ): $(OBJ_LIBO2OBJS) $(OBJ_LIBOSOBJS) $(OBJ_LIBO2CPPOBJS) $(OBJ_LIBOSCPPOBJS) $(OBJ_LIBASMOBJS) $(PLUGINLIBS)
113 @echo "Linking Objects"
114 $(QUIET) $(CXX) -c $(OPT_O2) $(CFLAGS) -o $@ $^ \
115 -Wl,-Map,$(MAPFILE) --no-standard-libraries \
116 $(LDFLAGS) $(EXTRA_LDFLAGS)
117else
118$(LIBOBJ): $(OBJ_LIBO2OBJS) $(OBJ_LIBOSOBJS) $(OBJ_LIBO2CPPOBJS) $(OBJ_LIBOSCPPOBJS) $(OBJ_LIBASMOBJS) $(PLUGINLIBS)
119 @echo "Linking Objects"
120 $(QUIET) $(CXX) -c $(OPT_O2) $(CFLAGS) -o $@ $^ \
121 -Wl,-Map,$(MAPFILE) --no-standard-libraries \
122 -Wl,--retain-symbols-file,$(SYMFILE) \
123 $(IPA_FLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS)
124 $(QUIET) $(OBJCOPY) --keep-global-symbols=$(SYMFILE) $@ $(TEMPOBJ)
125 $(QUIET) $(OBJCOPY) --strip-unneeded $(TEMPOBJ) $@
126 $(QUIET) -$(RM) $(TEMPOBJ)
127endif
128
129
130$(OBJ_LIBO2OBJS): $(OBJDIR)/%.o: %.c
131 @echo "Compiling $<"
132 $(QUIET) $(CC) -o $@ $(OPT_O2) $(CFLAGS) $(INCLUDES) -c $<
133
134$(OBJ_LIBOSOBJS): $(OBJDIR)/%.o: %.c
135 @echo "Compiling $<"
136 $(QUIET) $(CC) -o $@ $(OPT_OS) $(CFLAGS) $(INCLUDES) -c $<
137
138$(OBJ_LIBO2CPPOBJS): $(OBJDIR)/%.o: %.cpp
139 @echo "Compiling $<"
140 $(QUIET) $(CXX) -o $@ $(OPT_O2) $(CFLAGS) $(INCLUDES) -c $<
141
142$(OBJ_LIBOSCPPOBJS): $(OBJDIR)/%.o: %.cpp
143 @echo "Compiling $<"
144 $(QUIET) $(CXX) -o $@ $(OPT_OS) $(CFLAGS) $(INCLUDES) -c $<
145
146$(OBJ_LIBASMOBJS): $(OBJDIR)/%.o: %.S
147 @echo "Compiling $<"
148 $(QUIET) $(CC) -o $@ $(OPT_ASM) $(ASMFLAGS) $(INCLUDES) -c $<
149
150$(LIB): %.img: $(OBJDIR)/%.o
151 @echo "Creating Library $@"
152 $(ELFTOBIN) $< $@
153
154clean:
155 -$(RM) $(LIB) $(MAPFILE)
156 -$(RM_R) $(OBJDIR) $(LIBDIR)