shithub: openh264

Download patch

ref: dc2d799d2b60348a9af9add060bb7d08dd9107bf
parent: 0c438ecdd39e645a0f6315c6bea413fc214e6fd6
parent: 6e75136201fd193873e263d450a6966a1c1d2c11
author: Ethan Hugg <[email protected]>
date: Fri Jan 17 03:49:00 EST 2014

Merge pull request #150 from mstorsjo/msvc-make

Support building with MSVC via the makefiles by doing "make UNAME=msvc"

--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,14 @@
 LIBSUFFIX=a
 CP=cp
 ROOTDIR=$(PWD)
+CXX_O=-o $@
+CXX_LINK_O=-o $@
+AR_OPTS=cr $@
+LINK_LIB=-l$(1)
+CFLAGS_OPT=-O3
+CFLAGS_DEBUG=-g
+CFLAGS_M32=-m32
+CFLAGS_M64=-m64
 
 
 
@@ -14,10 +22,10 @@
 
 # Configurations
 ifeq ($(BUILDTYPE), Release)
-CFLAGS += -O3
+CFLAGS += $(CFLAGS_OPT)
 USE_ASM = Yes
 else
-CFLAGS = -g
+CFLAGS = $(CFLAGS_DEBUG)
 USE_ASM = No
 endif
 
@@ -27,12 +35,12 @@
 endif
 
 ifeq ($(ENABLE64BIT), Yes)
-CFLAGS += -m64
-LDFLAGS += -m64
+CFLAGS += $(CFLAGS_M64)
+LDFLAGS += $(CFLAGS_M64)
 ASMFLAGS_PLATFORM = -DUNIX64
 else
-CFLAGS += -m32
-LDFLAGS += -m32
+CFLAGS += $(CFLAGS_M32)
+LDFLAGS += $(CFLAGS_M32)
 ASMFLAGS_PLATFORM = -DX86_32
 endif
 
@@ -69,11 +77,11 @@
     -Icodec/encoder/plus/inc
 
 H264DEC_INCLUDES = $(DECODER_INCLUDES) -Icodec/console/dec/inc
-H264DEC_LDFLAGS = -L. -ldecoder -lcommon
+H264DEC_LDFLAGS = -L. $(call LINK_LIB, decoder) $(call LINK_LIB, common)
 H264DEC_DEPS = $(LIBPREFIX)decoder.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
 
 H264ENC_INCLUDES = $(ENCODER_INCLUDES) -Icodec/console/enc/inc
-H264ENC_LDFLAGS = -L. -lencoder -lprocessing -lcommon
+H264ENC_LDFLAGS = -L. $(call LINK_LIB, encoder) $(call LINK_LIB, processing) $(call LINK_LIB, common)
 H264ENC_DEPS = $(LIBPREFIX)encoder.$(LIBSUFFIX) $(LIBPREFIX)processing.$(LIBSUFFIX) $(LIBPREFIX)common.$(LIBSUFFIX)
 
 CODEC_UNITTEST_LDFLAGS = -L. -lgtest -ldecoder -lcrypto -lencoder -lprocessing -lcommon
--- a/build/mktargets.py
+++ b/build/mktargets.py
@@ -21,7 +21,7 @@
     dst = "$(%s_SRCDIR)/%%.o"%(PREFIX)
 
     f.write("%s: %s\n"%(dst, src))
-    f.write('\t$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c -o $@ $<\n');
+    f.write('\t$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(' + PREFIX + '_CFLAGS) $(' + PREFIX + '_INCLUDES) -c $(CXX_O) $<\n');
     f.write("\n")
 
 def write_asm_rule_pattern(f):
@@ -90,7 +90,7 @@
 if args.library is not None:
     f.write("$(LIBPREFIX)%s.$(LIBSUFFIX): $(%s_OBJS)\n"%(args.library, PREFIX));
     f.write("\trm -f $(LIBPREFIX)%s.$(LIBSUFFIX)\n"%args.library)
-    f.write("\t$(AR) cr $@ $(%s_OBJS)\n"%PREFIX);
+    f.write("\t$(AR) $(AR_OPTS) $(%s_OBJS)\n"%PREFIX);
     f.write("\n");
     f.write("libraries: $(LIBPREFIX)%s.$(LIBSUFFIX)\n"%args.library);
     f.write("LIBRARIES += $(LIBPREFIX)%s.$(LIBSUFFIX)\n"%args.library);
@@ -97,6 +97,6 @@
 
 if args.binary is not None:
     f.write("%s: $(%s_OBJS) $(LIBS) $(%s_LIBS) $(%s_DEPS)\n"%(args.binary, PREFIX, PREFIX, PREFIX))
