1#  FLAC - Free Lossless Audio Codec
2#  Copyright (C) 2001,2002,2003,2004,2005,2006,2007  Josh Coalson
3#
4#  This file is part the FLAC project.  FLAC is comprised of several
5#  components distributed under difference licenses.  The codec libraries
6#  are distributed under Xiph.Org's BSD-like license (see the file
7#  COPYING.Xiph in this distribution).  All other programs, libraries, and
8#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
9#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
10#  FLAC distribution contains at the top the terms under which it may be
11#  distributed.
12#
13#  Since this particular file is relevant to all components of FLAC,
14#  it may be distributed under the Xiph.Org license, which is the least
15#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
16#  distribution.
17
18#
19# GNU makefile fragment for building a library
20#
21
22include $(topdir)/build/config.mk
23
24ifeq ($(DARWIN_BUILD),yes)
25CC          = cc
26CCC         = c++
27else
28CC          = gcc
29CCC         = g++
30endif
31AS          = as
32NASM        = nasm
33LINK        = ar cru
34OBJPATH     = $(topdir)/obj
35LIBPATH     = $(OBJPATH)/$(BUILD)/lib
36DEBUG_LIBPATH     = $(OBJPATH)/debug/lib
37RELEASE_LIBPATH   = $(OBJPATH)/release/lib
38ifeq ($(DARWIN_BUILD),yes)
39STATIC_LIB_SUFFIX = a
40DYNAMIC_LIB_SUFFIX = dylib
41else
42STATIC_LIB_SUFFIX = a
43DYNAMIC_LIB_SUFFIX = so
44endif
45STATIC_LIB_NAME     = $(LIB_NAME).$(STATIC_LIB_SUFFIX)
46DYNAMIC_LIB_NAME    = $(LIB_NAME).$(DYNAMIC_LIB_SUFFIX)
47STATIC_LIB          = $(LIBPATH)/$(STATIC_LIB_NAME)
48DYNAMIC_LIB         = $(LIBPATH)/$(DYNAMIC_LIB_NAME)
49DEBUG_STATIC_LIB    = $(DEBUG_LIBPATH)/$(STATIC_LIB_NAME)
50DEBUG_DYNAMIC_LIB   = $(DEBUG_LIBPATH)/$(DYNAMIC_LIB_NAME)
51RELEASE_STATIC_LIB  = $(RELEASE_LIBPATH)/$(STATIC_LIB_NAME)
52RELEASE_DYNAMIC_LIB = $(RELEASE_LIBPATH)/$(DYNAMIC_LIB_NAME)
53ifeq ($(DARWIN_BUILD),yes)
54LINKD       = $(CC) -dynamiclib -flat_namespace -undefined suppress -install_name $(DYNAMIC_LIB)
55else
56LINKD       = $(CC) -shared
57endif
58
59debug   : CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -W -Wall -Wmissing-prototypes -Wstrict-prototypes -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
60valgrind: CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -DFLAC__VALGRIND_TESTING -W -Wall -Wmissing-prototypes -Wstrict-prototypes -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
61release : CFLAGS = -O3 -fomit-frame-pointer -funroll-loops -finline-functions -DNDEBUG $(CONFIG_CFLAGS) $(RELEASE_CFLAGS) -W -Wall -Wmissing-prototypes -Wstrict-prototypes -Winline -DFLaC__INLINE=__inline__ -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
62
63LFLAGS  = -L$(LIBPATH)
64
65DEBUG_OBJS = $(SRCS_C:%.c=%.debug.o) $(SRCS_CC:%.cc=%.debug.o) $(SRCS_CPP:%.cpp=%.debug.o) $(SRCS_NASM:%.nasm=%.debug.o) $(SRCS_S:%.s=%.debug.o)
66RELEASE_OBJS = $(SRCS_C:%.c=%.release.o) $(SRCS_CC:%.cc=%.release.o) $(SRCS_CPP:%.cpp=%.release.o) $(SRCS_NASM:%.nasm=%.release.o) $(SRCS_S:%.s=%.release.o)
67
68debug   : $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
69valgrind: $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
70release : $(RELEASE_STATIC_LIB) $(RELEASE_DYNAMIC_LIB)
71
72$(DEBUG_STATIC_LIB): $(DEBUG_OBJS)
73	$(LINK) $@ $(DEBUG_OBJS) && ranlib $@
74
75$(RELEASE_STATIC_LIB): $(RELEASE_OBJS)
76	$(LINK) $@ $(RELEASE_OBJS) && ranlib $@
77
78$(DEBUG_DYNAMIC_LIB) : $(DEBUG_OBJS)
79ifeq ($(DARWIN_BUILD),yes)
80	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS) -lc
81else
82	$(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS)
83endif
84
85$(RELEASE_DYNAMIC_LIB) : $(RELEASE_OBJS)
86ifeq ($(DARWIN_BUILD),yes)
87	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS) -lc
88else
89	$(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS)
90endif
91
92%.debug.o %.release.o : %.c
93	$(CC) $(CFLAGS) -c $< -o $@
94%.debug.o %.release.o : %.cc
95	$(CCC) $(CFLAGS) -c $< -o $@
96%.debug.o %.release.o : %.cpp
97	$(CCC) $(CFLAGS) -c $< -o $@
98%.debug.i %.release.i : %.c
99	$(CC) $(CFLAGS) -E $< -o $@
100%.debug.i %.release.i : %.cc
101	$(CCC) $(CFLAGS) -E $< -o $@
102%.debug.i %.release.i : %.cpp
103	$(CCC) $(CFLAGS) -E $< -o $@
104
105%.debug.o %.release.o : %.s
106ifeq ($(DARWIN_BUILD),yes)
107	#$(CC) -c -arch ppc -Wall -force_cpusubtype_ALL $< -o $@
108	$(AS) -arch ppc -force_cpusubtype_ALL $< -o $@
109else
110	$(AS) $< -o $@
111endif
112
113%.debug.o : %.nasm
114	$(NASM) -f elf -d OBJ_FORMAT_elf -i ia32/ -g $< -o $@
115%.release.o : %.nasm
116	$(NASM) -f elf -d OBJ_FORMAT_elf -i ia32/ $< -o $@
117
118.PHONY : clean
119clean :
120	-rm -f $(DEBUG_OBJS) $(RELEASE_OBJS) $(OBJPATH)/*/lib/$(STATIC_LIB_NAME) $(OBJPATH)/*/lib/$(DYNAMIC_LIB_NAME)
121
122.PHONY : depend
123depend:
124	makedepend -fMakefile.lite -- $(CFLAGS) $(INCLUDES) -- *.c *.cc *.cpp
125