lib.mk 4.33 KB
Newer Older
1
#  FLAC - Free Lossless Audio Codec
Josh Coalson's avatar
Josh Coalson committed
2
#  Copyright (C) 2001,2002,2003,2004,2005  Josh Coalson
3
#
Josh Coalson's avatar
Josh Coalson committed
4 5 6 7 8 9 10 11
#  This file is part the FLAC project.  FLAC is comprised of several
#  components distributed under difference licenses.  The codec libraries
#  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.
12
#
Josh Coalson's avatar
Josh Coalson committed
13 14 15 16
#  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.
17

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

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

Josh Coalson's avatar
Josh Coalson committed
24 25
ifeq ($(DARWIN_BUILD),yes)
CC          = cc
26
CCC         = c++
Josh Coalson's avatar
Josh Coalson committed
27
else
Josh Coalson's avatar
Josh Coalson committed
28
CC          = gcc
29
CCC         = g++
Josh Coalson's avatar
Josh Coalson committed
30
endif
31
AS          = as
Josh Coalson's avatar
Josh Coalson committed
32
NASM        = nasm
Josh Coalson's avatar
Josh Coalson committed
33
LINK        = ar cru
34 35 36 37
OBJPATH     = $(topdir)/obj
LIBPATH     = $(OBJPATH)/$(BUILD)/lib
DEBUG_LIBPATH     = $(OBJPATH)/debug/lib
RELEASE_LIBPATH   = $(OBJPATH)/release/lib
Josh Coalson's avatar
Josh Coalson committed
38
ifeq ($(DARWIN_BUILD),yes)
39 40
STATIC_LIB_SUFFIX = a
DYNAMIC_LIB_SUFFIX = dylib
Josh Coalson's avatar
Josh Coalson committed
41
else
42 43
STATIC_LIB_SUFFIX = a
DYNAMIC_LIB_SUFFIX = so
Josh Coalson's avatar
Josh Coalson committed
44
endif
45 46 47 48 49 50 51 52
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)
Josh Coalson's avatar
Josh Coalson committed
53
ifeq ($(DARWIN_BUILD),yes)
54
LINKD       = $(CC) -dynamiclib -flat_namespace -undefined suppress -install_name $(DYNAMIC_LIB)
Josh Coalson's avatar
Josh Coalson committed
55
else
Josh Coalson's avatar
Josh Coalson committed
56
LINKD       = $(CC) -shared
Josh Coalson's avatar
Josh Coalson committed
57
endif
Josh Coalson's avatar
Josh Coalson committed
58

59
debug   : CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -Wall -W -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
60
valgrind: CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -DFLAC__VALGRIND_TESTING -Wall -W -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
61
release : CFLAGS = -O3 -fomit-frame-pointer -funroll-loops -finline-functions -DNDEBUG $(CONFIG_CFLAGS) $(RELEASE_CFLAGS) -Wall -W -Winline -DFLaC__INLINE=__inline__ -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
Josh Coalson's avatar
Josh Coalson committed
62 63 64

LFLAGS  = -L$(LIBPATH)

65 66
DEBUG_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)
RELEASE_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

68 69 70
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
71

72 73 74 75 76 77 78 79
$(DEBUG_STATIC_LIB): $(DEBUG_OBJS)
	$(LINK) $@ $(DEBUG_OBJS) && ranlib $@

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

$(DEBUG_DYNAMIC_LIB) : $(DEBUG_OBJS)
ifeq ($(DARWIN_BUILD),yes)
80
	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS) -lc
81 82 83
else
	$(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS)
endif
Josh Coalson's avatar
Josh Coalson committed
84

85
$(RELEASE_DYNAMIC_LIB) : $(RELEASE_OBJS)
Josh Coalson's avatar
Josh Coalson committed
86
ifeq ($(DARWIN_BUILD),yes)
87
	echo Not building dynamic lib, command is: $(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS) -lc
Josh Coalson's avatar
Josh Coalson committed
88
else
89
	$(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS)
Josh Coalson's avatar
Josh Coalson committed
90
endif
Josh Coalson's avatar
Josh Coalson committed
91

92
%.debug.o %.release.o : %.c
Josh Coalson's avatar
Josh Coalson committed
93
	$(CC) $(CFLAGS) -c $< -o $@
94
%.debug.o %.release.o : %.cc
95
	$(CCC) $(CFLAGS) -c $< -o $@
96
%.debug.o %.release.o : %.cpp
Josh Coalson's avatar
Josh Coalson committed
97
	$(CCC) $(CFLAGS) -c $< -o $@
98
%.debug.i %.release.i : %.c
Josh Coalson's avatar
Josh Coalson committed
99
	$(CC) $(CFLAGS) -E $< -o $@
100
%.debug.i %.release.i : %.cc
101
	$(CCC) $(CFLAGS) -E $< -o $@
102
%.debug.i %.release.i : %.cpp
Josh Coalson's avatar
Josh Coalson committed
103
	$(CCC) $(CFLAGS) -E $< -o $@
Josh Coalson's avatar
Josh Coalson committed
104

105 106 107 108 109 110 111 112
%.debug.o %.release.o : %.s
ifeq ($(DARWIN_BUILD),yes)
	#$(CC) -c -arch ppc -Wall -force_cpusubtype_ALL $< -o $@
	$(AS) -arch ppc -force_cpusubtype_ALL $< -o $@
else
	$(AS) $< -o $@
endif

113
%.debug.o %.release.o : %.nasm
Josh Coalson's avatar
Josh Coalson committed
114
	$(NASM) -f elf -d OBJ_FORMAT_elf -i ia32/ $< -o $@
Josh Coalson's avatar
Josh Coalson committed
115

Josh Coalson's avatar
Josh Coalson committed
116 117
.PHONY : clean
clean :
118
	-rm -f $(DEBUG_OBJS) $(RELEASE_OBJS) $(OBJPATH)/*/lib/$(STATIC_LIB_NAME) $(OBJPATH)/*/lib/$(DYNAMIC_LIB_NAME)
Josh Coalson's avatar
Josh Coalson committed
119 120 121

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