Skip to content

Instantly share code, notes, and snippets.

@myfreeer
Last active November 25, 2022 14:41
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save myfreeer/a4abbd91c1d23d5626ca8b9ba7aa393e to your computer and use it in GitHub Desktop.
Save myfreeer/a4abbd91c1d23d5626ca8b9ba7aa393e to your computer and use it in GitHub Desktop.
7-zip build script
@echo off
setlocal EnableExtensions EnableDelayedExpansion
pushd "%~dp0"
:Download_7zip
set version=7z1803
appveyor DownloadFile https://www.7-zip.org/a/%version%-src.7z
7z x %version%-src.7z
:Patch
C:\msys64\usr\bin\bash -lc "cd \"$APPVEYOR_BUILD_FOLDER\" && exec ./7-zip-patch.sh"
:Init_VC_LTL
git clone https://github.com/Chuyu-Team/VC-LTL.git --depth=1
set "VC_LTL_PATH=%CD%\VC-LTL"
set "CL_VER=14.0.24210"
set "SDK_VER=10.0.10240.0"
:Env_x64
call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" amd64
set BITS=x64
set "PATH=%VC_LTL_PATH%;%VC_LTL_PATH%\VC\%CL_VER%\include;%VC_LTL_PATH%\%BITS%;%VC_LTL_PATH%\VC\%CL_VER%\lib\%BITS%;%PATH%"
set "INCLUDE=%VC_LTL_PATH%\VC\%CL_VER%\include;%INCLUDE%"
set "LIB=%VC_LTL_PATH%\%BITS%;%VC_LTL_PATH%\VC\%CL_VER%\lib\%BITS%;%VC_LTL_PATH%\ucrt\%SDK_VER%\lib\%BITS%;%LIB%"
:Build_x64
cd CPP\7zip
nmake NEW_COMPILER=1 CPU=AMD64
cd ..\..\C\Util\7z
nmake NEW_COMPILER=1 CPU=AMD64
cd ..\7zipInstall
nmake NEW_COMPILER=1 CPU=AMD64
cd ..\7zipUninstall
nmake NEW_COMPILER=1 CPU=AMD64
cd ..\SfxSetup
nmake NEW_COMPILER=1 CPU=AMD64
nmake /F makefile_con NEW_COMPILER=1 CPU=AMD64
:Env_x86
call "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools\vsvars32.bat"
set BITS=x86
set "PATH=%VC_LTL_PATH%;%VC_LTL_PATH%\VC\%CL_VER%\include;%VC_LTL_PATH%\%BITS%;%VC_LTL_PATH%\VC\%CL_VER%\lib\%BITS%;%PATH%"
set "INCLUDE=%VC_LTL_PATH%\VC\%CL_VER%\include;%INCLUDE%"
set "LIB=%VC_LTL_PATH%\%BITS%;%VC_LTL_PATH%\VC\%CL_VER%\lib\%BITS%;%VC_LTL_PATH%\ucrt\%SDK_VER%\lib\%BITS%;%LIB%"
:Build_x86
nmake NEW_COMPILER=1
nmake /F makefile_con NEW_COMPILER=1
cd ..\7z
nmake NEW_COMPILER=1
cd ..\7zipInstall
nmake NEW_COMPILER=1
cd ..\7zipUninstall
nmake NEW_COMPILER=1
cd ..\..
7z a -mx9 -r ..\%version%.7z *.dll *.exe *.efi *.sfx
cd ..\CPP\7zip
nmake NEW_COMPILER=1
:Package
REM 7-zip extra
mkdir 7-zip-extra-x86
mkdir 7-zip-extra-x64
for /f "tokens=* eol=; delims=" %%i in (..\..\pack-7-zip-extra-x86.txt) do if exist "%%~i" move /Y "%%~i" 7-zip-extra-x86\
for /f "tokens=* eol=; delims=" %%i in (..\..\pack-7-zip-extra-x64.txt) do if exist "%%~i" move /Y "%%~i" 7-zip-extra-x64\
REM 7-zip
mkdir 7-zip-x86
mkdir 7-zip-x86\Lang
mkdir 7-zip-x64
mkdir 7-zip-x64\Lang
for /f "tokens=* eol=; delims=" %%i in (..\..\pack-7-zip-x86.txt) do if exist "%%~i" move /Y "%%~i" 7-zip-x86\
for /f "tokens=* eol=; delims=" %%i in (..\..\pack-7-zip-x64.txt) do if exist "%%~i" move /Y "%%~i" 7-zip-x64\
if exist 7-zip-x86\7-zip.dll copy 7-zip-x86\7-zip.dll 7-zip-x64\7-zip32.dll
mkdir installer
cd installer
appveyor DownloadFile https://www.7-zip.org/a/%version%-x64.exe
7z x %version%-x64.exe
xcopy /S /G /H /R /Y /Q .\Lang ..\7-zip-x86\Lang
xcopy /S /G /H /R /Y /Q .\Lang ..\7-zip-x64\Lang
for /f "tokens=* eol=; delims=" %%i in (..\..\..\pack-7-zip-common.txt) do if exist "%%~i" copy /Y "%%~i" ..\7-zip-x86\
for /f "tokens=* eol=; delims=" %%i in (..\..\..\pack-7-zip-common.txt) do if exist "%%~i" copy /Y "%%~i" ..\7-zip-x64\
cd ..
del /f /s /q installer\* >nul
rd /s /q installer
move /Y .\7-zip-x64\7zipUninstall.exe .\7-zip-x64\Uninstall.exe
move /Y .\7-zip-x86\7zipUninstall.exe .\7-zip-x86\Uninstall.exe
7z a -mx9 -r ..\..\%version%.7z *.dll *.exe *.efi *.sfx 7-zip-x86\* 7-zip-x64\* 7-zip-extra-x86\* 7-zip-extra-x64\*
7z a -m0=lzma -mx9 ..\..\%version%-x64.7z .\7-zip-x64\*
7z a -m0=lzma -mx9 ..\..\%version%-x86.7z .\7-zip-x86\*
cd ..\..
copy /b .\C\Util\7zipInstall\AMD64\7zipInstall.exe /b + %version%-x64.7z /b %version%-x64.exe
copy /b .\C\Util\7zipInstall\O\7zipInstall.exe /b + %version%-x86.7z /b %version%-x86.exe
:Upload
appveyor PushArtifact %version%-x64.exe
appveyor PushArtifact %version%-x86.exe
appveyor PushArtifact %version%.7z
#!/bin/bash
# remove -OPT:NOWIN98 flag in Build.mak
# http://www.ski-epic.com/2012_compiling_7zip_on_windows_with_visual_studio_10/index.html
sed -i '/LFLAGS = $(LFLAGS) -OPT:NOWIN98/ c\LFLAGS = $(LFLAGS)\' CPP/Build.mak
# patch NsisIn.h to enable NSIS script decompiling
# https://sourceforge.net/p/sevenzip/discussion/45797/thread/5d10a376/
# insert #define NSIS_SCRIPT before the 19th line using sed
sed -i '19 i #define NSIS_SCRIPT' CPP/7zip/Archive/Nsis/NsisIn.h
# drop -WX option in Build.mak
# workaround error C2220: warning treated as error
# since warning C4456: declaration of '&1' hides previous local declaration
# introduced by NSIS_SCRIPT
sed -i 's/ -WX//g' CPP/Build.mak
# MSIL .netmodule or module compiled with /GL found; restarting link with /LTCG;
# add /LTCG to the link command line to improve linker performance
sed -i '1 a LFLAGS = $(LFLAGS) /LTCG' CPP/Build.mak
# VC-LTL
# https://github.com/Chuyu-Team/VC-LTL
# reduces binary size
sed -i '2 a LIBS = msvcrt_light.obj ltl.lib vc.lib ucrt.lib $(LIBS)' CPP/Build.mak
sed -i '3 a CFLAGS = $(CFLAGS) /D_NO_CRT_STDIO_INLINE=1 /D_Build_By_LTL=1 /D_DISABLE_DEPRECATE_STATIC_CPPLIB=1 /D_STATIC_CPPLIB=1' CPP/Build.mak
version: 18.03-{build}
build_script:
- cmd: >-
7-zip-build.bat
test: off
7-zip.chm
descript.ion
History.txt
License.txt
readme.txt
UI\Far\AMD64\7-ZipFar.dll
Bundles\Format7z\AMD64\7za.dll
Bundles\Format7zExtract\AMD64\7zxa.dll
Bundles\Alone\AMD64\7za.exe
UI\Far\O\7-ZipFar.dll
Bundles\Format7z\O\7za.dll
Bundles\Format7zExtract\O\7zxa.dll
Bundles\Alone\O\7za.exe
UI\Console\AMD64\7z.exe
UI\Explorer\AMD64\7-zip.dll
UI\FileManager\AMD64\7zFM.exe
UI\GUI\AMD64\7zG.exe
Bundles\Format7zF\AMD64\7z.dll
Bundles\SFXCon\AMD64\7zCon.sfx
Bundles\SFXWin\AMD64\7z.sfx
..\..\C\Util\7zipUninstall\AMD64\7zipUninstall.exe
UI\Console\O\7z.exe
UI\Explorer\O\7-zip.dll
UI\FileManager\O\7zFM.exe
UI\GUI\O\7zG.exe
Bundles\Format7zF\O\7z.dll
Bundles\SFXCon\O\7zCon.sfx
Bundles\SFXWin\O\7z.sfx
..\..\C\Util\7zipUninstall\O\7zipUninstall.exe
@myfreeer
Copy link
Author

myfreeer commented Mar 2, 2018

Deprecated

Moved to https://github.com/myfreeer/7z-build-nsis

README

Build status

7-zip build script with nsis script decompiling

License

LGPL-2.1

Artifacts

Binary for x86 and x64 of 7-zip

Credits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment