lib.mk 4.87 KB
Newer Older
1
#  FLAC - Free Lossless Audio Codec
2
#  Copyright (C) 2001-2009  Josh Coalson
3
#  Copyright (C) 2011-2016  Xiph.Org Foundation
4
#
Josh Coalson's avatar
Josh Coalson committed
5
#  This file is part the FLAC project.  FLAC is comprised of several
6
#  components distributed under different licenses.  The codec libraries
Josh Coalson's avatar
Josh Coalson committed
7
8
9
10
11
12
#  are distributed under Xiph.Org's BSD-like license (see the file
#  COPYING.Xiph in this distribution).  All other programs, libraries, and
#  plugins are distributed under the GPL (see COPYING.GPL).  The documentation
#  is distributed under the Gnu FDL (see COPYING.FDL).  Each file in the
#  FLAC distribution contains at the top the terms under which it may be
#  distributed.
13
#
Josh Coalson's avatar
Josh Coalson committed
14
15
16
17
#  Since this particular file is relevant to all components of FLAC,
#  it may be distributed under the Xiph.Org license, which is the least
#  restrictive of those mentioned above.  See the file COPYING.Xiph in this
#  distribution.
18

Josh Coalson's avatar
Josh Coalson committed
19
20
21
22
#
# GNU makefile fragment for building a library
#

23
24
include $(topdir)/build/config.mk

25
ifeq ($(OS),Darwin)
26
27
    CC          = cc
    CCC         = c++
28
29
30
31
else
ifeq ($(OS),FreeBSD)
    CC          = cc
    CCC         = c++
Josh Coalson's avatar
Josh Coalson committed
32
else
33
34
    CC          = gcc
    CCC         = g++
Josh Coalson's avatar
Josh Coalson committed
35
endif
36
endif
Josh Coalson's avatar
Josh Coalson committed
37
NASM        = nasm
Josh Coalson's avatar
Josh Coalson committed
38
LINK        = ar cru
39
OBJPATH     = $(topdir)/objs
40
41
42
LIBPATH     = $(OBJPATH)/$(BUILD)/lib
DEBUG_LIBPATH     = $(OBJPATH)/debug/lib
RELEASE_LIBPATH   = $(OBJPATH)/release/lib
43
ifeq ($(OS),Darwin)
44
45
    STATIC_LIB_SUFFIX = a
    DYNAMIC_LIB_SUFFIX = dylib
46
47
else
ifeq ($(findstring Windows,$(OS)),Windows)
48
49
    STATIC_LIB_SUFFIX = a
    DYNAMIC_LIB_SUFFIX = dll
Josh Coalson's avatar
Josh Coalson committed
50
else
51
52
    STATIC_LIB_SUFFIX = a
    DYNAMIC_LIB_SUFFIX = so
Josh Coalson's avatar
Josh Coalson committed
53
endif
54
endif
55
56
57
58
59
60
61
62
STATIC_LIB_NAME     = $(LIB_NAME).$(STATIC_LIB_SUFFIX)
DYNAMIC_LIB_NAME    = $(LIB_NAME).$(DYNAMIC_LIB_SUFFIX)
STATIC_LIB          = $(LIBPATH)/$(STATIC_LIB_NAME)
DYNAMIC_LIB         = $(LIBPATH)/$(DYNAMIC_LIB_NAME)
DEBUG_STATIC_LIB    = $(DEBUG_LIBPATH)/$(STATIC_LIB_NAME)
DEBUG_DYNAMIC_LIB   = $(DEBUG_LIBPATH)/$(DYNAMIC_LIB_NAME)
RELEASE_STATIC_LIB  = $(RELEASE_LIBPATH)/$(STATIC_LIB_NAME)
RELEASE_DYNAMIC_LIB = $(RELEASE_LIBPATH)/$(DYNAMIC_LIB_NAME)
63
ifeq ($(OS),Darwin)
64
    LINKD       = $(CC) -dynamiclib -flat_namespace -undefined suppress -install_name $(DYNAMIC_LIB)
Josh Coalson's avatar
Josh Coalson committed
65
else
66
    LINKD       = $(CC) -shared
Josh Coalson's avatar
Josh Coalson committed
67
endif
Josh Coalson's avatar
Josh Coalson committed
68

Erik de Castro Lopo's avatar
Erik de Castro Lopo committed
69
BASE_CFLAGS = -Wall -Wextra $(CONFIG_CFLAGS) -DVERSION=$(VERSION) -DPACKAGE_VERSION=$(VERSION) $(DEFINES) $(INCLUDES)
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84

