Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
A donation makes a contribution towards the costs, the time and effort that's going in this site and building.
Thank You! Steffen
Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
| |
|
Topic: Howto :: Building Apache httpd Windows from GitHub sources |
|
Author |
|
guischulz
Joined: 26 Aug 2021 Posts: 2
|
Posted: Thu 26 Aug '21 17:37 Post subject: Howto :: Building Apache httpd Windows from GitHub sources |
|
|
This is an alternative to the existing guide for building Apache with CMake.
The main objectives of this approach:
- use GitHub sources for all packages
- provide a script for batch building
- keep things simple, making the batch script kind of self-explanatory
- use existing build mechanisms, leave original sources untouched
- result should be similar to the Apache Lounge distribution
- use Makefile.win (not CMake) for Apache httpd build
The following tools are required:
Visual Studio 2019 Community
CMake for Windows
Git for Windows (MinGit distribution is sufficient)
Strawberry Perl or ActiveState Perl
Netwide Assembler (NASM)
AWK for Windows (the "One True AWK" by Brian Kernighan, we can compile it from source)
Dependend packages (can all be found on GitHub):
zlib, openssl, pcre, libxml2, libexpat, brotli, jansson, curl, lua, nghttp2, apr, apr-iconv, apr-util
The full URLs to these packages can be found in the provided batch 'build_httpd.bat'
Build instructions:
a. Create a base directory for the third-party dependencies, e.g. D:\work\apache_build\3rdparty
b. Clone all the required repositories below the created base directory
c. Clone the Apache 'httpd' repository from Github into a new directory, e.g. D:\work\apache_build\httpd
d. Create directory junctions in [..]httpd\srclib\ directory
The Apache build script expects all dependent packages in the 'srclib' directory. Using directory junctions makes it possible to keep the sources at a different location and still use 'git clean -xfd', as with current Git versions NTFS junctions are not followed.
Create junctions for all cloned source directories. Only for 'lua' the junction must be created in 'httpd\srclib\src' (create 'src' directory first)
Example: mklink /j D:\work\apache_build\httpd\srclib\curl D:\work\apache_build\3rdparty\curl
e. If you do not have AWK, clone the "One True AWK" project from danfuzz on GitHub
f. Get the batch from https://gist.github.com/guischulz/9599a7116435517a3073c32520a867f2 or use the code block at the end of this post
g. Edit the batch build script to match your environment and your requirements (tools, directories, versions, options, ...)
Note: you may notice unusual modifications to some ".lib" names in the batch file, like copying a library to an other dir with changed name or use of 'lua51.lib' instead of 'lua53.lib'. This is required to use the unmodified "Makefile.win" and to fulfil some naming assumptions of the build mechanism to find libraries.
h. Run and wait, the script will install the result to c:\Apache24
build_httpd.bat
Code: |
@setlocal
REM start with a clean path
set PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem
REM --- MSVC C++ build tools ---
rem Win64Build
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"
rem Win32Build
rem call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars32.bat"
@echo on
REM --- Build helper utilities ---
set _git_home_=D:\work\git-2.33.0.2
set _cmake_home_=D:\work\cmake-3.21.1-windows-x86_64
set _nasm_home_=D:\work\nasm-2.15.05
set _perl_home_=C:\Strawberry\perl
rem AWK for Windows from https://github.com/danfuzz/one-true-awk/
set _awk_home_=D:\work\one-true-awk\versions\2010-05-23
set "PATH=%_git_home_%\cmd;%_cmake_home_%\bin;%_nasm_home_%;%_perl_home_%\bin;%_awk_home_%;%PATH%"
:awk
cd /d "%_awk_home_%"
if not exist "%_awk_home_%\awk.exe" call "%_awk_home_%\buildwin.bat"
REM --- Third party git source directories ---
REM !!ATTENTION!! create corresponding directory junctions in "%HTTPD_DIR%\srclib\" with mklink /j
set THIRDPARTY_BASE=D:\work\apache_build\3rdparty
set ZLIB_DIR=%THIRDPARTY_BASE%\zlib
set OPENSSL_DIR=%THIRDPARTY_BASE%\openssl
set PCRE_DIR=%THIRDPARTY_BASE%\pcre
set LIBXML2_DIR=%THIRDPARTY_BASE%\libxml2
set LIBEXPAT_DIR=%THIRDPARTY_BASE%\libexpat
set BROTLI_DIR=%THIRDPARTY_BASE%\brotli
set JANSSON_DIR=%THIRDPARTY_BASE%\jansson
set CURL_DIR=%THIRDPARTY_BASE%\curl
set LUA_DIR=%THIRDPARTY_BASE%\lua
set NGHTTP2_DIR=%THIRDPARTY_BASE%\nghttp2
set APR_DIR=%THIRDPARTY_BASE%\apr
set APR_ICONV_DIR=%THIRDPARTY_BASE%\apr-iconv
set APR_UTIL_DIR=%THIRDPARTY_BASE%\apr-util
REM --- Apache httpd source directory ---
set HTTPD_DIR=D:\work\apache_build\httpd
set INSTALL_DIR=c:\Apache24
:zlib
REM === Zlib ===
rem https://github.com/madler/zlib.git
cd /d "%ZLIB_DIR%"
git clean -xfd
git checkout tags/v1.2.11
rem Win64Build
nmake -f win32/Makefile.msc AS=ml64 LOC="-DASMV -DASMINF -I." OBJA="inffasx64.obj gvmat64.obj inffas8664.obj"
rem Win32Build
rem nmake -f win32/Makefile.msc LOC="-DASMV -DASMINF" OBJA="inffas32.obj match686.obj"
copy zlib.lib zlib1.lib
:openssl
REM === OpenSSL ===
rem https://github.com/openssl/openssl.git
cd /d "%OPENSSL_DIR%"
git clean -xfd
git checkout tags/OpenSSL_1_1_1l
rem Win64Build
perl Configure no-comp VC-WIN64A
rem Win32Build
rem perl Configure no-comp VC-WIN32
nmake -f makefile
:pcre
REM === PCRE ===
rem https://github.com/jwilk-mirrors/pcre.git
cd /d "%PCRE_DIR%"
git clean -xfd
git checkout tags/pcre-8.45
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=True -DPCRE_SUPPORT_JIT=ON -DPCRE_SUPPORT_UTF=ON -DPCRE_REBUILD_CHARTABLES=ON -DZLIB_LIBRARY=%ZLIB_DIR%\zlib1.lib -DZLIB_INCLUDE_DIR=%ZLIB_DIR%
nmake
:libxml2
REM === LibXML2===
rem https://github.com/GNOME/libxml2.git
cd /d "%LIBXML2_DIR%"
git clean -xfd
git checkout tags/v2.9.12
cd "%LIBXML2_DIR%\win32"
cscript configure.js zlib=no iconv=no compiler=msvc debug=no
nmake -f Makefile.msvc
:expat
REM === Expat ===
rem https://github.com/libexpat/libexpat.git
cd /d "%LIBEXPAT_DIR%"
git clean -xfd
git checkout tags/R_2_4_1
cd "%LIBEXPAT_DIR%\expat"
cmake -G "NMake Makefiles" -DBUILD_tools=Off -DBUILD_examples=Off -DBUILD_tests=Off -DBUILD_shared=Off -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_SHARED_LIBS=False
nmake
:brotli
rem === Brotli ===
rem https://github.com/google/brotli.git
cd /d "%BROTLI_DIR%"
git clean -xfd
git checkout tags/1.0.9
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DBROTLI_BUNDLED_MODE=ON
nmake
copy /y brotlicommon-static.lib brotlicommon.lib
copy /y brotlienc-static.lib brotlienc.lib
:jansson
REM === Jansson ===
rem https://github.com/akheron/jansson.git
cd /d "%JANSSON_DIR%"
git clean -xfd
git checkout tags/v2.13.1
cmake -G "NMake Makefiles" -DJANSSON_BUILD_DOCS=OFF -DJANSSON_EXAMPLES=OFF -DJANSSON_BUILD_SHARED_LIBS=ON -DCMAKE_BUILD_TYPE=Release
nmake
:curl
REM === cURL ===
rem https://github.com/curl/curl.git
cd /d "%CURL_DIR%"
git clean -xfd
git checkout tags/curl-7_78_0
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DZLIB_LIBRARY=%ZLIB_DIR%\zlib1.lib -DZLIB_INCLUDE_DIR=%ZLIB_DIR% -DCMAKE_USE_SCHANNEL=ON -DBUILD_SHARED_LIBS=ON -DBUILD_CURL_EXE=OFF
nmake
copy "%CURL_DIR%\lib\libcurl_imp.lib" "%CURL_DIR%\lib\libcurl.lib"
:lua
REM === Lua ===
rem https://github.com/lua/lua.git
rem the lua git source directory must be linked to "%HTTPD_DIR%\srclib\src\lua", not just "lua"
cd /d "%LUA_DIR%"
git clean -xfd
git checkout tags/v5.3.6
cl /MD /O2 /c /DLUA_BUILD_AS_DLL /DLUA_COMPAT_5_2 /DLUA_COMPAT_5_1 *.c
link /MANIFEST /DLL /IMPLIB:lua51.lib /OUT:lua53.dll *.obj
mt -manifest lua53.dll.manifest -outputresource:lua53.dll;2
:nghttp2
REM === nghttp2 ===
rem https://github.com/nghttp2/nghttp2.git
cd /d "%NGHTTP2_DIR%"
git clean -xfd
git checkout tags/v1.44.0
cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DZLIB_LIBRARY=%ZLIB_DIR%\zlib1.lib -DZLIB_INCLUDE_DIR=%ZLIB_DIR% -DOPENSSL_ROOT_DIR=%OPENSSL_DIR% -DLIBXML2_LIBRARY=%LIBXML2_DIR%\win32\bin\libxml2.lib -DLIBXML2_INCLUDE_DIR=%LIBXML2_DIR% -DJANSSON_LIBRARY=%JANSSON_DIR%\lib\jansson.lib -DJANSSON_INCLUDE_DIR=%JANSSON_DIR%\include -DENABLE_LIB_ONLY=ON
nmake
md "%NGHTTP2_DIR%\lib\MSVC_obj"
copy "%NGHTTP2_DIR%\lib\nghttp2.lib" "%NGHTTP2_DIR%\lib\MSVC_obj"
copy "%NGHTTP2_DIR%\lib\nghttp2.dll" "%NGHTTP2_DIR%\lib\MSVC_obj"
echo.>"%NGHTTP2_DIR%\lib\MSVC_obj\nghttp2.pdb"
:apr
REM === Apr ===
rem https://github.com/apache/apr.git
rem https://github.com/apache/apr-iconv.git
rem https://github.com/apache/apr-util.git
cd /d "%APR_DIR%"
git clean -xfd
git checkout tags/1.7.0
cd /d "%APR_ICONV_DIR%"
git clean -xfd
git checkout tags/1.2.2
cd /d "%APR_UTIL_DIR%"
git clean -xfd
git checkout tags/1.6.1
git checkout -- .
rem use external libexpat as xml parser
set expat_dir=%APR_UTIL_DIR%\xml\expat
xcopy /e/s/v/i/y "%LIBEXPAT_DIR%\expat" "%expat_dir%"
echo.> "%expat_dir%\lib\xml.mak"
md "%expat_dir%\lib\LibR"
copy "%expat_dir%\libexpatMD.lib" "%expat_dir%\lib\LibR\xml.lib"
echo.>"%expat_dir%\lib\LibR\xml.pdb"
rem compile with crypto and openssl enabled
copy "%APR_UTIL_DIR%\include\apu.hw" "%APR_UTIL_DIR%\include\apu.hw.tmp"
awk "$2 ~ /^APU_HAVE_(CRYPTO)|(OPENSSL)$/ {$3=\"1\"}; 1" "%APR_UTIL_DIR%\include\apu.hw.tmp" > "%APR_UTIL_DIR%\include\apu.hw"
:httpd
REM === Apache HTTP Server ===
rem https://github.com/apache/httpd.git
cd /d %HTTPD_DIR%
git clean -xfd
git checkout tags/2.4.48
rem Win64Build
set CL=/D_WIN32_WINNT#0x0600 /D "WIN64" /D "_WIN64"
set _LINK_=/MANIFEST /MACHINE:x64
rem Win32Build
rem set CL=/D_WIN32_WINNT#0x0600
rem set _LINK_=/MANIFEST /MACHINE:x86
nmake -f Makefile.win XML_PARSER="%LIBEXPAT_DIR%\expat\libexpatMD" XML_OPTIONS="/D XML_STATIC" _buildr
:post_httpd
REM --- mod_session_crypto ---
rem not build with the httpd default Makefile.win
cd /d "%APR_UTIL_DIR%\crypto"
nmake -f apr_crypto_openssl.mak _HAVE_OSSL110=1 CFG="apr_crypto_openssl - Win32 Release" RECURSE=0
cd /d "%HTTPD_DIR%\modules\session"
nmake -f "mod_session_crypto.mak" CFG="mod_session_crypto - Win32 Release" RECURSE=0
:install
cd /d %HTTPD_DIR%
nmake -f Makefile.win INSTDIR="%INSTALL_DIR%" installr
del /s "%INSTALL_DIR%\*.pdb"
rem copy additional files
copy /y "%CURL_DIR%\lib\libcurl.dll" "%INSTALL_DIR%\bin"
copy /y "%JANSSON_DIR%\bin\jansson.dll" "%INSTALL_DIR%\bin"
copy /y "%LUA_DIR%\lua53.dll" "%INSTALL_DIR%\bin"
copy /y "%ZLIB_DIR%\zlib.lib" "%INSTALL_DIR%\lib"
copy /y "%ZLIB_DIR%\zconf.h" "%INSTALL_DIR%\include"
copy /y "%ZLIB_DIR%\zlib.h" "%INSTALL_DIR%\include"
copy /y "%HTTPD_DIR%\modules\proxy\Release\mod_proxy.lib" "%INSTALL_DIR%\lib"
copy /y "%APR_UTIL_DIR%\crypto\Release\apr_crypto_openssl-1.dll" "%INSTALL_DIR%\bin"
copy /y "%HTTPD_DIR%\modules\session\Release\mod_session_crypto.so" "%INSTALL_DIR%\modules"
|
Last edited by guischulz on Fri 27 Aug '21 12:12; edited 1 time in total |
|
Back to top |
|
Steffen Moderator
Joined: 15 Oct 2005 Posts: 3093 Location: Hilversum, NL, EU
|
Posted: Fri 27 Aug '21 10:00 Post subject: |
|
|
Thanks for contributing.
Hope that Gregg continues to maintain the .mak etc files.
Win32 ? |
|
Back to top |
|
guischulz
Joined: 26 Aug 2021 Posts: 2
|
Posted: Fri 27 Aug '21 12:22 Post subject: |
|
|
I have updated the batch script and added the required changes for a Win32 build as REM comments.
- initialize MSVC build tools with x86 32-bit target architecture (vcvars32.bat)
- zlib: modified nmake command (use x86 ASM code)
- openssl: run configure with VC-WIN32
- httpd: modified compiler and linker options |
|
Back to top |
|
admin Site Admin
Joined: 15 Oct 2005 Posts: 688
|
Posted: Fri 27 Aug '21 20:03 Post subject: |
|
|
Thanks.
Moved to the forum : How-to's & Documentation & Tips |
|
Back to top |
|
nono303
Joined: 20 Dec 2016 Posts: 203 Location: Lille, FR, EU
|
Posted: Fri 24 Sep '21 13:51 Post subject: |
|
|
Hi @guischulz,
Thx for your batch
Fyi, I've Just updated mine (with same main objectives as yours) https://github.com/nono303/win-build-scripts/tree/1.3.0 for openssl3 & vs17.
Don't hesitate to make PR or tickets if you see some improvements! |
|
Back to top |
|
ranemstsage
Joined: 04 Sep 2024 Posts: 3 Location: Lennon, MI, United States
|
Posted: Wed 04 Sep '24 18:56 Post subject: |
|
|
I love this, though I would love to understand how to compile AWK for windows. been having a heck of a time. so far I ended merging this guide with the other excluding awk. so i can get a build but would be interested to get full compatibility for windows. |
|
Back to top |
|
|
|
|
|
|