Further updates to the Makefile.lite build system.
[flac.git] / build / lib.mk
blob5d81f8f5b30195143e5846ae68fb622a80b3f63f
1 # FLAC - Free Lossless Audio Codec
2 # Copyright (C) 2001-2009 Josh Coalson
3 # Copyright (C) 2011-2013 Xiph.Org Foundation
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.
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.
20 # GNU makefile fragment for building a library
23 include $(topdir)/build/config.mk
25 ifeq ($(OS),Darwin)
26 CC = cc
27 CCC = c++
28 else
29 CC = gcc
30 CCC = g++
31 endif
32 AS = as
33 NASM = nasm
34 LINK = ar cru
35 OBJPATH = $(topdir)/objs
36 LIBPATH = $(OBJPATH)/$(BUILD)/lib
37 DEBUG_LIBPATH = $(OBJPATH)/debug/lib
38 RELEASE_LIBPATH = $(OBJPATH)/release/lib
39 ifeq ($(OS),Darwin)
40 STATIC_LIB_SUFFIX = a
41 DYNAMIC_LIB_SUFFIX = dylib
42 else
43 ifeq ($(findstring Windows,$(OS)),Windows)
44 STATIC_LIB_SUFFIX = a
45 DYNAMIC_LIB_SUFFIX = dll
46 else
47 STATIC_LIB_SUFFIX = a
48 DYNAMIC_LIB_SUFFIX = so
49 endif
50 endif
51 STATIC_LIB_NAME = $(LIB_NAME).$(STATIC_LIB_SUFFIX)
52 DYNAMIC_LIB_NAME = $(LIB_NAME).$(DYNAMIC_LIB_SUFFIX)
53 STATIC_LIB = $(LIBPATH)/$(STATIC_LIB_NAME)
54 DYNAMIC_LIB = $(LIBPATH)/$(DYNAMIC_LIB_NAME)
55 DEBUG_STATIC_LIB = $(DEBUG_LIBPATH)/$(STATIC_LIB_NAME)
56 DEBUG_DYNAMIC_LIB = $(DEBUG_LIBPATH)/$(DYNAMIC_LIB_NAME)
57 RELEASE_STATIC_LIB = $(RELEASE_LIBPATH)/$(STATIC_LIB_NAME)
58 RELEASE_DYNAMIC_LIB = $(RELEASE_LIBPATH)/$(DYNAMIC_LIB_NAME)
59 ifeq ($(OS),Darwin)
60 LINKD = $(CC) -dynamiclib -flat_namespace -undefined suppress -install_name $(DYNAMIC_LIB)
61 else
62 LINKD = $(CC) -shared
63 endif
65 debug : CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -W -Wall -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
66 valgrind: CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -DFLAC__VALGRIND_TESTING -W -Wall -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
67 release : CFLAGS = -O3 -fomit-frame-pointer -funroll-loops -finline-functions -DNDEBUG $(CONFIG_CFLAGS) $(RELEASE_CFLAGS) -W -Wall -Winline -DFLaC__INLINE=__inline__ -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
69 CFLAGS = $(CFLAGS) -Wmissing-prototypes -Wstrict-prototypes
70 CXXFLAGS = $(CFLAGS)
72 LFLAGS = -L$(LIBPATH)
74 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)
75 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)
76 ifeq ($(PROC),x86_64)
77 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) $(SRCS_S:%.s=%.debug.pic.o)
78 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) $(SRCS_S:%.s=%.release.pic.o)
79 endif
81 debug : $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
82 valgrind: $(DEBUG_STATIC_LIB) $(DEBUG_DYNAMIC_LIB)
83 release : $(RELEASE_STATIC_LIB) $(RELEASE_DYNAMIC_LIB)
85 $(DEBUG_STATIC_LIB): $(DEBUG_OBJS)
86 $(LINK) $@ $(DEBUG_OBJS) && ranlib $@
88 $(RELEASE_STATIC_LIB): $(RELEASE_OBJS)
89 $(LINK) $@ $(RELEASE_OBJS) && ranlib $@
91 $(DEBUG_DYNAMIC_LIB) : $(DEBUG_OBJS) $(DEBUG_PIC_OBJS)
92 ifeq ($(OS),Darwin)
93 echo Not building dynamic lib, command is: $(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS) -lc
94 else
95 ifeq ($(PROC),x86_64)
96 $(LINKD) -o $@ $(DEBUG_PIC_OBJS) $(LFLAGS) $(LIBS)
97 else
98 $(LINKD) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS)
99 endif
100 endif
102 $(RELEASE_DYNAMIC_LIB) : $(RELEASE_OBJS) $(RELEASE_PIC_OBJS)
103 ifeq ($(OS),Darwin)
104 echo Not building dynamic lib, command is: $(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS) -lc
105 else
106 ifeq ($(PROC),x86_64)
107 $(LINKD) -o $@ $(RELEASE_PIC_OBJS) $(LFLAGS) $(LIBS)
108 else
109 $(LINKD) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS)
110 endif
111 endif
113 include $(topdir)/build/compile.mk
115 .PHONY : clean
116 clean :
117 -rm -f $(DEBUG_OBJS) $(RELEASE_OBJS) $(DEBUG_PIC_OBJS) $(RELEASE_PIC_OBJS) $(OBJPATH)/*/lib/$(STATIC_LIB_NAME) $(OBJPATH)/*/lib/$(DYNAMIC_LIB_NAME)
119 .PHONY : depend
120 depend:
121 makedepend -fMakefile.lite -- $(CFLAGS) $(INCLUDES) -- *.c *.cc *.cpp