Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Windows batch script to bootstrap development environment

  • Loading branch information...
commit b6b091cdd74a0ec416f712c3b594b39286726972 1 parent ea5e239
Peter Odding authored
2  NOTES.md
View
@@ -65,4 +65,4 @@ I wasted a few hours getting `libapreq2` version 2.13 to build on Windows becaus
Eventually I decided to just rewrite the damned makefile and be done with it, enabling me to finally test the HTTP request parsing module on Windows (all tests passed the first time). I've included the [customized makefile] [apreq_makefile] in the Lua/APR git repository.
-[apreq_makefile]: https://github.com/xolox/lua-apr/blob/master/etc/libapreq2.mak
+[apreq_makefile]: https://github.com/xolox/lua-apr/blob/master/etc/win32-bootstrap/libapreq2.mak
3  README.md
View
@@ -108,10 +108,13 @@ At the top of the makefile several file locations are defined, you'll need to ch
Please note that the Windows makefile only builds the Lua/APR binding, you need to build the APR, APR-util and APREQ libraries yourself. There are instructions available on [how to build APR/APR-util on apache.org][apr_build] but [my notes on the process][notes] may be a more useful starting point.
+I've also recently created a Windows batch script that bootstraps a Lua/APR development environment by downloading, unpacking, patching and building the libraries involved. To use it, download the [ZIP archive][bootstrap_zip], unpack it to a directory, open a Windows SDK command prompt in the directory where you unpacked the ZIP archive and execute `make.cmd`. I've only tested it on a 32 bit Windows XP virtual machine, butif it doesn't work out of the box it may provide a useful starting point.
+
[msvc]: http://www.microsoft.com/express/Downloads/#2010-Visual-CPP
[autozip]: http://github.com/xolox/lua-apr/zipball/master
[apr_build]: http://apr.apache.org/compiling_win32.html
[notes]: https://github.com/xolox/lua-apr/blob/master/NOTES.md#readme
+[bootstrap_zip]: http://peterodding.com/code/lua/apr/downloads/win32-bootstrap.zip
## Status
6 etc/win32-bootstrap/clean.cmd
View
@@ -0,0 +1,6 @@
+RMDIR /S /Q apr
+RMDIR /S /Q apr-util
+RMDIR /S /Q apr-iconv
+RMDIR /S /Q libapreq2
+RMDIR /S /Q sqlite3
+RMDIR /S /Q binaries
22 etc/libapreq2.mak → etc/win32-bootstrap/libapreq2.mak
View
@@ -1,9 +1,9 @@
# Microsoft Developer Studio Generated NMAKE File, Based on libapreq.dsp
# Compile with NMAKE /f libapreq2.mak "CFG=libapreq2 - Win32 Debug"
-APR_LIB=c:\lua-apr\apr\Release\libapr-1.lib
-APU_LIB=c:\lua-apr\apr-util\Release\libaprutil-1.lib
-APREQ_HOME=c:\lua-apr\libapreq2
+APR_LIB=$(ROOT)\apr\Debug\libapr-1.lib
+APU_LIB=$(ROOT)\apr-util\Debug\libaprutil-1.lib
+APREQ_HOME=$(ROOT)\libapreq2
!IF "$(CFG)" == ""
CFG=libapreq2 - Win32 Release
@@ -31,8 +31,8 @@ NULL=
NULL=nul
!ENDIF
-CPP=cl.exe /IC:\lua-apr\apr\include /IC:\lua-apr\apr-util\include
-RSC=rc.exe /IC:\lua-apr\apr\include /IC:\lua-apr\apr-util\include
+CPP=cl.exe /I$(ROOT)\apr\include /I$(ROOT)\apr-util\include
+RSC=rc.exe /I$(ROOT)\apr\include /I$(ROOT)\apr-util\include
CFG_HOME=$(APREQ_HOME)\win32
OUTDIR=$(CFG_HOME)\libs
@@ -53,9 +53,9 @@ LINK32_OBJS= \
!IF "$(CFG)" == "libapreq2 - Win32 Release"
-ALL : "$(OUTDIR)\libapreq2.dll"
+ALL: "$(OUTDIR)\libapreq2.dll"
-"$(OUTDIR)" :
+"$(OUTDIR)":
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP_PROJ=/nologo /MD /W3 /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APREQ_DECLARE_EXPORT" /I"$(APREQ_HOME)\include" /FD /c
@@ -67,15 +67,15 @@ LINK32=link.exe
MANIFEST=$(OUTDIR)\libapreq2.dll.manifest
LINK32_FLAGS="$(APR_LIB)" "$(APU_LIB)" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:no /machine:I386 /out:"$(OUTDIR)\libapreq2.dll" /implib:"$(OUTDIR)\libapreq2.lib"
-"$(OUTDIR)\libapreq2.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+"$(OUTDIR)\libapreq2.dll": "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) $(LINK32_FLAGS) $(DEF_FLAGS) $(LINK32_OBJS)
if exist $(MANIFEST) mt /nologo /manifest $(MANIFEST) /outputresource:$(OUTDIR)\libapreq2.dll;2
!ELSEIF "$(CFG)" == "libapreq2 - Win32 Debug"
-ALL : "$(OUTDIR)\libapreq2.dll"
+ALL: "$(OUTDIR)\libapreq2.dll"
-"$(OUTDIR)" :
+"$(OUTDIR)":
if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
CPP_PROJ=/nologo /MDd /W3 /Gm /EHsc /Zi /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "APREQ_DECLARE_EXPORT" /I"$(APREQ_HOME)\include" /FD /RTC1 /c
@@ -87,7 +87,7 @@ LINK32=link.exe
MANIFEST=$(OUTDIR)\libapreq2.dll.manifest
LINK32_FLAGS="$(APR_LIB)" "$(APU_LIB)" kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /incremental:yes /pdb:"$(OUTDIR)\libapreq2.pdb" /debug /machine:I386 /out:"$(OUTDIR)\libapreq2.dll" /implib:"$(OUTDIR)\libapreq2.lib" /pdbtype:sept
-"$(OUTDIR)\libapreq2.dll" : "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
+"$(OUTDIR)\libapreq2.dll": "$(OUTDIR)" $(DEF_FILE) $(LINK32_OBJS)
$(LINK32) $(LINK32_FLAGS) $(DEF_FLAGS) $(LINK32_OBJS)
if exist $(MANIFEST) mt /nologo /manifest $(MANIFEST) /outputresource:$(OUTDIR)\libapreq2.dll;2
160 etc/win32-bootstrap/make.cmd
View
@@ -0,0 +1,160 @@
+:: Batch script to bootstrap a development environment for the Lua/APR binding.
+::
+:: Author: Peter Odding <peter@peterodding.com>
+:: Last Change: August 24, 2011
+:: Homepage: http://peterodding.com/code/lua/apr/
+:: License: MIT
+::
+:: This is a Windows batch script that bootstraps a development environment for
+:: the Lua/APR binding. Run this script from a Windows SDK command prompt.
+:: Apart from the Windows SDK this script depends on the programs "wget.exe",
+:: "unzip.exe", "gunzip.exe", "tar.exe" and "sed.exe" from UnxUtils. I've
+:: tested this script on a virtualized 32 bits Windows XP installation in both
+:: the Win32 and x64 Windows SDK command prompts. There's a ZIP file with this
+:: script, the patched "libapreq2.mak" makefile and the above executables
+:: available online at the following location:
+::
+:: http://peterodding.com/code/lua/apr/downloads/win32-bootstrap.zip
+::
+:: TODO Currently fails to build libapreq2 for x64. Is it even possible?!
+
+:: Pick either "Debug" or "Release".
+SET BUILD_MODE=Debug
+
+:: Version strings (embedded in filenames and URLs).
+:: This script has only tested with the versions below.
+SET APR_VERSION=1.4.5
+SET APU_VERSION=1.3.12
+SET API_VERSION=1.2.1
+SET APQ_VERSION=2.13
+SET SQLITE_VERSION=3070701
+
+:: Location of source code archives mirror.
+SET APR_MIRROR=http://www.apache.org/dist/apr
+SET APQ_MIRROR=http://www.apache.org/dist/httpd/libapreq
+SET SQLITE_SITE=http://sqlite.org
+
+:: Names of source code archives.
+SET APR_ARCHIVE=apr-%APR_VERSION%-win32-src.zip
+SET APU_ARCHIVE=apr-util-%APU_VERSION%-win32-src.zip
+SET API_ARCHIVE=apr-iconv-%API_VERSION%-win32-src-r2.zip
+SET APQ_ARCHIVE=libapreq2-%APQ_VERSION%.tar.gz
+SET SQLITE_ARCHIVE=sqlite-amalgamation-%SQLITE_VERSION%.zip
+
+:: Try to detect the intended platform.
+IF "%PLATFORM%" == "" (
+ IF /i "%CPU%" == "i386" (
+ SET PLATFORM=Win32
+ ) ELSE (
+ IF /i "%CPU%" == "AMD64" (
+ SET PLATFORM=x64
+ ) ELSE (
+ ECHO Failed to determine CPU type, please set PLATFORM=Win32 or PLATFORM=x64
+ EXIT /b 1
+ )
+ )
+)
+
+:: Get any missing source code archives.
+IF NOT EXIST %APR_ARCHIVE% WGET %APR_MIRROR%/%APR_ARCHIVE% || (ECHO Failed to download APR archive & EXIT /b 1)
+IF NOT EXIST %APU_ARCHIVE% WGET %APR_MIRROR%/%APU_ARCHIVE% || (ECHO Failed to download APR-util archive & EXIT /b 1)
+IF NOT EXIST %API_ARCHIVE% WGET %APR_MIRROR%/%API_ARCHIVE% || (ECHO Failed to download APR-iconv archive & EXIT /b 1)
+IF NOT EXIST %APQ_ARCHIVE% WGET %APQ_MIRROR%/%APQ_ARCHIVE% || (ECHO Failed to download libapreq2 archive & EXIT /b 1)
+IF NOT EXIST %SQLITE_ARCHIVE% WGET %SQLITE_SITE%/%SQLITE_ARCHIVE% || (ECHO Failed to download SQLite3 archive & EXIT /b 1)
+
+:: Create the directory where the resulting binaries are stored.
+IF NOT EXIST binaries MKDIR binaries || (ECHO Failed to create binaries directory & EXIT /b 1)
+
+:: Unpack the source code archives.
+IF NOT EXIST apr (
+ UNZIP -qo %APR_ARCHIVE% || (ECHO Failed to unpack APR archive & EXIT /b 1)
+ MOVE apr-%APR_VERSION% apr || (ECHO Failed to rename APR directory & EXIT /b 1)
+ :: I haven't a clue why this is needed, but it certainly helps :-)
+ TYPE apr\include\apr.hw > apr\apr.h
+ TYPE apr\include\apr.hw > apr\include\apr.h
+)
+IF NOT EXIST apr-util (
+ UNZIP -qo %APU_ARCHIVE% || (ECHO Failed to unpack APR-util archive & EXIT /b 1)
+ MOVE apr-util-%APU_VERSION% apr-util || (ECHO Failed to rename APR-util directory & EXIT /b 1)
+)
+IF NOT EXIST apr-iconv (
+ UNZIP -qo %API_ARCHIVE% || (ECHO Failed to unpack APR-iconv archive & EXIT /b 1)
+ MOVE apr-iconv-%API_VERSION% apr-iconv || (ECHO Failed to rename APR-iconv directory & EXIT /b 1)
+)
+IF NOT EXIST libapreq2 (
+ COPY %APQ_ARCHIVE% %APQ_ARCHIVE%.tmp
+ GUNZIP -f %APQ_ARCHIVE% || (ECHO Failed to decompress libapreq2 archive & EXIT /b 1)
+ MOVE %APQ_ARCHIVE%.tmp %APQ_ARCHIVE%
+ TAR xf *.tar || (ECHO Failed to unpack libapreq2 archive & EXIT /b 1)
+ DEL libapreq2-*.tar
+ MOVE libapreq2-%APQ_VERSION% libapreq2 || (ECHO Failed to rename libapreq2 directory & EXIT /b 1)
+)
+IF NOT EXIST sqlite3 (
+ UNZIP -qo %SQLITE_ARCHIVE% || (ECHO Failed to unpack SQLite3 archive & EXIT /b 1)
+ MOVE sqlite-amalgamation-%SQLITE_VERSION% sqlite3 || (ECHO Failed to rename SQLite3 directory & EXIT /b 1)
+ :: Copy sqlite3.h (needed to build apr_dbd_sqlite3-1.dll).
+ COPY /Y sqlite3\sqlite3.h apr-util\include || (ECHO Failed to copy sqlite3.h & EXIT /b 1)
+)
+
+:: APR creates 32 bit builds in the "Debug" and "Release" directories
+:: but 64 bit builds in the "x64\Debug" or "x64\Release" directories.
+SET BUILD_DIR=%BUILD_MODE%
+IF %PLATFORM% == x64 SET BUILD_DIR=x64\%BUILD_DIR%
+
+:: Build the APR library.
+PUSHD apr
+NMAKE /nologo /f libapr.mak CFG="libapr - %PLATFORM% %BUILD_MODE%" || (POPD & ECHO Failed to build APR library & EXIT /b 1)
+POPD
+COPY apr\%BUILD_DIR%\libapr-1.dll binaries || (ECHO Failed to copy APR binary & EXIT /b 1)
+IF EXIST apr\%BUILD_DIR%\libapr-1.pdb COPY apr\%BUILD_DIR%\libapr-1.pdb binaries
+
+:: Build the APR-iconv library.
+PUSHD apr-iconv
+NMAKE /nologo /f libapriconv.mak CFG="libapriconv - %PLATFORM% %BUILD_MODE%" || (POPD & ECHO Failed to build APR-iconv library & EXIT /b 1)
+POPD
+:: Workaround for "LINK : fatal error LNK1181: cannot open input file ..\Debug\libapriconv-1.lib".
+IF %PLATFORM% == x64 XCOPY /Y apr-iconv\x64\%BUILD_MODE% apr-iconv
+COPY apr-iconv\%BUILD_DIR%\libapriconv-1.dll binaries
+IF EXIST apr-iconv\%BUILD_DIR%\libapriconv-1.pdb COPY apr-iconv\%BUILD_DIR%\libapriconv-1.pdb binaries
+:: TODO I'm not sure how or why but apparently the above does not build the
+:: *.so files, instead they are built by the apr-util section below. This is
+:: why the *.so files are copied after building apr-util instead of here...
+
+:: Build the APR-util library.
+IF "%PLATFORM%" == "x64" (
+ :: I haven't a clue why this is needed, but it certainly helps :-)
+ TYPE apr-util\include\apu.hw > apr-util\include\apu.h
+)
+PUSHD apr-util
+NMAKE /nologo /f libaprutil.mak CFG="libaprutil - %PLATFORM% %BUILD_MODE%" || (POPD & ECHO Failed to build APR-util library & EXIT /b 1)
+POPD
+COPY apr-util\%BUILD_DIR%\libaprutil-1.dll binaries
+IF EXIST apr-util\%BUILD_DIR%\libaprutil-1.pdb COPY apr-util\%BUILD_DIR%\libaprutil-1.pdb binaries
+
+:: TODO As explained above, apr-util builds the apr-iconv *.so files...
+IF NOT EXIST binaries\iconv MKDIR binaries\iconv
+COPY apr-iconv\%BUILD_MODE%\iconv\*.so binaries\iconv
+COPY apr-iconv\%BUILD_MODE%\iconv\*.pdb binaries\iconv
+
+:: Build the SQLite3 database driver.
+PUSHD sqlite3
+CL /LD /D"SQLITE_API=__declspec(dllexport)" sqlite3.c || (POPD & ECHO Failed to build SQLite3 library & EXIT /b 1)
+POPD
+COPY /Y sqlite3\sqlite3.dll binaries || (POPD & ECHO Failed to copy sqlite3.dll & EXIT /b 1)
+COPY /Y sqlite3\sqlite3.lib apr-util\dbd || (POPD & ECHO Failed to copy sqlite3.lib & EXIT /b 1)
+PUSHD apr-util\dbd
+NMAKE /nologo /f apr_dbd_sqlite3.mak CFG="apr_dbd_sqlite3 - %PLATFORM% %BUILD_MODE%" || (POPD & ECHO Failed to build SQLite3 driver & EXIT /b 1)
+POPD
+COPY apr-util\dbd\%BUILD_MODE%\apr_dbd_sqlite3-1.dll binaries
+IF EXIST apr-util\dbd\%BUILD_MODE%\apr_dbd_sqlite3-1.pdb COPY apr-util\dbd\%BUILD_MODE%\apr_dbd_sqlite3-1.pdb binaries
+
+:: Build the libapreq2 library.
+SET ROOT="%CD%"
+:: The makefile included with libapreq2 assumes it's build as part of Apache.
+:: We replace it with a custom makefile that doesn't include the Apache glue.
+TYPE libapreq2.mak > libapreq2\win32\libapreq2.mak
+PUSHD libapreq2
+NMAKE /nologo /f win32\libapreq2.mak CFG="libapreq2 - %PLATFORM% %BUILD_MODE%" ROOT="%ROOT%" APR_LIB="%ROOT%\apr\%BUILD_DIR%\libapr-1.lib" APU_LIB="%ROOT%\apr-util\%BUILD_DIR%\libaprutil-1.lib" || (POPD & ECHO Failed to build libapreq2 library & EXIT /b 1)
+POPD
+COPY libapreq2\win32\libs\libapreq2.dll binaries
+IF EXIST libapreq2\win32\libs\libapreq2.pdb COPY libapreq2\win32\libs\libapreq2.pdb binaries
Please sign in to comment.
Something went wrong with that request. Please try again.