windows_installer.mk
changeset 120 02e37d9e96a9
parent 116 dc462ee1c0f5
equal deleted inserted replaced
119:6be785b8cc85 120:02e37d9e96a9
     1 
       
     2 VERSIONPY=sources/beremiz/version.py
       
     3 BVERSION?=$(if $(file <$(VERSIONPY)), $(shell python2 $(VERSIONPY)), $(shell date '+%x_%R' | tr '/: ' '---'))
       
     4 
       
     5 CROSS_COMPILE=i686-w64-mingw32
       
     6 CROSS_COMPILE_LIBS_DIR=$(shell dirname $(shell $(CROSS_COMPILE)-gcc -print-libgcc-file-name))
       
     7 CC=$(CROSS_COMPILE)-gcc
       
     8 CXX=$(CROSS_COMPILE)-g++
       
     9 
     1 
    10 installer:
     2 installer:
    11 	mkdir -p installer
     3 	mkdir -p installer
    12 	cp $(src)/winpaths.py installer
     4 	cp $(src)/winpaths.py installer
    13 
     5 
    14 
     6 
    15 CURDIR:=$(shell pwd)
     7 CURDIR:=$(shell pwd)
    16 PACMANPFX=$(CURDIR)/pacman
     8 PACMANPFX=$(CURDIR)/pacman
    17 msysdir=msys32
     9 MSYS_DIR=msys64
    18 MSYS_ROOT=$(CURDIR)/$(msysdir)
    10 MSYS_ENV_DIR=ucrt64
       
    11 MSYS_ENV=mingw-w64-ucrt-x86_64
       
    12 MSYS_ROOT=$(CURDIR)/$(MSYS_DIR)
    19 
    13 
    20 XVFBRUN ?= xvfb-run -a
    14 XVFBRUN ?= xvfb-run -a
    21 
    15 
    22 msysfinaldir=installer/msys2
    16 msysfinaldir=installer/$(MSYS_DIR)
    23 
    17 
    24 pacman/.stamp:
    18 pacman-6.0.0/src.stamp:
    25 	rm -rf pacman pacman-6.0.0
    19 	rm -rf pacman pacman-6.0.0
    26 	$(call get_src_http,https://sources.archlinux.org/other/pacman,pacman-6.0.0.tar.xz)\
    20 	$(call get_src_http,https://sources.archlinux.org/other/pacman,pacman-6.0.0.tar.xz)\
    27 	tar -xJf $$dld
    21 	tar -xJf $$dld
       
    22 	touch $@
       
    23 
       
    24 pacman-6.0.0/patched.stamp: pacman-6.0.0/src.stamp
    28 	cd pacman-6.0.0 ;\
    25 	cd pacman-6.0.0 ;\
    29 	patch -p1 < $(src)/pacman-6.0.0-nogpg-relative_conf.patch ;\
    26 	patch -p1 < $(src)/pacman-6.0.0-nogpg-relative_conf.patch ;
       
    27 	touch $@
       
    28 
       
    29 pacman/.stamp: pacman-6.0.0/patched.stamp
       
    30 	cd pacman-6.0.0 ;\
    30 	meson -Droot-dir=$(MSYS_ROOT) -Dsysconfdir=$(MSYS_ROOT)/etc -Dlocalstatedir=$(MSYS_ROOT)/var build ;\
    31 	meson -Droot-dir=$(MSYS_ROOT) -Dsysconfdir=$(MSYS_ROOT)/etc -Dlocalstatedir=$(MSYS_ROOT)/var build ;\
    31 	DESTDIR=$(PACMANPFX) ninja -C build install
    32 	DESTDIR=$(PACMANPFX) ninja -C build install
    32 	touch $@
    33 	touch $@
    33 
    34 
    34 define pacman_install
    35 define pacman_call
    35 LD_LIBRARY_PATH=$(PACMANPFX)/usr/lib/x86_64-linux-gnu/ fakeroot pacman/usr/bin/pacman -S $(1) --arch i686 --noconfirm --cachedir $(distfiles)
    36 LD_LIBRARY_PATH=$(PACMANPFX)/usr/lib/x86_64-linux-gnu/ fakeroot pacman/usr/bin/pacman $(1)
    36 endef
    37 endef
    37 
    38 
    38 $(msysdir)/.stamp: pacman/.stamp 
    39 pacman_update=$(call pacman_call, -Sy --noconfirm --cachedir $(distfiles));
    39 	rm -rf $(msysdir)
    40 pacman_install_ming=$(call pacman_call, -S $(1) --arch x86_64 --noconfirm --cachedir $(distfiles));
    40 	$(call get_src_http,http://repo.msys2.org/distrib/i686,msys2-base-i686-20210705.tar.xz)\
    41 pacman_install_msys=$(call pacman_call, -S $(1) --noconfirm --cachedir $(distfiles));
       
    42 
       
    43 # First part are python packages requested by our app and available in msys
       
    44 # Second part are dependencies of packages to be later installed with pip
       
    45 # Third part : neede for cross-install operation
       
    46 #    -> all those packages are installed with pacman, ignoring version given in requirements.txt
       
    47 define MSYS_PY_PACKAGES
       
    48 	brotli
       
    49 	click
       
    50 	fonttools
       
    51 	lxml
       
    52 	matplotlib
       
    53 	msgpack
       
    54 	pycountry
       
    55 	u-msgpack
       
    56 	zeroconf
       
    57 	twisted
       
    58 	
       
    59 	cryptography
       
    60 	aiosqlite
       
    61 	pytz
       
    62 	sortedcontainers
       
    63 
       
    64 	pip
       
    65 endef
       
    66 
       
    67 define MSYS_PACKAGES_NAMES
       
    68 	gcc
       
    69 	make
       
    70 	wxPython
       
    71 	$(foreach package, $(MSYS_PY_PACKAGES), python-$(package))
       
    72 endef
       
    73 
       
    74 MSYS_PACKAGES=$(foreach package, $(MSYS_PACKAGES_NAMES), $(MSYS_ENV)-$(package))
       
    75 
       
    76 $(MSYS_DIR)/.stamp: pacman/.stamp 
       
    77 	rm -rf $(MSYS_DIR)
       
    78 
       
    79 	$(call get_src_http,https://repo.msys2.org/distrib/x86_64,msys2-base-x86_64-20230718.tar.xz)\
    41 	tar -xJf $$dld
    80 	tar -xJf $$dld
    42 	$(call pacman_install, mingw-w64-i686-gcc)
    81 
    43 	$(call pacman_install, make)
    82 	# Do NOT update package lists to make build reproducible
       
    83 	# All packages version are as given in base image.
       
    84 	## $(pacman_update)	
       
    85 
       
    86 	$(call pacman_install_ming,$(MSYS_PACKAGES))
    44 	touch $@
    87 	touch $@
    45 
    88 
    46 $(msysfinaldir): $(msysdir)/.stamp | installer
    89 # filter-out all python packages already installed by pacman
       
    90 filtered_requirements.txt: $(MSYS_DIR)/.stamp sources/beremiz_src
       
    91 	grep sources/beremiz/requirements.txt -i -v \
       
    92 		`$(call pacman_call, -Qqs 'python-.*') | sed -e 's/$(MSYS_ENV)-python-/ -e /'` \
       
    93 		-e wxPython \
       
    94 		$(foreach package, $(MSYS_PY_PACKAGES), -e $(package)) > filtered_requirements.txt
       
    95 
       
    96 # download remaining pip packages separtately with local python
       
    97 # workaround msys2's git crashing when launched from pip on wine
       
    98 # bug: https://bugs.winehq.org/show_bug.cgi?id=40528
       
    99 pip_downloads/.stamp: filtered_requirements.txt
       
   100 	rm -rf pip_downloads
       
   101 	# python3 -m pip download --no-deps -r filtered_requirements.txt -d pip_downloads
       
   102 	python3 -m pip wheel --no-deps -r filtered_requirements.txt -w pip_downloads
       
   103 	touch $@
       
   104 
       
   105 # install downloaded .whl files with wine
       
   106 # TODO: find a less convoluited way instead of wine to unpack wheels
       
   107 #       but still populating __pycache__ for this particular python version
       
   108 winpythonbin = $(MSYS_ROOT)/$(MSYS_ENV_DIR)/bin/python.exe
       
   109 wine = WINEPREFIX=$(tmp) $(XVFBRUN) wine
       
   110 pip.stamp: pip_downloads/.stamp
       
   111 	cd pip_downloads; $(wine) $(winpythonbin) -m pip install --no-deps *
       
   112 	touch $@
       
   113 
       
   114 $(msysfinaldir)/.stamp: pip.stamp | installer
    47 	rm -rf $(msysfinaldir)
   115 	rm -rf $(msysfinaldir)
    48 	cp -a $(msysdir) $(msysfinaldir)
   116 	cp -a $(MSYS_DIR) $(msysfinaldir)
       
   117 	touch $@
    49 
   118 
    50 msiexec = WINEPREFIX=$(tmp) $(XVFBRUN) msiexec
   119 CROSS_COMPILE=x86_64-w64-mingw32
    51 wine = WINEPREFIX=$(tmp) $(XVFBRUN) wine
   120 CROSS_COMPILE_LIBS_DIR=$(shell dirname $(shell $(CROSS_COMPILE)-gcc -print-libgcc-file-name))
    52 pydir = installer/python
       
    53 pysite = $(pydir)/Lib/site-packages
       
    54 
       
    55 python: $(pydir)/.stamp
       
    56 $(pydir)/.stamp: | installer
       
    57 	rm -rf $(pydir)
       
    58 	mkdir -p $(pydir)
       
    59 	
       
    60 	# Python
       
    61 	$(call get_src_http,http://www.python.org/ftp/python/2.7.13,python-2.7.13.msi)\
       
    62 	$(msiexec) /qn /i $$dld TARGETDIR=.\\$(pydir)
       
    63 	
       
    64 	# # wxPython fails if VC9.0 redistribuable is not fully here.
       
    65 	# $(call get_src_http,http://download.microsoft.com/download/1/1/1/1116b75a-9ec3-481a-a3c8-1777b5381140,vcredist_x86.exe)\
       
    66 	# cp $$dld $(tmp)
       
    67 	# $(wine) $(tmp)/vcredist_x86.exe /qn /i
       
    68 	# cp -fu $(tmp)/drive_c/windows/winsxs/x86_microsoft.vc90*/* $(pydir)
       
    69 	
       
    70 	$(wine) $(pydir)/python.exe -m pip install --only-binary :all: --cache-dir $(distfiles) \
       
    71         wxPython            \
       
    72         future              \
       
    73         matplotlib          \
       
    74         pywin32             \
       
    75         twisted             \
       
    76         pyOpenSSL           \
       
    77         Nevow               \
       
    78         autobahn            \
       
    79         msgpack_python      \
       
    80         u-msgpack-python    \
       
    81         zeroconf-py2compat  \
       
    82         lxml                \
       
    83         sslpsk              \
       
    84         pycountry           \
       
    85         fonttools           \
       
    86         Brotli
       
    87 	
       
    88 	$(wine) $(pydir)/python.exe -m pip install --cache-dir $(distfiles) \
       
    89         Pyro                \
       
    90         gnosis              
       
    91 	
       
    92 	# # FIXME : this uses 'some' binaries of openssl that forces us to stick to python 2.7.13
       
    93 	# # FIXME : (from here : https://www.npcglib.org/~stathis/blog/precompiled-openssl/)
       
    94 	# # FIXME : build it, and use openssl binaries from https://github.com/python/cpython-bin-deps/tree/openssl-bin-1.0.2k
       
    95 	# WxGlade
       
    96 	$(call get_src_http,https://github.com/wxGlade/wxGlade/archive,v0.8.3.zip)\
       
    97 	unzip -d $(tmp) $$dld
       
    98 	mv $(tmp)/wxGlade-0.8.3 $(pysite)/wxglade
       
    99 	
       
   100 	touch $@
       
   101 
   121 
   102 matiecdir = installer/matiec
   122 matiecdir = installer/matiec
   103 matiec: $(matiecdir)/.stamp
   123 matiec: $(matiecdir)/.stamp
   104 $(matiecdir)/.stamp: sources/matiec_src | installer
   124 $(matiecdir)/.stamp: sources/matiec_src | installer
   105 	cp -a sources/matiec $(tmp);\
   125 	cp -a sources/matiec $(tmp);\
   106 	cd $(tmp)/matiec;\
   126 	cd $(tmp)/matiec;\
   107 	autoreconf;\
   127 	autoreconf ;\
   108 	automake --add-missing;\
   128 	automake --add-missing ;\
   109 	./configure --host=$(CROSS_COMPILE);\
   129 	LDFLAGS=-lstdc++ ./configure --host=$(CROSS_COMPILE);\
   110 	make -j$(CPUS);
   130 	$(MAKE) -j$(CPUS);
   111 	rm -rf $(matiecdir)
   131 	rm -rf $(matiecdir)
   112 	mkdir -p $(matiecdir)
   132 	mkdir -p $(matiecdir)
   113 	mv $(tmp)/matiec/*.exe $(matiecdir)
   133 	mv $(tmp)/matiec/*.exe $(matiecdir)
   114 	
   134 	
   115 	# install necessary shared libraries from local cross-compiler
   135 	# install necessary shared libraries from local cross-compiler
   116 	cp $(CROSS_COMPILE_LIBS_DIR)/libgcc_s_sjlj-1.dll $(matiecdir)
   136 	cp $(CROSS_COMPILE_LIBS_DIR)/libgcc_s_seh-1.dll $(matiecdir)
   117 	cp $(CROSS_COMPILE_LIBS_DIR)/libstdc++-6.dll $(matiecdir)
   137 	cp $(CROSS_COMPILE_LIBS_DIR)/libstdc++-6.dll $(matiecdir)
   118 	
   138 	
   119 	mv $(tmp)/matiec/lib $(matiecdir)
   139 	mv $(tmp)/matiec/lib $(matiecdir)
   120 	touch $@
   140 	touch $@
   121 
   141 
   123 
   143 
   124 beremiz: $(beremizdir)/.stamp
   144 beremiz: $(beremizdir)/.stamp
   125 $(beremizdir)/.stamp:  sources/beremiz_src | installer
   145 $(beremizdir)/.stamp:  sources/beremiz_src | installer
   126 	rm -rf $(beremizdir);\
   146 	rm -rf $(beremizdir);\
   127 	cp -a sources/beremiz $(beremizdir);\
   147 	cp -a sources/beremiz $(beremizdir);\
       
   148 	# populate __pycache__'s .pyc files
       
   149 	cd $(beremizdir) ;\
       
   150 		find . -name "*.py" | grep -v \
       
   151 			-e \./etherlab \
       
   152 			-e .*/web_settings.py \
       
   153 			-e \./tests \
       
   154 			-e \./exemples \
       
   155 			> tocompile.lst ;\
       
   156 		$(wine) $(winpythonbin) -m compileall -i tocompile.lst
       
   157 	rm $(beremizdir)/tocompile.lst
   128 	touch $@
   158 	touch $@
   129 
   159 
   130 ide_revisions = installer/revisions.txt
   160 ide_revisions = installer/revisions.txt
   131 $(ide_revisions): revisions.txt
   161 $(ide_revisions): revisions.txt
   132 	cp $< $@ 
   162 	cp $< $@ 
   133 
   163 
   134 Beremiz-build: Beremiz-$(BVERSION)_build
   164 Beremiz-windows-build: $(msysfinaldir)/.stamp pip.stamp $(matiecdir)/.stamp $(beremizdir)/.stamp ide_targets_from_dist $(ide_revisions)
   135 Beremiz-$(BVERSION)_build: $(msysfinaldir) $(pydir)/.stamp $(matiecdir)/.stamp $(beremizdir)/.stamp ide_targets_from_dist $(ide_revisions)
       
   136 	touch $@
   165 	touch $@
   137 
   166 
   138 Beremiz-archive: Beremiz-$(BVERSION).zip
   167 Beremiz-portable.zip: Beremiz-windows-build
   139 
       
   140 Beremiz-installer: Beremiz-$(BVERSION).exe
       
   141 
       
   142 Beremiz-$(BVERSION).zip: Beremiz-$(BVERSION)_build
       
   143 	rm -f $@
   168 	rm -f $@
   144 	cd installer; zip -r -q ../$@ .
   169 	cd installer; zip -r -q ../$@ .
   145 
   170 
   146 Beremiz-$(BVERSION).exe: Beremiz-$(BVERSION)_build $(src)/license.txt $(src)/install.nsi 
   171 VERSIONPY=sources/beremiz/version.py
   147 	sed -e 's/\$$BVERSION/$(BVERSION)/g' $(src)/license.txt > installer/license.txt
   172 
   148 	sed -e 's/\$$BVERSION/$(BVERSION)/g' $(src)/install.nsi |\
   173 Beremiz-nsis-installer.exe: Beremiz-windows-build $(src)/license.txt $(src)/install.nsi 
   149 	makensis -
   174 	export BVERSION=`python3 $(VERSIONPY)` ;\
       
   175 	sed -e "s/\$$BVERSION/$$BVERSION/g" $(src)/license.txt > installer/license.txt ;\
       
   176 	sed -e "s/\$$BVERSION/$$BVERSION/g" $(src)/install.nsi |\
       
   177 	sed -e "s#\$$MSYS_DIR#$(MSYS_DIR)#g" |\
       
   178 	sed -e "s#\$$MSYS_ENV_DIR#$(MSYS_ENV_DIR)#g" > install.nsi
       
   179 	makensis install.nsi
   150 
   180 
   151 
   181 
   152