22GO =$(shell which go)
33DOCKER =$(shell which docker)
44
5+ # Current ffmpeg version and config
6+ FFMPEG_VERSION =ffmpeg-7.1.1
7+ # Empty variable to collect FFmpeg configuration options - will be populated dynamically
8+ FFMPEG_CONFIG =
9+
510# Build flags
611BUILD_MODULE := $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
712BUILD_LD_FLAGS += -X $(BUILD_MODULE ) /pkg/version.GitSource=${BUILD_MODULE}
@@ -21,11 +26,65 @@ DOCKER_REGISTRY ?= ghcr.io/mutablelogic
2126BUILD_DIR := "build"
2227CMD_DIR := $(filter-out cmd/ffmpeg/README.md, $(wildcard cmd/ffmpeg/* ) )
2328BUILD_TAG := ${DOCKER_REGISTRY}/go-media-${OS}-${ARCH}:${VERSION}
29+ PREFIX ?= ${BUILD_DIR}/install
30+
31+ # ##############################################################################
32+ # TARGETS
2433
25- all : clean cmds
34+ .PHONY : all
35+ all : clean ffinstall cli
2636
37+ .PHONY : cmds
2738cmds : $(CMD_DIR )
2839
40+ .PHONY : cli
41+ cli : go-dep mkdir
42+ @echo Build media tool
43+ @PKG_CONFIG_PATH=" $( shell realpath ${PREFIX} ) /lib/pkgconfig" CGO_LDFLAGS_ALLOW=" -(W|D).*" ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR} /media ./cmd/media
44+
45+ $(CMD_DIR ) : go-dep mkdir
46+ @echo Build cmd $(notdir $@ )
47+ @PKG_CONFIG_PATH=" $( shell realpath ${PREFIX} ) /lib/pkgconfig" CGO_LDFLAGS_ALLOW=" -(W|D).*" ${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR} /$(notdir $@ ) ./$@
48+
49+ # ##############################################################################
50+ # FFMPEG
51+
52+ # Download ffmpeg sources
53+ ${BUILD_DIR}/${FFMPEG_VERSION} :
54+ @if [ ! -d " $( BUILD_DIR) /$( FFMPEG_VERSION) " ]; then \
55+ echo " Downloading $( FFMPEG_VERSION) " ; \
56+ mkdir -p $(BUILD_DIR ) /${FFMPEG_VERSION} ; \
57+ curl -L -o $(BUILD_DIR ) /ffmpeg.tar.gz https://ffmpeg.org/releases/$(FFMPEG_VERSION ) .tar.gz; \
58+ tar -xzf $(BUILD_DIR ) /ffmpeg.tar.gz -C $(BUILD_DIR ) ; \
59+ rm -f $(BUILD_DIR ) /ffmpeg.tar.gz; \
60+ fi
61+
62+ # Configure ffmpeg
63+ .PHONY : ffmpeg
64+ ffmpeg : mkdir ${BUILD_DIR}/${FFMPEG_VERSION} ffmpeg-dep
65+ @echo " Configuring ${FFMPEG_VERSION} => ${PREFIX} "
66+ @cd ${BUILD_DIR} /${FFMPEG_VERSION} && ./configure \
67+ --enable-static --disable-doc --disable-programs \
68+ --prefix=" $( shell realpath ${PREFIX} ) " \
69+ --pkg-config-flags=" --static" \
70+ --extra-libs=" -lpthread" \
71+ --enable-gpl --enable-nonfree ${FFMPEG_CONFIG}
72+
73+ # Build ffmpeg
74+ .PHONY : ffbuild
75+ ffbuild : ffmpeg
76+ @echo " Building ${FFMPEG_VERSION} "
77+ @cd $(BUILD_DIR ) /$(FFMPEG_VERSION ) && make
78+
79+ # Install ffmpeg
80+ .PHONY : ffinstall
81+ ffinstall : ffbuild
82+ @echo " Installing ${FFMPEG_VERSION} "
83+ @cd $(BUILD_DIR ) /$(FFMPEG_VERSION ) && make install
84+
85+ # ##############################################################################
86+ # DOCKER
87+
2988docker : docker-dep
3089 @echo build docker image: ${BUILD_TAG} for ${OS} /${ARCH}
3190 @${DOCKER} build \
@@ -40,43 +99,40 @@ docker-push: docker-dep
4099 @echo push docker image: ${BUILD_TAG}
41100 @${DOCKER} push ${BUILD_TAG}
42101
102+ # ##############################################################################
103+ # TESTS
104+
43105test : go-dep
44106 @echo Test
45107 @${GO} mod tidy
46- @echo ... test sys/ffmpeg61
47- @${ GO} test ./sys/ffmpeg61
48- @echo ... test pkg/ffmpeg
49- @${GO} test -v ./pkg/ffmpeg
50- @echo ... test sys/chromaprint
51- @${GO} test ./sys/chromaprint
52- @echo ... test pkg/chromaprint
53- @${GO} test ./pkg/chromaprint
54- @echo ... test pkg/file
55- @${GO} test ./pkg/file
56- @echo ... test pkg/generator
57- @${GO} test ./pkg/generator
58- @echo ... test pkg/image
59- @${GO} test ./pkg/image
60- @echo ... test pkg
61- @${GO} test ./pkg/...
108+ @echo ... test sys/ffmpeg71
109+ @PKG_CONFIG_PATH= $( shell realpath ${PREFIX}) /lib/pkgconfig ${ GO} test ./sys/ffmpeg71
110+ # @echo ... test pkg/ffmpeg
111+ # @${GO} test -v ./pkg/ffmpeg
112+ # @echo ... test sys/chromaprint
113+ # @${GO} test ./sys/chromaprint
114+ # @echo ... test pkg/chromaprint
115+ # @${GO} test ./pkg/chromaprint
116+ # @echo ... test pkg/file
117+ # @${GO} test ./pkg/file
118+ # @echo ... test pkg/generator
119+ # @${GO} test ./pkg/generator
120+ # @echo ... test pkg/image
121+ # @${GO} test ./pkg/image
122+ # @echo ... test pkg
123+ # @${GO} test ./pkg/...
62124
63125container-test : go-dep
64126 @echo Test
65127 @${GO} mod tidy
66- @${GO} test --tags=container ./sys/ffmpeg61
128+ @${GO} test --tags=container ./sys/ffmpeg71
67129 @${GO} test --tags=container ./sys/chromaprint
68130 @${GO} test --tags=container ./pkg/...
69131 @${GO} test --tags=container .
70132
71- cli : go-dep mkdir
72- @echo Build media tool
73- @${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR} /media ./cmd/cli
74133
75- $(CMD_DIR ) : go-dep mkdir
76- @echo Build cmd $(notdir $@ )
77- @${GO} build ${BUILD_FLAGS} -o ${BUILD_DIR} /$(notdir $@ ) ./$@
78-
79- FORCE :
134+ # ##############################################################################
135+ # DEPENDENCIES, ETC
80136
81137go-dep :
82138 @test -f " ${GO} " && test -x " ${GO} " || (echo " Missing go binary" && exit 1)
@@ -87,9 +143,26 @@ docker-dep:
87143mkdir :
88144 @echo Mkdir ${BUILD_DIR}
89145 @install -d ${BUILD_DIR}
146+ @install -d ${PREFIX}
90147
91148clean :
92149 @echo Clean
93150 @rm -fr $(BUILD_DIR )
94151 @${GO} mod tidy
95152 @${GO} clean
153+
154+ # Check for FFmpeg dependencies
155+ .PHONY : ffmpeg-dep
156+ ffmpeg-dep :
157+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists libass && echo "--enable-libass") )
158+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists fdk-aac && echo "--enable-libfdk-aac") )
159+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists lame && echo "--enable-libmp3lame") )
160+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists freetype2 && echo "--enable-libfreetype") )
161+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists theora && echo "--enable-libtheora") )
162+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists vorbis && echo "--enable-libvorbis") )
163+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists vpx && echo "--enable-libvpx") )
164+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists x264 && echo "--enable-libx264") )
165+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists x265 && echo "--enable-libx265") )
166+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists opus && echo "--enable-libopus") )
167+ $(eval FFMPEG_CONFIG := $(FFMPEG_CONFIG ) $(shell pkg-config --exists xvid && echo "--enable-libxvid") )
168+ @echo " FFmpeg configuration: $( FFMPEG_CONFIG) "
0 commit comments