1SRC_PATH=$(word 1, $(dir $(MAKEFILE_LIST))) 2vpath %.c $(SRC_PATH) 3vpath %.cc $(SRC_PATH) 4vpath %.cpp $(SRC_PATH) 5vpath %.asm $(SRC_PATH) 6vpath %.S $(SRC_PATH) 7vpath %.rc $(SRC_PATH) 8vpath %.pc.in $(SRC_PATH) 9 10OS=$(shell uname | tr A-Z a-z | tr -d \\-0-9. | sed -E 's/^(net|open|free)bsd/bsd/') 11ARCH=$(shell uname -m) 12LIBPREFIX=lib 13LIBSUFFIX=a 14CCAS=$(CC) 15CXX_O=-o $@ 16CXX_LINK_O=-o $@ 17AR_OPTS=cr $@ 18LINK_LOCAL_DIR=-L. 19LINK_LIB=-l$(1) 20CFLAGS_OPT=-O3 21CFLAGS_DEBUG=-g 22BUILDTYPE=Release 23V=Yes 24PREFIX=/usr/local 25SHARED=-shared 26OBJ=o 27DESTDIR= 28LIBDIR_NAME=lib 29SHAREDLIB_DIR=$(PREFIX)/lib 30PROJECT_NAME=openh264 31MODULE_NAME=gmpopenh264 32GMP_API_BRANCH=Firefox39 33GTEST_VER=release-1.8.1 34CCASFLAGS=$(CFLAGS) 35STATIC_LDFLAGS=-lstdc++ 36STRIP ?= strip 37USE_STACK_PROTECTOR = Yes 38 39SHAREDLIB_MAJORVERSION=6 40FULL_VERSION := 2.2.0 41 42ifeq (,$(wildcard $(SRC_PATH)gmp-api)) 43HAVE_GMP_API=No 44else 45HAVE_GMP_API=Yes 46endif 47 48ifeq (,$(wildcard $(SRC_PATH)gtest)) 49HAVE_GTEST=No 50else 51HAVE_GTEST=Yes 52endif 53 54# Configurations 55ifeq ($(BUILDTYPE), Release) 56CFLAGS += $(CFLAGS_OPT) 57CFLAGS += -DNDEBUG 58USE_ASM = Yes 59ifeq ($(DEBUGSYMBOLS), True) 60CFLAGS += -g 61CXXFLAGS += -g 62DEBUGSYMBOLS_TAG := _debug_symbols 63PROCESS_FILES := True 64endif 65else 66CFLAGS += $(CFLAGS_DEBUG) 67USE_ASM = No 68endif 69 70ifeq ($(USE_ASAN), Yes) 71CFLAGS += -fsanitize=address 72LDFLAGS += -fsanitize=address 73endif 74 75STRIP_FLAGS := -S 76ifeq (linux, $((OS))) 77STRIP_FLAGS := -g 78endif 79 80# Make sure the all target is the first one 81all: libraries binaries 82 83include $(SRC_PATH)build/platform-$(OS).mk 84 85MODULE := $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIX) 86 87CFLAGS += -DGENERATED_VERSION_HEADER 88LDFLAGS += 89 90ifeq (Yes, $(GCOV)) 91CFLAGS += -fprofile-arcs -ftest-coverage 92LDFLAGS += -lgcov 93endif 94 95#### No user-serviceable parts below this line 96ifneq ($(V),Yes) 97 QUIET_CXX = @printf "CXX\t$@\n"; 98 QUIET_CC = @printf "CC\t$@\n"; 99 QUIET_CCAS = @printf "CCAS\t$@\n"; 100 QUIET_ASM = @printf "ASM\t$@\n"; 101 QUIET_AR = @printf "AR\t$@\n"; 102 QUIET_RC = @printf "RC\t$@\n"; 103 QUIET = @ 104endif 105 106 107INCLUDES += -I$(SRC_PATH)codec/api/svc -I$(SRC_PATH)codec/common/inc -Icodec/common/inc 108 109DECODER_INCLUDES += \ 110 -I$(SRC_PATH)codec/decoder/core/inc \ 111 -I$(SRC_PATH)codec/decoder/plus/inc 112 113ENCODER_INCLUDES += \ 114 -I$(SRC_PATH)codec/encoder/core/inc \ 115 -I$(SRC_PATH)codec/encoder/plus/inc \ 116 -I$(SRC_PATH)codec/processing/interface 117 118PROCESSING_INCLUDES += \ 119 -I$(SRC_PATH)codec/processing/interface \ 120 -I$(SRC_PATH)codec/processing/src/common \ 121 -I$(SRC_PATH)codec/processing/src/adaptivequantization \ 122 -I$(SRC_PATH)codec/processing/src/downsample \ 123 -I$(SRC_PATH)codec/processing/src/scrolldetection \ 124 -I$(SRC_PATH)codec/processing/src/vaacalc 125 126GTEST_INCLUDES += \ 127 -I$(SRC_PATH)gtest/googletest \ 128 -I$(SRC_PATH)gtest/googletest/include 129 130CODEC_UNITTEST_INCLUDES += \ 131 -I$(SRC_PATH)gtest/googletest/include \ 132 -I$(SRC_PATH)codec/common/inc \ 133 -I$(SRC_PATH)test 134 135CONSOLE_COMMON_INCLUDES += \ 136 -I$(SRC_PATH)codec/console/common/inc 137 138H264DEC_INCLUDES += $(DECODER_INCLUDES) $(CONSOLE_COMMON_INCLUDES) -I$(SRC_PATH)codec/console/dec/inc 139H264DEC_LDFLAGS = $(LINK_LOCAL_DIR) $(call LINK_LIB,decoder) $(call LINK_LIB,common) $(call LINK_LIB,console_common) 140H264DEC_DEPS = $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX) $(LIBPREFIX)console_common.$(LIBSUFFIX) 141 142H264ENC_INCLUDES += $(ENCODER_INCLUDES) $(CONSOLE_COMMON_INCLUDES) -I$(SRC_PATH)codec/console/enc/inc 143H264ENC_LDFLAGS = $(LINK_LOCAL_DIR) $(call LINK_LIB,encoder) $(call LINK_LIB,processing) $(call LINK_LIB,common) $(call LINK_LIB,console_common) 144H264ENC_DEPS = $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX) $(LIBPREFIX)console_common.$(LIBSUFFIX) 145 146CODEC_UNITTEST_LDFLAGS = $(LINK_LOCAL_DIR) $(call LINK_LIB,gtest) $(call LINK_LIB,decoder) $(call LINK_LIB,encoder) $(call LINK_LIB,processing) $(call LINK_LIB,common) $(CODEC_UNITTEST_LDFLAGS_SUFFIX) 147CODEC_UNITTEST_DEPS = $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX) 148DECODER_UNITTEST_INCLUDES += $(CODEC_UNITTEST_INCLUDES) $(DECODER_INCLUDES) 149ENCODER_UNITTEST_INCLUDES += $(CODEC_UNITTEST_INCLUDES) $(ENCODER_INCLUDES) 150PROCESSING_UNITTEST_INCLUDES += $(CODEC_UNITTEST_INCLUDES) $(PROCESSING_INCLUDES) 151API_TEST_INCLUDES += $(CODEC_UNITTEST_INCLUDES) 152COMMON_UNITTEST_INCLUDES += $(CODEC_UNITTEST_INCLUDES) 153MODULE_INCLUDES += -I$(SRC_PATH)gmp-api 154 155DECODER_UNITTEST_CFLAGS += $(CODEC_UNITTEST_CFLAGS) 156ENCODER_UNITTEST_CFLAGS += $(CODEC_UNITTEST_CFLAGS) 157PROCESSING_UNITTEST_CFLAGS += $(CODEC_UNITTEST_CFLAGS) 158API_TEST_CFLAGS += $(CODEC_UNITTEST_CFLAGS) 159COMMON_UNITTEST_CFLAGS += $(CODEC_UNITTEST_CFLAGS) 160 161.PHONY: test gtest-bootstrap clean $(PROJECT_NAME).pc $(PROJECT_NAME)-static.pc 162 163generate-version: 164 $(QUIET)sh $(SRC_PATH)codec/common/generate_version.sh $(SRC_PATH) 165 166codec/decoder/plus/src/welsDecoderExt.$(OBJ): | generate-version 167codec/encoder/plus/src/welsEncoderExt.$(OBJ): | generate-version 168 169clean: 170ifeq (android,$(OS)) 171clean: clean_Android 172endif 173 $(QUIET)rm -f $(OBJS) $(OBJS:.$(OBJ)=.d) $(OBJS:.$(OBJ)=.obj) $(LIBRARIES) $(BINARIES) *.lib *.a *.dylib *.dll *.so *.so.* *.exe *.pdb *.exp *.pc *.res *.map $(SRC_PATH)codec/common/inc/version_gen.h 174 175gmp-bootstrap: 176 if [ ! -d gmp-api ] ; then git clone https://github.com/mozilla/gmp-api gmp-api ; fi 177 cd gmp-api && git fetch origin && git checkout $(GMP_API_BRANCH) 178 179gtest-bootstrap: 180 if [ ! -d gtest ] ; then git clone https://github.com/google/googletest.git gtest && \ 181 cd gtest && git checkout -b $(GTEST_VER) $(GTEST_VER) ; fi 182 183ifeq ($(HAVE_GTEST),Yes) 184 185ifneq (android,$(OS)) 186ifneq (ios,$(OS)) 187ifneq (msvc-wp,$(OS)) 188BUILD_UT_EXE=Yes 189endif 190endif 191endif 192 193test: codec_unittest$(EXEEXT) 194ifeq ($(BUILD_UT_EXE), Yes) 195 ./codec_unittest 196endif 197 198else 199test: 200 @echo "./gtest: No such file or directory." 201 @echo "You do not have gtest. Run make gtest-bootstrap to get gtest" 202endif 203 204include $(SRC_PATH)codec/common/targets.mk 205include $(SRC_PATH)codec/decoder/targets.mk 206include $(SRC_PATH)codec/encoder/targets.mk 207include $(SRC_PATH)codec/processing/targets.mk 208 209ifeq ($(HAVE_GMP_API),Yes) 210include $(SRC_PATH)module/targets.mk 211endif 212 213ifneq (android, $(OS)) 214ifneq (ios, $(OS)) 215ifneq (msvc-wp, $(OS)) 216include $(SRC_PATH)codec/console/dec/targets.mk 217include $(SRC_PATH)codec/console/enc/targets.mk 218include $(SRC_PATH)codec/console/common/targets.mk 219endif 220endif 221endif 222 223libraries: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) 224 225# No point in building dylib for ios 226ifneq (ios, $(OS)) 227libraries: $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) 228endif 229 230LIBRARIES += $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER) 231 232$(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX): $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS) 233 $(QUIET)rm -f $@ 234 $(QUIET_AR)$(AR) $(AR_OPTS) $+ 235ifeq (True, $(PROCESS_FILES)) 236 cp $@ $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(LIBSUFFIX) 237 $(STRIP) $(STRIP_FLAGS) $@ -o $@ 238endif 239 240$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER): $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS) 241 $(QUIET)rm -f $@ 242 $(QUIET_CXX)$(CXX) $(SHARED) $(CXX_LINK_O) $+ $(LDFLAGS) $(SHLDFLAGS) 243ifeq (True, $(PROCESS_FILES)) 244 cp $@ $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXFULLVER) 245 $(STRIP) $(STRIP_FLAGS) $@ -o $@ 246endif 247 248ifneq ($(SHAREDLIBSUFFIXFULLVER),$(SHAREDLIBSUFFIX)) 249$(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX): $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER) 250 $(QUIET)ln -sfn $+ $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER) 251 $(QUIET)ln -sfn $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER) $@ 252ifeq (True, $(PROCESS_FILES)) 253 $(QUIET)ln -sfn $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXFULLVER) $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXMAJORVER) 254 $(QUIET)ln -sfn $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXMAJORVER) $(LIBPREFIX)$(PROJECT_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIX) 255endif 256endif 257 258ifeq ($(HAVE_GMP_API),Yes) 259plugin: $(MODULE) 260LIBRARIES += $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXFULLVER) 261else 262plugin: 263 @echo "./gmp-api: No such file or directory." 264 @echo "You do not have gmp-api. Run make gmp-bootstrap to get the gmp-api headers." 265endif 266 267echo-plugin-name: 268 @echo $(MODULE) 269 270$(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXFULLVER): $(MODULE_OBJS) $(ENCODER_OBJS) $(DECODER_OBJS) $(PROCESSING_OBJS) $(COMMON_OBJS) 271 $(QUIET)rm -f $@ 272 $(QUIET_CXX)$(CXX) $(SHARED) $(CXX_LINK_O) $+ $(LDFLAGS) $(SHLDFLAGS) $(MODULE_LDFLAGS) 273ifeq (True, $(PROCESS_FILES)) 274 cp $@ $(LIBPREFIX)$(MODULE_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXFULLVER) 275 $(STRIP) $(STRIP_FLAGS) $@ -o $@ 276endif 277 278ifneq ($(SHAREDLIBSUFFIXFULLVER),$(SHAREDLIBSUFFIX)) 279$(MODULE): $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXFULLVER) 280 $(QUIET)ln -sfn $+ $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXMAJORVER) 281 $(QUIET)ln -sfn $(LIBPREFIX)$(MODULE_NAME).$(SHAREDLIBSUFFIXMAJORVER) $@ 282ifeq (True, $(PROCESS_FILES)) 283 $(QUIET)ln -sfn $(LIBPREFIX)$(MODULE_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXFULLVER) $(LIBPREFIX)$(MODULE_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXMAJORVER) 284 $(QUIET)ln -sfn $(LIBPREFIX)$(MODULE_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIXMAJORVER) $(LIBPREFIX)$(MODULE_NAME)$(DEBUGSYMBOLS_TAG).$(SHAREDLIBSUFFIX) 285endif 286endif 287 288$(PROJECT_NAME).pc: $(PROJECT_NAME).pc.in 289 @sed -e 's;@prefix@;$(PREFIX);' -e 's;@libdir@;$(PREFIX)/lib;' -e 's;@VERSION@;$(FULL_VERSION);' -e 's;@LIBS@;;' -e 's;@LIBS_PRIVATE@;$(STATIC_LDFLAGS);' < $< > $@ 290 291$(PROJECT_NAME)-static.pc: $(PROJECT_NAME).pc.in 292 @sed -e 's;@prefix@;$(PREFIX);' -e 's;@libdir@;$(PREFIX)/lib;' -e 's;@VERSION@;$(FULL_VERSION);' -e 's;@LIBS@;$(STATIC_LDFLAGS);' -e 's;@LIBS_PRIVATE@;;' < $< > $@ 293 294install-headers: 295 mkdir -p $(DESTDIR)$(PREFIX)/include/wels 296 install -m 644 $(SRC_PATH)/codec/api/svc/codec*.h $(DESTDIR)$(PREFIX)/include/wels 297 298install-static-lib: $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) install-headers 299 mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME) 300 install -m 644 $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME) 301 302install-static: install-static-lib $(PROJECT_NAME)-static.pc 303 mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig 304 install -m 644 $(PROJECT_NAME)-static.pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig/$(PROJECT_NAME).pc 305 306install-shared: $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) install-headers $(PROJECT_NAME).pc 307 mkdir -p $(DESTDIR)$(SHAREDLIB_DIR) 308 install -m 755 $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXFULLVER) $(DESTDIR)$(SHAREDLIB_DIR) 309 if [ "$(SHAREDLIBSUFFIXFULLVER)" != "$(SHAREDLIBSUFFIX)" ]; then \ 310 cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIXMAJORVER) $(DESTDIR)$(SHAREDLIB_DIR) ; \ 311 cp -a $(LIBPREFIX)$(PROJECT_NAME).$(SHAREDLIBSUFFIX) $(DESTDIR)$(SHAREDLIB_DIR) ; \ 312 fi 313 mkdir -p $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig 314 install -m 644 $(PROJECT_NAME).pc $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME)/pkgconfig 315ifneq ($(EXTRA_LIBRARY),) 316 install -m 644 $(EXTRA_LIBRARY) $(DESTDIR)$(PREFIX)/$(LIBDIR_NAME) 317endif 318 319install: install-static-lib install-shared 320 @: 321 322ifneq ($(HAVE_GTEST),Yes) 323binaries: 324 @: 325else 326include $(SRC_PATH)build/gtest-targets.mk 327include $(SRC_PATH)test/api/targets.mk 328include $(SRC_PATH)test/decoder/targets.mk 329include $(SRC_PATH)test/encoder/targets.mk 330include $(SRC_PATH)test/processing/targets.mk 331include $(SRC_PATH)test/common/targets.mk 332 333LIBRARIES += $(LIBPREFIX)ut.$(LIBSUFFIX) 334$(LIBPREFIX)ut.$(LIBSUFFIX): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(COMMON_UNITTEST_OBJS) $(API_TEST_OBJS) 335 $(QUIET)rm -f $@ 336 $(QUIET_AR)$(AR) $(AR_OPTS) $+ 337 338 339LIBRARIES +=$(LIBPREFIX)ut.$(SHAREDLIBSUFFIX) 340$(LIBPREFIX)ut.$(SHAREDLIBSUFFIX): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(API_TEST_OBJS) $(COMMON_UNITTEST_OBJS) $(CODEC_UNITTEST_DEPS) 341 $(QUIET)rm -f $@ 342 $(QUIET_CXX)$(CXX) $(SHARED) $(CXX_LINK_O) $+ $(LDFLAGS) $(UTSHLDFLAGS) $(CODEC_UNITTEST_LDFLAGS) 343 344binaries: codec_unittest$(EXEEXT) 345BINARIES += codec_unittest$(EXEEXT) 346 347ifeq ($(BUILD_UT_EXE), Yes) 348# Build a normal command line executable 349codec_unittest$(EXEEXT): $(DECODER_UNITTEST_OBJS) $(ENCODER_UNITTEST_OBJS) $(PROCESSING_UNITTEST_OBJS) $(API_TEST_OBJS) $(COMMON_UNITTEST_OBJS) $(CODEC_UNITTEST_DEPS) | res 350 $(QUIET)rm -f $@ 351 $(QUIET_CXX)$(CXX) $(CXX_LINK_O) $+ $(CODEC_UNITTEST_LDFLAGS) $(LDFLAGS) 352 353res: 354 $(QUIET)if [ ! -e res ]; then ln -s $(SRC_PATH)res .; fi 355else 356 357# Build the unit test suite into a library that is included in a project file 358ifeq (ios,$(OS)) 359codec_unittest$(EXEEXT): $(LIBPREFIX)ut.$(LIBSUFFIX) $(LIBPREFIX)gtest.$(LIBSUFFIX) $(LIBPREFIX)$(PROJECT_NAME).$(LIBSUFFIX) 360else 361codec_unittest$(EXEEXT): $(LIBPREFIX)ut.$(SHAREDLIBSUFFIX) 362endif 363 364ifeq (android,$(OS)) 365ifeq (./,$(SRC_PATH)) 366codec_unittest$(EXEEXT): 367 cd ./test/build/android && $(NDKROOT)/ndk-build -B APP_ABI=$(APP_ABI) && android update project -t $(TARGET) -p . && ant debug 368 369clean_Android: clean_Android_ut 370clean_Android_ut: 371 -cd ./test/build/android && $(NDKROOT)/ndk-build APP_ABI=$(APP_ABI) clean && ant clean 372endif 373endif 374 375endif 376endif 377 378-include $(OBJS:.$(OBJ)=.d) 379 380OBJDIRS = $(sort $(dir $(OBJS))) 381 382$(OBJDIRS): 383 $(QUIET)mkdir -p $@ 384 385$(OBJS): | $(OBJDIRS) 386