Makefile 3.3 KB
Newer Older
1 2 3 4 5 6 7
# Cross-compile opusfile under mingw

TOOL_PREFIX ?= i686-w64-mingw32

# To build opusfile under mingw, we first need to build:
DEPS = ogg opus ssl

8 9
ogg_URL := https://downloads.xiph.org/releases/ogg/libogg-1.3.4.tar.xz
ogg_SHA := c163bc12bc300c401b6aa35907ac682671ea376f13ae0969a220f7ddf71893fe
10

11 12
opus_URL := https://archive.mozilla.org/pub/opus/opus-1.3.1.tar.gz
opus_SHA := 65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d
13

14 15
ssl_URL := https://openssl.org/source/openssl-1.1.1g.tar.gz
ssl_SHA := ddb04774f1e32f0c49751e21b67216ac87852ceb056b75209af2443400636d46
16

17 18
all: $(DEPS)

19 20 21
libopusfile-0.dll: ../unix/Makefile $(DEPS)
	CC=$(TOOL_PREFIX)-gcc \
	RANLIB=$(TOOL_PREFIX)-ranlib \
22
	PKG_CONFIG_PATH=$(CURDIR)/lib/pkgconfig \
23 24 25
	$(MAKE) -f $<

opusfile: $(DEPS)
26 27
	../configure --host=$(TOOL_PREFIX) --prefix=$(CURDIR) \
	  PKG_CONFIG_PATH=$(CURDIR)/lib/pkgconfig
28 29 30 31
	$(MAKE)

clean:
	$(RM) -r objs
Ralph Giles's avatar
Ralph Giles committed
32 33 34 35
	$(RM) -r  bin include lib share ssl
	$(RM) -r $(DEP_DIRS)
	$(RM) opusfile_example.exe seeking_example.exe
	$(RM) libopusfile.a libopusurl.a
36 37 38

# Generate rules to download and verify each dependency.
define WGET_template =
39 40
 # Generate tarball name from the url.
 DEP_TARBALLS += $$(notdir $$($(1)_URL))
41
 $(1)_DIR := $$(basename $$(basename $$(notdir $$($(1)_URL))))
Ralph Giles's avatar
Ralph Giles committed
42
 DEP_DIRS += $$($(1)_DIR)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63

 # Verify and unpack tarball.
 $$($(1)_DIR): $$(notdir $$($(1)_URL))
	@if test "$$($(1)_SHA)" = "$$$$(sha256sum $$< | cut -f 1 -d ' ')"; \
	then \
	  echo "+ $$< checksum verified."; \
	else \
	  echo "! $$< checksum didn't match!"; \
	  $(RM) $$<; exit 1; \
	fi
	tar xf $$<

 # Fetch tarball from the url.
 $$(notdir $$($(1)_URL)):
	wget $$($(1)_URL)

 # Hook project-specific build rule.
 $(1): $(1)_BUILD
endef
$(foreach dep,$(DEPS),$(eval $(call WGET_template,$(dep))))

64 65 66 67 68
fetch: $(DEP_TARBALLS)

realclean: clean
	$(RM) $(DEP_TARBALLS)

69 70 71 72
# Build scripts for each specific target.

# NOTE: 'make check' generally requires wine with cross-compiling.
ogg_BUILD: $(ogg_DIR)
73
	cd $< && ./configure --host=$(TOOL_PREFIX) --prefix=$(CURDIR)
74 75 76
	$(MAKE) -C $< install

opus_BUILD: $(opus_DIR)
77
	cd $< && ./configure --host=$(TOOL_PREFIX) --prefix=$(CURDIR)
78 79 80 81
	$(MAKE) -C $< install

ssl_BUILD: $(ssl_DIR)
	cd $< && ./Configure shared mingw64 no-asm \
82
	  --prefix=$(CURDIR) \
83 84 85 86 87 88
	  --cross-compile-prefix=$(TOOL_PREFIX)-
	$(MAKE) -C $< depend
	$(MAKE) -C $<
	$(MAKE) -C $< install

# CROSS_COMPILE="i686-w64-mingw32-" ./Configure mingw no-asm no-shared --prefix=$PWD/mingw && make depend && make -j8 && make install
Ralph Giles's avatar
Ralph Giles committed
89 90

# Package the binaries.
91
DIST_VERSION := $(shell git describe --dirty)
92
DIST := opusfile-$(DIST_VERSION)-win32
Ralph Giles's avatar
Ralph Giles committed
93 94 95 96 97 98 99 100 101
package: $(DIST).zip

$(DIST).zip: $(DIST)
	zip -r $@ $</*
	@echo $@ ready to go.

$(DIST): $(addprefix $(CURDIR)/bin/, libogg-0.dll libopus-0.dll ssleay32.dll) 
	cd .. && make install
	mkdir -p $(DIST)
Ralph Giles's avatar
Ralph Giles committed
102
	cp ../AUTHORS ../COPYING ../README.md ../include/opusfile.h $@
Ralph Giles's avatar
Ralph Giles committed
103 104 105 106 107 108 109 110
	cp ../.libs/libopusfile-0.dll $@
	cp ../.libs/libopusfile.a $@
	cp ../.libs/libopusfile.dll.a $@
	cp ../.libs/libopusurl-0.dll $@
	cp ../.libs/libopusurl.a $@
	cp ../.libs/libopusurl.dll.a $@
	cp bin/*.dll $@
	cp ../examples/.libs/*.exe $@
111
	cp /usr/i686-w64-mingw32/sys-root/mingw/bin/libgcc_s_dw2-1.dll $@
Ralph Giles's avatar
Ralph Giles committed
112 113 114 115 116
	cp /usr/i686-w64-mingw32/sys-root/mingw/bin/libwinpthread-1.dll $@
	i686-w64-mingw32-strip $@/*.exe
	i686-w64-mingw32-strip $@/*.dll
	i686-w64-mingw32-strip $@/*.a
	cd $@ && sha256sum * > SHA256SUMS.txt