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