ifeq ($(DEFAULT_BUILD),debug)
CFLAGS   := -g -O0 -DDEBUG $(CFLAGS) $(BASE_CFLAGS) -Wmissing-prototypes -Wstrict-prototypes
CXXFLAGS := -g -O0 -DDEBUG $(CFLAGS) $(BASE_CFLAGS)
endif

ifeq ($(DEFAULT_BUILD),valgrind)
CFLAGS   := -g -O0 -DDEBUG  -DDEBUG -DFLAC__VALGRIND_TESTING $(CFLAGS) $(BASE_CFLAGS) -Wmissing-prototypes -Wstrict-prototypes
CXXFLAGS := -g -O0 -DDEBUG -DDEBUG -DFLAC__VALGRIND_TESTING $(CFLAGS) $(BASE_CFLAGS)
endif

ifeq ($(DEFAULT_BUILD),release)
CFLAGS   := -O3 -fomit-frame-pointer -funroll-loops -finline-functions -DFLaC__INLINE=__inline__ -DNDEBUG $(CFLAGS) $(BASE_CFLAGS) -Wmissing-prototypes -Wstrict-prototypes
CXXFLAGS := -O3 -fomit-frame-pointer -funroll-loops -finline-functions -DFLaC__INLINE=__inline__ -DNDEBUG $(CFLAGS) $(BASE_CFLAGS)
endif
85
86

LFLAGS   = -L$(LIBPATH)
Josh Coalson's avatar
Josh Coalson committed
87

88
89
DEBUG_OBJS = $(SRCS_C:%.c=%.debug.o) $(SRCS_CC:%.cc=%.debug.o) $(SRCS_CPP:%.cpp=%.debug.o) $(SRCS_NASM:%.nasm=%.debug.o)
RELEASE_OBJS = $(SRCS_C:%.c=%.release.o) $(SRCS_CC:%.cc=%.release.o) $(SRCS_CPP:%.cpp=%.release.o) $(SRCS_NASM:%.nasm=%.release.o)
90
ifeq ($(PROC),x86_64)
91
92
DEBUG_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)
RELEASE_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)
93
endif
94

95
96
97
debug   : $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
valgrind: $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
release : $(RELEASE_STATIC_LIB) $(RELEASE_DYNAMIC_LIB)
Josh Coalson's avatar
Josh Coalson committed
98

99
100
101
102
103
104
$(DEBUG_STATIC_LIB): $(DEBUG_OBJS)
	$(LINK) $@ $(DEBUG_OBJS) && ranlib $@

$(RELEASE_STATIC_LIB): $(RELEASE_OBJS)
	$(LINK) $@ $(RELEASE_OBJS) && ranlib $@

105
106
$(DEBUG_DYNAMIC_LIB) : $(DEBUG_OBJS) $(DEBUG_PIC_OBJS)
ifeq ($(OS),Darwin)
107
	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS) -lc
108
109
110
else
ifeq ($(PROC),x86_64)
	$(LINKD) -o $@ $(DEBUG_PIC_OBJS) $(LFLAGS) $(LIBS)
111
112
113
else
	$(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS)
endif
114
endif
Josh Coalson's avatar
Josh Coalson committed
115

116
117
$(RELEASE_DYNAMIC_LIB) : $(RELEASE_OBJS) $(RELEASE_PIC_OBJS)
ifeq ($(OS),Darwin)
118
	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS) -lc
119
120
121
else
ifeq ($(PROC),x86_64)
	$(LINKD) -o $@ $(RELEASE_PIC_OBJS) $(LFLAGS) $(LIBS)
Josh Coalson's avatar
Josh Coalson committed
122
else
123
	$(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS)
Josh Coalson's avatar
Josh Coalson committed
124
endif
125
126
endif

127
include $(topdir)/build/compile.mk
Josh Coalson's avatar
Josh Coalson committed
128

Josh Coalson's avatar
Josh Coalson committed
129
130
.PHONY : clean
clean :
131
	-rm -f $(DEBUG_OBJS) $(RELEASE_OBJS) $(DEBUG_PIC_OBJS) $(RELEASE_PIC_OBJS) $(OBJPATH)/*/lib/$(STATIC_LIB_NAME) $(OBJPATH)/*/lib/$(DYNAMIC_LIB_NAME)
Josh Coalson's avatar
Josh Coalson committed
132
133
134

.PHONY : depend
depend:
Josh Coalson's avatar
Josh Coalson committed
135
	makedepend -fMakefile.lite -- $(CFLAGS) $(INCLUDES) -- *.c *.cc *.cpp