-    f.write("\t$(CXX) -o $@  $(%s_OBJS) $(%s_LDFLAGS) $(%s_LIBS) $(LDFLAGS) $(LIBS)\n\n"%(PREFIX, PREFIX, PREFIX))
+    f.write("\t$(CXX) $(CXX_LINK_O)  $(%s_OBJS) $(%s_LDFLAGS) $(%s_LIBS) $(LDFLAGS) $(LIBS)\n\n"%(PREFIX, PREFIX, PREFIX))
     f.write("binaries: %s\n"%args.binary);
     f.write("BINARIES += %s\n"%args.binary);
--- /dev/null
+++ b/build/platform-msvc-arm.mk
@@ -1,0 +1,5 @@
+include build/platform-msvc-common.mk
+CFLAGS += -DWINAPI_FAMILY=WINAPI_FAMILY_PHONE_APP -MD -DWIN32
+LDFLAGS +=
+USE_ASM = No
+
--- /dev/null
+++ b/build/platform-msvc-common.mk
@@ -1,0 +1,13 @@
+CXX=cl
+AR=lib
+CXX_O=-Fo$@
+CFLAGS += -nologo
+CXX_LINK_O=-nologo -Fe$@
+AR_OPTS=-nologo -out:$@
+CFLAGS_OPT=-O2
+CFLAGS_DEBUG=
+CFLAGS_M32=
+CFLAGS_M64=
+LINK_LIB=$(1).lib
+LIBSUFFIX=lib
+LIBPREFIX=
--- /dev/null
+++ b/build/platform-msvc.mk
@@ -1,0 +1,12 @@
+include build/platform-msvc-common.mk
+ASM = nasm
+LDFLAGS += user32.lib
+ifeq ($(ENABLE64BIT), Yes)
+ASMFLAGS += -f win64
+ASMFLAGS_PLATFORM = -DWIN64
+CFLAGS += -DWIN64
+else
+ASMFLAGS += -f win32 -DPREFIX
+CFLAGS += -DWIN32
+endif
+
--- a/codec/build/win32/dec/decConsole.vcproj
+++ b/codec/build/win32/dec/decConsole.vcproj
@@ -74,6 +74,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="$(OutDir)\welsdec.lib"
 				OutputFile="$(OutDir)\decConsole.exe"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
@@ -166,6 +167,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="$(OutDir)\welsdec.lib"
 				OutputFile="$(OutDir)\decConsole.exe"
 				LinkIncremental="1"
 				SuppressStartupBanner="true"
@@ -258,6 +260,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="$(OutDir)\welsdec.lib"
 				OutputFile="$(OutDir)\decConsoled.exe"
 				LinkIncremental="2"
 				SuppressStartupBanner="true"
@@ -351,6 +354,7 @@
 			/>
 			<Tool
 				Name="VCLinkerTool"
+				AdditionalDependencies="$(OutDir)\welsdec.lib"
 				OutputFile="$(OutDir)\decConsoled.exe"
 				LinkIncremental="2"
 				SuppressStartupBanner="true"
