1- # This is a makefile that will build a command-line application for Linux
2- # (and hopefully similar operating systems) .
1+ # This is a makefile that will build a command-line application and library
2+ # files for Linux, macOS, BSD, and similar operating systems.
33# Requires libflac-dev (or equivalent) to be installed.
44
5+ # Detect the operating system
6+ OS := $(shell uname)
7+
58CXX := g++
6- CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -fno-aggressive-loop-optimizations
79LDFLAGS := -lFLAC
10+
11+ # Platform-specific settings
12+ # macOS (Darwin): g++ is actually clang, so avoid GCC-specific flags.
13+ # Dynamic library is .dylib on macOS, .so on Linux/BSD/etc.
14+ ifeq ($(OS ) ,Darwin)
15+ CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -fPIC
16+ DYNAMIC_LIB := libaudiomixer.dylib
17+ DYNAMIC_LDFLAGS := -dynamiclib -install_name $(DYNAMIC_LIB)
18+ else
19+ CXXFLAGS := -std=c++17 -O2 -Wall -Wextra -fPIC -fno-aggressive-loop-optimizations
20+ DYNAMIC_LIB := libaudiomixer.so
21+ DYNAMIC_LDFLAGS := -shared -Wl,-soname,$(DYNAMIC_LIB)
22+ endif
23+
24+ STATIC_LIB := libaudiomixer.a
825AUDIO_MIXER_CMDLINE_APP := audioMixer
926
1027SRC_DIR := ./common
@@ -16,21 +33,33 @@ SOURCES := \
1633 $(SRC_DIR ) /EOUtils.cpp \
1734 $(SRC_DIR ) /FLACFile.cpp \
1835 $(SRC_DIR ) /FLACFileInfo.cpp \
36+ $(SRC_DIR ) /MetadataAudioFile.cpp \
1937 $(SRC_DIR ) /utilFunctions.cpp \
2038 $(SRC_DIR ) /WAVFile.cpp \
2139 $(SRC_DIR ) /WAVFileInfo.cpp
2240
2341OBJECTS := $(SOURCES:.cpp=.o )
2442
25- .PHONY : all clean
43+ .PHONY : all libs clean
2644
27- all : $(AUDIO_MIXER_CMDLINE_APP )
45+ all : $(AUDIO_MIXER_CMDLINE_APP ) libs
46+
47+ libs : $(STATIC_LIB ) $(DYNAMIC_LIB )
2848
2949$(AUDIO_MIXER_CMDLINE_APP ) : $(OBJECTS ) $(SRC_DIR ) /cmdLineApp.cpp
3050 $(CXX ) $(CXXFLAGS ) -o $@ $(OBJECTS ) $(SRC_DIR ) /cmdLineApp.cpp $(LDFLAGS )
3151
52+ # Static library
53+ $(STATIC_LIB ) : $(OBJECTS )
54+ ar rvu $(STATIC_LIB ) $(OBJECTS )
55+ ranlib $(STATIC_LIB )
56+
57+ # Dynamic/shared library
58+ $(DYNAMIC_LIB ) : $(OBJECTS )
59+ $(CXX ) $(DYNAMIC_LDFLAGS ) -o $(DYNAMIC_LIB ) $(OBJECTS ) $(LDFLAGS )
60+
3261% .o : % .cpp % .h
3362 $(CXX ) $(CXXFLAGS ) -c $< -o $@
3463
3564clean :
36- rm -f $(AUDIO_MIXER_CMDLINE_APP ) $(OBJECTS )
65+ rm -f $(AUDIO_MIXER_CMDLINE_APP ) $(OBJECTS ) $( STATIC_LIB ) $( DYNAMIC_LIB )
0 commit comments