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 an executable
20#
21
22include $(topdir)/build/config.mk
23
24ifeq ($(DARWIN_BUILD),yes)
25CC          = cc
26CCC         = c++
27else
28CC          = gcc
29CCC         = g++
30endif
31NASM        = nasm
32LINK        = $(CC) $(LINKAGE)
33OBJPATH     = $(topdir)/obj
34BINPATH     = $(OBJPATH)/$(BUILD)/bin
35LIBPATH     = $(OBJPATH)/$(BUILD)/lib
36DEBUG_BINPATH   = $(OBJPATH)/debug/bin
37DEBUG_LIBPATH   = $(OBJPATH)/debug/lib
38RELEASE_BINPATH = $(OBJPATH)/release/bin
39RELEASE_LIBPATH = $(OBJPATH)/release/lib
40PROGRAM         = $(BINPATH)/$(PROGRAM_NAME)
41DEBUG_PROGRAM   = $(DEBUG_BINPATH)/$(PROGRAM_NAME)
42RELEASE_PROGRAM = $(RELEASE_BINPATH)/$(PROGRAM_NAME)
43
44debug   : CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -W -Wall -Wmissing-prototypes -Wstrict-prototypes -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
45valgrind: CFLAGS = -g -O0 -DDEBUG $(CONFIG_CFLAGS) $(DEBUG_CFLAGS) -DFLAC__VALGRIND_TESTING -W -Wall -Wmissing-prototypes -Wstrict-prototypes -DVERSION=$(VERSION) $(DEFINES) $(INCLUDES)
46release : 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)
47
48LFLAGS  = -L$(LIBPATH)
49
50DEBUG_OBJS = $(SRCS_C:%.c=%.debug.o) $(SRCS_CC:%.cc=%.debug.o) $(SRCS_CPP:%.cpp=%.debug.o) $(SRCS_NASM:%.nasm=%.debug.o)
51RELEASE_OBJS = $(SRCS_C:%.c=%.release.o) $(SRCS_CC:%.cc=%.release.o) $(SRCS_CPP:%.cpp=%.release.o) $(SRCS_NASM:%.nasm=%.release.o)
52
53debug   : $(DEBUG_PROGRAM)
54valgrind: $(DEBUG_PROGRAM)
55release : $(RELEASE_PROGRAM)
56
57# by default on OS X we link with static libs as much as possible
58
59$(DEBUG_PROGRAM) : $(DEBUG_OBJS)
60ifeq ($(DARWIN_BUILD),yes)
61	$(LINK) -o $@ $(DEBUG_OBJS) $(EXPLICIT_LIBS)
62else
63	$(LINK) -o $@ $(DEBUG_OBJS) $(LFLAGS) $(LIBS)
64endif
65
66$(RELEASE_PROGRAM) : $(RELEASE_OBJS)
67ifeq ($(DARWIN_BUILD),yes)
68	$(LINK) -o $@ $(RELEASE_OBJS) $(EXPLICIT_LIBS)
69else
70	$(LINK) -o $@ $(RELEASE_OBJS) $(LFLAGS) $(LIBS)
71endif
72
73%.debug.o %.release.o : %.c
74	$(CC) $(CFLAGS) -c $< -o $@
75%.debug.o %.release.o : %.cc
76	$(CCC) $(CFLAGS) -c $< -o $@
77%.debug.o %.release.o : %.cpp
78	$(CCC) $(CFLAGS) -c $< -o $@
79%.debug.i %.release.i : %.c
80	$(CC) $(CFLAGS) -E $< -o $@
81%.debug.i %.release.i : %.cc
82	$(CCC) $(CFLAGS) -E $< -o $@
83%.debug.i %.release.i : %.cpp
84	$(CCC) $(CFLAGS) -E $< -o $@
85
86%.debug.o : %.nasm
87	$(NASM) -f elf -d OBJ_FORMAT_elf -i ia32/ -g $< -o $@
88%.release.o : %.nasm
89	$(NASM) -f elf -d OBJ_FORMAT_elf -i ia32/ $< -o $@
90
91.PHONY : clean
92clean :
93	-rm -f $(DEBUG_OBJS) $(RELEASE_OBJS) $(OBJPATH)/*/bin/$(PROGRAM_NAME)
94
95.PHONY : depend
96depend:
97	makedepend -fMakefile.lite -- $(CFLAGS) $(INCLUDES) -- *.c *.cc *.cpp
98