--- a/codec/common/targets.mk
+++ b/codec/common/targets.mk
@@ -22,7 +22,7 @@
 
 OBJS += $(COMMON_OBJS)
 $(COMMON_SRCDIR)/%.o: $(COMMON_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(COMMON_CFLAGS) $(COMMON_INCLUDES) -c $(CXX_O) $<
 
 $(COMMON_SRCDIR)/%.o: $(COMMON_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(COMMON_ASMFLAGS) $(COMMON_ASM_INCLUDES) -o $@ $<
@@ -29,7 +29,7 @@
 
 $(LIBPREFIX)common.$(LIBSUFFIX): $(COMMON_OBJS)
 	rm -f $(LIBPREFIX)common.$(LIBSUFFIX)
-	$(AR) cr $@ $(COMMON_OBJS)
+	$(AR) $(AR_OPTS) $(COMMON_OBJS)
 
 libraries: $(LIBPREFIX)common.$(LIBSUFFIX)
 LIBRARIES += $(LIBPREFIX)common.$(LIBSUFFIX)
--- a/codec/console/dec/src/h264dec.cpp
+++ b/codec/console/dec/src/h264dec.cpp
@@ -433,41 +433,11 @@
 
 
 
-#if defined(_MSC_VER)
-
-  HMODULE hModule = LoadLibraryA (".\\welsdec.dll");
-
-  PCreateDecoderFunc  pCreateDecoderFunc				= NULL;
-  PDestroyDecoderFunc pDestroyDecoderFunc				= NULL;
-
-
-  pCreateDecoderFunc  = (PCreateDecoderFunc)::GetProcAddress (hModule, "CreateDecoder");
-  pDestroyDecoderFunc = (PDestroyDecoderFunc)::GetProcAddress (hModule, "DestroyDecoder");
-
-  if ((hModule != NULL) && (pCreateDecoderFunc != NULL) && (pDestroyDecoderFunc != NULL)) {
-    printf ("load library sw function successfully\n");
-
-    if (pCreateDecoderFunc (&pDecoder)  || (NULL == pDecoder)) {
-      printf ("Create Decoder failed.\n");
-      return 1;
-    }
-  } else {
-    printf ("load library sw function failed\n");
-    return 1;
-  }
-
-
-#else
-
-
   if (CreateDecoder (&pDecoder)  || (NULL == pDecoder)) {
     printf ("Create Decoder failed.\n");
     return 1;
   }
 
-#endif
-
-
   if (pDecoder->Initialize (&sDecParam, INIT_TYPE_PARAMETER_BASED)) {
     printf ("Decoder initialization failed.\n");
     return 1;
@@ -489,11 +459,7 @@
   if (pDecoder) {
     pDecoder->Uninitialize();
 
-#if defined(_MSC_VER)
-    pDestroyDecoderFunc (pDecoder);
-#else
     DestroyDecoder (pDecoder);
-#endif
   }
 
   return 0;
--- a/codec/console/dec/targets.mk
+++ b/codec/console/dec/targets.mk
@@ -14,13 +14,13 @@
 
 OBJS += $(H264DEC_OBJS)
 $(H264DEC_SRCDIR)/%.o: $(H264DEC_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(H264DEC_CFLAGS) $(H264DEC_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(H264DEC_CFLAGS) $(H264DEC_INCLUDES) -c $(CXX_O) $<
 
 $(H264DEC_SRCDIR)/%.o: $(H264DEC_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(H264DEC_ASMFLAGS) $(H264DEC_ASM_INCLUDES) -o $@ $<
 
 h264dec: $(H264DEC_OBJS) $(LIBS) $(H264DEC_LIBS) $(H264DEC_DEPS)
-	$(CXX) -o $@  $(H264DEC_OBJS) $(H264DEC_LDFLAGS) $(H264DEC_LIBS) $(LDFLAGS) $(LIBS)
+	$(CXX) $(CXX_LINK_O)  $(H264DEC_OBJS) $(H264DEC_LDFLAGS) $(H264DEC_LIBS) $(LDFLAGS) $(LIBS)
 
 binaries: h264dec
 BINARIES += h264dec
--- a/codec/console/enc/targets.mk
+++ b/codec/console/enc/targets.mk
@@ -13,13 +13,13 @@
 
 OBJS += $(H264ENC_OBJS)
 $(H264ENC_SRCDIR)/%.o: $(H264ENC_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(H264ENC_CFLAGS) $(H264ENC_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(H264ENC_CFLAGS) $(H264ENC_INCLUDES) -c $(CXX_O) $<
 
 $(H264ENC_SRCDIR)/%.o: $(H264ENC_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(H264ENC_ASMFLAGS) $(H264ENC_ASM_INCLUDES) -o $@ $<
 
 h264enc: $(H264ENC_OBJS) $(LIBS) $(H264ENC_LIBS) $(H264ENC_DEPS)
-	$(CXX) -o $@  $(H264ENC_OBJS) $(H264ENC_LDFLAGS) $(H264ENC_LIBS) $(LDFLAGS) $(LIBS)
+	$(CXX) $(CXX_LINK_O)  $(H264ENC_OBJS) $(H264ENC_LDFLAGS) $(H264ENC_LIBS) $(LDFLAGS) $(LIBS)
 
 binaries: h264enc
 BINARIES += h264enc
--- a/codec/decoder/targets.mk
+++ b/codec/decoder/targets.mk
@@ -36,7 +36,7 @@
 
 OBJS += $(DECODER_OBJS)
 $(DECODER_SRCDIR)/%.o: $(DECODER_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(DECODER_CFLAGS) $(DECODER_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(DECODER_CFLAGS) $(DECODER_INCLUDES) -c $(CXX_O) $<
 
 $(DECODER_SRCDIR)/%.o: $(DECODER_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(DECODER_ASMFLAGS) $(DECODER_ASM_INCLUDES) -o $@ $<
@@ -43,7 +43,7 @@
 
 $(LIBPREFIX)decoder.$(LIBSUFFIX): $(DECODER_OBJS)
 	rm -f $(LIBPREFIX)decoder.$(LIBSUFFIX)
-	$(AR) cr $@ $(DECODER_OBJS)
+	$(AR) $(AR_OPTS) $(DECODER_OBJS)
 
 libraries: $(LIBPREFIX)decoder.$(LIBSUFFIX)
 LIBRARIES += $(LIBPREFIX)decoder.$(LIBSUFFIX)
--- a/codec/encoder/targets.mk
+++ b/codec/encoder/targets.mk
@@ -50,7 +50,7 @@
 
 OBJS += $(ENCODER_OBJS)
 $(ENCODER_SRCDIR)/%.o: $(ENCODER_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(ENCODER_CFLAGS) $(ENCODER_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(ENCODER_CFLAGS) $(ENCODER_INCLUDES) -c $(CXX_O) $<
 
 $(ENCODER_SRCDIR)/%.o: $(ENCODER_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(ENCODER_ASMFLAGS) $(ENCODER_ASM_INCLUDES) -o $@ $<
@@ -57,7 +57,7 @@
 
 $(LIBPREFIX)encoder.$(LIBSUFFIX): $(ENCODER_OBJS)
 	rm -f $(LIBPREFIX)encoder.$(LIBSUFFIX)
-	$(AR) cr $@ $(ENCODER_OBJS)
+	$(AR) $(AR_OPTS) $(ENCODER_OBJS)
 
 libraries: $(LIBPREFIX)encoder.$(LIBSUFFIX)
 LIBRARIES += $(LIBPREFIX)encoder.$(LIBSUFFIX)
--- a/codec/processing/targets.mk
+++ b/codec/processing/targets.mk
@@ -35,7 +35,7 @@
 
 OBJS += $(PROCESSING_OBJS)
 $(PROCESSING_SRCDIR)/%.o: $(PROCESSING_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(PROCESSING_CFLAGS) $(PROCESSING_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(PROCESSING_CFLAGS) $(PROCESSING_INCLUDES) -c $(CXX_O) $<
 
 $(PROCESSING_SRCDIR)/%.o: $(PROCESSING_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(PROCESSING_ASMFLAGS) $(PROCESSING_ASM_INCLUDES) -o $@ $<
@@ -42,7 +42,7 @@
 
 $(LIBPREFIX)processing.$(LIBSUFFIX): $(PROCESSING_OBJS)
 	rm -f $(LIBPREFIX)processing.$(LIBSUFFIX)
-	$(AR) cr $@ $(PROCESSING_OBJS)
+	$(AR) $(AR_OPTS) $(PROCESSING_OBJS)
 
 libraries: $(LIBPREFIX)processing.$(LIBSUFFIX)
 LIBRARIES += $(LIBPREFIX)processing.$(LIBSUFFIX)
--- a/test/targets.mk
+++ b/test/targets.mk
@@ -14,13 +14,13 @@
 
 OBJS += $(CODEC_UNITTEST_OBJS)
 $(CODEC_UNITTEST_SRCDIR)/%.o: $(CODEC_UNITTEST_SRCDIR)/%.cpp
-	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c -o $@ $<
+	$(CXX) $(CFLAGS) $(CXXFLAGS) $(INCLUDES) $(CODEC_UNITTEST_CFLAGS) $(CODEC_UNITTEST_INCLUDES) -c $(CXX_O) $<
 
 $(CODEC_UNITTEST_SRCDIR)/%.o: $(CODEC_UNITTEST_SRCDIR)/%.asm
 	$(ASM) $(ASMFLAGS) $(ASM_INCLUDES) $(CODEC_UNITTEST_ASMFLAGS) $(CODEC_UNITTEST_ASM_INCLUDES) -o $@ $<
 
 codec_unittest: $(CODEC_UNITTEST_OBJS) $(LIBS) $(CODEC_UNITTEST_LIBS) $(CODEC_UNITTEST_DEPS)
-	$(CXX) -o $@  $(CODEC_UNITTEST_OBJS) $(CODEC_UNITTEST_LDFLAGS) $(CODEC_UNITTEST_LIBS) $(LDFLAGS) $(LIBS)
+	$(CXX) $(CXX_LINK_O)  $(CODEC_UNITTEST_OBJS) $(CODEC_UNITTEST_LDFLAGS) $(CODEC_UNITTEST_LIBS) $(LDFLAGS) $(LIBS)
 
 binaries: codec_unittest
 BINARIES += codec_unittest