[原]在win上编译 subversion 源码实践Tonyfield的专栏

(百度和网页的作者无关,不对其内容负责。百度快照谨为网络故障时之索引,不代表被搜索网站的即时页面。)

[原]在win上编译 subversion 源码实践

2013-6-9阅读400 评论0

(参考 http://svn.apache.org/repos/asf/subversion/trunk/INSTALL 的 E. Building the Latest Source under Windows)

资源准备

1, 下载subversion源码下载地址: http://subversion.apache.org/download/#recommended-release,win平台下载zip包你可以选择 release版本也可以选择rc1测试版本。

2. VS6VS2002,VS2003,VS2005,VS2008 中的一种

3. python2.5 或更高版本下载地址:http://www.python.org/

4. perl 5.8.   下载地址:http://dl.pcgames.com.cn/download/50293.html

5. AWK.exe。 下载地址 http://www.cs.princeton.edu/~bwk/btl.mirror/awk95.exe

6. 三个库文件 Apache apr(版本 0.9.12 或更高)apr-util apr-iconv (可选项) 下载地址:http://www.apache.org/dist/apr/不想这样下载源码编译可以下载二进制打包的库下载地址:文件http://www.apache.org/dist/apr/binaries/win32/

7. 【可选项】Apache 2 源码下载地址:http://httpd.apache.org/download.cgi

8. 【可选项】Berkerly DB4 下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=688db-4.3.27-win32.zip 和 db-4.4.20-win32.zip哪个都行。

9. 【可选项】openssl 0.9.7f 下载地址: http://www.openssl.org/source/openssl-0.9.7f.tar.gz. 

10. 【可选项】GNU libintl的修改版本称作 svn-win32-libintl.zip用来显示本地化信息下载地址:http://subversion.tigris.org/servlets/ProjectDocumentList?folderID=2627

11. 【可选项】GNUGettex下载地址:http://www.gnu.org/software/gettext/

12.  【可选项】汇编语言编译器 MASM32下载地址:http://www.masm32.com/或是 NASM 下载地址:

虽然很多标明可选项但从subversion的编译批处理文件模板来看还是都配置的比较方便。

安装过程:

1. 创建SVN 目录如将源码解压到指定路径下。例如 E:SVN在命令行运行下载版本的指令

   svn co https://svn.apache.org/repos/asf/subversion/trunk src-trunk

 或者将下载的 zip文件解压到SVN中将文件夹名称(例如:subversion-1.7.10)换成 src-trunk。

2 . 安装 VS6VS2002,VS2003,VS2005,VS2008 中的一种。注册环境变量VS6.0 执行 VCVARS32.BAT批处理文件更 高版本运行程序菜单中的 “Microsoft Visual Studio 200x" -> "Visual Studio Tools" -> “Visual Studio 200x Command Prompt ” (中文 : “Visual Studio 200x 命令提示”)

如果你使用 VS6.0还要安装和注册当前Windows Core SDK。

"To register the SDK bin, include, and library directories with Microsoft Visual Studio�� version 6.0 and Visual Studio .NET, click Start, point to All Programs, point to Microsoft Platform SDK February 2003, point to Visual Studio Registration, and then click Register PSDK Directories with Visual Studio. This registration process places the SDK bin, include, and library directories at the beginning of the search paths, which ensures that the latest headers and libraries are used when building applications in the IDE. Note that for Visual Studio 6.0 integration to succeed, Visual Studio 6.0 must run at least once before you select Register PSDK Directories with Visual Studio. Also note that when this option is run, the IDEs should not be running."

3. 安装 python2.5 或更高版本。

4. 安装 perl 5.8. 

5. 将 AWK95.exe。复制到 SVNawkawk.exe将这个路径加入path环境变量

6. 三个库文件 Apache apr, apr-util, apr-iconv (可选项) 版本 0.9.12 或更高。 下载地址:http://www.apache.org/dist/apr/不想这样下载源码编译可以下载二进制打包的库下载地址:文件 http://www.apache.org/dist/apr/binaries/win32/

7. 如果你要编译server模块下载 httpd 2.x.x 源码下载地址:http://mirror.bit.edu.cn/apache//httpd/binaries/win32/目前windows平台下的httpd源码只有2.0.64版本解压到SVNhttpd-2.x.x用VS6.0或更高版本打开Apache.dsw全编报错

解决办法:

In case anyone else runs across this, the problem was with the ordering of the headers... windows.h can be commented out and wincrypt.h should be moved to after apr.h:

// #include <windows.h> <<---- commented
#include "apr.h"
#include <wincrypt.h>   // <<---- move to after apr.h
#include "apr_private.h"
#include "apr_general.h"
#include "apr_portable.h"
#include "apr_arch_misc.h"


参考:http://www.spinics.net/lists/apache-users/msg75121.html

然后遇到报错 AWK 不是有效命令明明完成了步骤4但还是报错参考 http://blog.csdn.net/ftomorrow/article/details/3980143在VC6.0 的 菜单Tools -> Options -> 选项 Directories -> Executable files 中加入 AWk 路径。编译成功


8. 如果你不用dependency中的zlib模块也可以到 http://www.zlib.net/ 下载源码解压到 SVNzlib-x.x.x

9. 下载 Berkerly DB 下载地址(需要注册免费的):http://www.oracle.com/technetwork/products/berkeleydb/downloads/index-082944.html

安装好后到安装目录下复制include 和 lib 文件夹到 路径 SVNsrc-trunkdb4-win32

10. 在 http://www.openssl.org/ 下载 openssl源码解压到 SVNopenssl-x.x.x

11. 解压svn-win32-libintl.zip 到 SVNsvn-win32-libintl目录它依赖于 Gettext

12. 解压 Gettext 到 SVNGettext

13. 解压 NASM  到 SVNNASM 目录或 MASM32 到 SVNMASM32nasm.exe 改名为nasmw.exe否则编译时会报告找不到nasmw可执行文件。

编译SVN

打开 SVNsrc-trunkuildwin32vc6-build.bat.in修改并另存为  批处理文件 vc6-build.bat

实际上我在上述源码目录树中保留了版本号如用 nasm-2.10.07 目录名代替了 nasm目录名用gettext-0.18.2目录名代替了gettext用openssl-0.9.7f代替了openssl。后来在编译openssl时发现openssl的脚本都假设了工作目录名是openssl不能是其他所以openssl的目录名是固定不能变的。

@echo off
@REM Licensed to the Apache Software Foundation (ASF) under one
@REM or more contributor license agreements.  See the NOTICE file
@REM distributed with this work for additional information
@REM regarding copyright ownership.  The ASF licenses this file
@REM to you under the Apache License, Version 2.0 (the
@REM "License"); you may not use this file except in compliance
@REM with the License.  You may obtain a copy of the License at
@REM
@REM   http://www.apache.org/licenses/LICENSE-2.0
@REM
@REM Unless required by applicable law or agreed to in writing,@REM software distributed under the License is distributed on an
@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
@REM KIND, either express or implied.  See the License for the
@REM specific language governing permissions and limitations
@REM under the License.

rem ====== Environment change lives only for the duration of the script
setlocal

rem ====== Set these shell variables before doing a build.
rem VER is used to name the output bin dir as svn-win32-%VER%
set VER=trunk
rem DIR is appended to src- to make the dir name, e.g., src-trunk
set DIR=trunk
set DRIVE=E
set SVNDIR=E:workdirSVN
set PYTHONDIR=C:Program Filespython33
set AWKDIR=%SVNDIR%AWK
set HTTPDDIR=httpd-2.0.64
set OPENSSLDIR=openssl-0.9.7f
set ZLIBDIR=zlib-1.2.8
set GETTEXTDIR=gettext-0.18.2
set NASMDIR=nasm-2.10.07
set SDKINC=C:Program FilesMicrosoft SDKsWindowsv5.0Include
set SDKLIB=C:Program FilesMicrosoft SDKsWindowsv6.0Alib
set APACHEDIR=C:Program FilesApache Software FoundationApache2.2
set GETTEXTINC=%SVNDIR%\%GETTEXTDIR%include
set GETTEXTLIB=%SVNDIR%\%GETTEXTDIR%lib
set GETTEXTBIN=%SVNDIR%\%GETTEXTDIR%in
rem ====== End of shell variables which need to be set.

rem Set up path to include Python and BDB.
PATH=%PATH%;%SVNDIR%SVNsrc-%DIR%db4-win32;%SVNDIR%\%NASMDIR%;%PYTHONDIR%;%AWKDIR%;%GETTEXTBIN%

rem Set INCLUDE and LIB for the msdev builds.
set INCLUDE=%SDKINC%;%INCLUDE%;%GETTEXTINC%
set LIB=%SDKLIB%;%LIB%;%GETTEXTLIB%

echo %INCLUDE%

rem Check that the subversion code exists here.
cd %SVNDIR%src-%DIR%
if not exist subversion goto wrongstartdir
cd ..

rem ====== Check the prerequisites are at least in the right place.
if not exist %HTTPDDIR% goto httpderr
if not exist %NASMDIR% goto nasmerr
if not exist %OPENSSLDIR% goto opensslerr
if not exist src-%DIR% goto svnerr
if not exist %ZLIBDIR% goto zliberr
if not exist %ZLIBDIR%zlibstat.lib goto zlibstaterr
if not exist src-%DIR%db4-win32 goto bdberr
rem if not exist src-%DIR%
eon goto neonerr
if not exist %GETTEXTDIR% goto gettexterr
goto allok

:wrongstartdir
echo Unable to find %SVNDIR%src-%DIR%subversion
goto theveryend
:httpderr
echo Unable to find %HTTPDDIR%
goto end
:nasmerr
echo Unable to find %NASMDIR%
goto end
:opensslerr
echo Unable to find %OPENSSLDIR%
goto end
:svnerr
echo Unable to find Subversion source in src-%DIR%
goto end
:zliberr
echo Unable to find %ZLIBDIR%
goto end
:zlibstaterr
echo Please copy %ZLIBDIR%static32zlibstat.lib to %ZLIBDIR%zlibstat.lib
goto end
:bdberr
echo Unable to find Berekely DB
goto end
:neonerr
echo Unable to find neon
goto end
:gettexterr
echo Unable to find %GETTEXTDIR%
goto end
:allok

rem ====== Build openssl.
cd %OPENSSLDIR%
perl Configure VC-WIN32
call msdo_nasm
nmake -f ms
tdll.mak
cd out32dll
call ..ms	est
cd ....

rem ====== Build Apache 2
cd src-%DIR%
python gen-make.py -t dsp --with-httpd=..\%HTTPDDIR% --with-berkeley-db=db4-win32 --with-openssl=..\%OPENSSLDIR% --with-zlib=..\%ZLIBDIR% --enable-nls --enable-bdb-in-apr-util
cd ..
msdev %HTTPDDIR%apache.dsw /MAKE "BuildBin - Win32 Release"

rem ====== Subversion
cd src-%DIR%
msdev subversion_msvc.dsw /USEENV /MAKE "__ALL_TESTS__ - Win32 Release"
mkdir Releasesubversion	estscmdline
xcopy /S /Y subversion	estscmdline Releasesubversion	estscmdline
copy Releasesubversionmod_dav_svnmod_dav_svn.so "%APACHEDIR%modules"
copy Releasesubversionmod_authz_svnmod_authz_svn.so "%APACHEDIR%modules"
cd ..

rem ====== Copy the binaries into a tree suitable for zipping.
mkdir svn-win32-%VER%
mkdir svn-win32-%VER%in
mkdir svn-win32-%VER%httpd
mkdir svn-win32-%VER%iconv
copy src-%DIR%db4-win32inlibdb42.dll svn-win32-%VER%in
copy %OPENSSLDIR%out32dlllibeay32.dll svn-win32-%VER%in
copy %OPENSSLDIR%out32dllssleay32.dll svn-win32-%VER%in
copy %HTTPDDIR%srclibaprReleaselibapr.dll svn-win32-%VER%in
copy %HTTPDDIR%srclibapr-iconvReleaselibapriconv.dll svn-win32-%VER%in
copy %HTTPDDIR%srclibapr-iconvReleaseiconv*.so svn-win32-%VER%iconv
copy %HTTPDDIR%srclibapr-utilReleaselibaprutil.dll svn-win32-%VER%in
copy gettextinintl.dll svn-win32-%VER%in
copy gettextiniconv.dll svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnsvn.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnadminsvnadmin.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvndumpfiltersvndumpfilter.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnlooksvnlook.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnservesvnserve.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnversionsvnversion.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionsvnrdumpsvnrdump.exe svn-win32-%VER%in
copy src-%DIR%Releasesubversionmod_authz_svnmod_authz_svn.so svn-win32-%VER%httpd
copy src-%DIR%Releasesubversionmod_dav_svnmod_dav_svn.so svn-win32-%VER%httpd
copy svn-win32-%VER%inintl.dll "%APACHEDIR%in"
copy svn-win32-%VER%iniconv.dll "%APACHEDIR%in"
copy svn-win32-%VER%inlibdb42.dll "%APACHEDIR%in"

rem ====== Configure Apache ready for doing tests.
@echo off
echo Configure Apache to use the mod_dav_svn and mod_authz_svn modules
echo by making sure these lines appear uncommented in httpd.conf:
echo LoadModule dav_module         modules/mod_dav.so
echo LoadModule dav_fs_module      modules/mod_dav_fs.so
echo LoadModule dav_svn_module     modules/mod_dav_svn.so
echo LoadModule authz_svn_module   modules/mod_authz_svn.so
echo And further down the file add:
echo ^<Location /svn-test-work/repositories^>
echo  DAV svn
echo  SVNParentPath %SVNDIR%/src-%DIR%/Release/subversion/tests/cmdline/svn-test-work/repositories
echo ^</Location^>
echo ^<Location /svn-test-work/local_tmp/repos^>
echo  DAV svn
echo  SVNPath %SVNDIR%/src-%DIR%/Release/subversion/tests/cmdline/svn-test-work/local_tmp/repos
echo ^</Location^>
echo Then restart Apache.

echo Please configure Apache and press enter:
pause
@echo on

rem ====== Run the tests.
PATH=%SVNDIR%svn-win32-%VER%in;%PATH%
cd src-%DIR%
python win-tests.py -c -r -v
python win-tests.py -c -r -v -u http://localhost
cd ..

:end
cd src-%DIR%
endlocal
:theveryend
call cmd.exe 


期间遇到各种报错的解决方式:

1. 路径找不到

确认 set HTTPDDIR=httpd-2.0.64set OPENSSLDIR=openssl-0.9.7fset ZLIBDIR=zlib-1.2.8set GETTEXTDIR=gettext-0.18.2set NASMDIR=%SVNDIR% asm-2.10.07 各路径是否存在以及文件夹内文件是否完整。

还有就是在 VC6.0 中也要设定SDK 包含路径和 awk 执行路径否则会遇到类似下面的报错

--------------------Configuration: mod_auth_dbm - Win32 Release--------------------

Creating Version Resource
'awk' 不是内部或外部命令也不是可运行的程序或批处理文件。

Error executing c:windowssystem32cmd.exe.

需要在Visual Studio 界面菜单Tools -> Options...设置


2. sal.h 文件不存在(specstring.h 中include "sal.h"语句)。

如果遇到这个问题可以考虑将SDK include 路径设定为 C:Program FilesMicrosoft SDKsWindowsv5.0Include而不要选择 C:Program FilesMicrosoft SDKsWindowsv6.0aInclude。SDK lib文件夹也做相应修改。

  如果不这样修改而是强制加入 9.0/VC/include路径(这个路径下有sal.h文件)可 能发生报错:C:Program FilesMicrosoft Visual Studio 9.0VCIncludestdio.h(237) : error C2485: 'deprecated' : unrecognized extended attribute


3.except getopt.GetoptError, e:

SyntaxError: invalid syntax

如果不是使用python 2.7/2.8而是像本文中用更高的python版本(3.3)except语句应该改为 except getopt.GetoptError as e: 而不是except getopt.GetoptError, e:逗号语法在新的版本中废弃了。由于还存在其他语法报错看来python3.3的语法改动还是有些多后来我还是安装了python 2.7.5而不是继续学习python脚本语言。

4. 找不到 WtsApi32.h

Compiling...
ApacheMonitor.c
E:lhk-workSVNhttpd-2.0.64supportwin32ApacheMonitor.c(45) : fatal error C1083: Cannot open include file: 'WtsApi32.h': No such file or directory
Error executing cl.exe.

这是因为 VC6.0 或 VS2005 或VS2008 选项中没有配置 SDK头文件包含路径。选择菜单 Tools -> Options...在列表中添加 SDK头文件包含目录“C:PROGRAM FILESMICROSOFT SDKSWINDOWSV5.0INCLUDE”

5. 缺少头文件

。。。SVNhttpd-2.0.64srclibaprincludeapr_want.h(52): Could not find the file strings.h.
。。。kSVNhttpd-2.0.64srclibaprincludeapr_want.h(85): Could not find the file sys/uio.h.
。。。SVNhttpd-2.0.64srclibaprincludeapr_want.h(103): Could not find the file arpa/inet.h.

采用简单粗暴的方式可以在apr_want.h 中注释掉出错的宏

#if APR_HAVE_STRINGS_H
//#include <strings.h>
#endif
。。。
#if APR_HAVE_SYS_UIO_H
//#include <sys/uio.h>
#endif
。。。
#if APR_HAVE_ARPA_INET_H
//#include <arpa/inet.h>
#endif
原则上应该是修改apr.h.hw文件模板但似乎不起作用。 

6. 汇编出错

.crypto c4asm 4_win32.asm:30: error: operation size not specified
.crypto c4asm 4_win32.asm:265: error: operation size not specified
.crypto c4asm 4_win32.asm:267: error: operation size not specified
.crypto c4asm 4_win32.asm:271: error: operation size not specified

试过3个版本nasm-2.10.07nasm-2.00nasm-0.99.06都出同样的错误按照http://comments.gmane.org/gmane.comp.encryption.openssl.devel/8634 所说原来openssl-0.9.7f的perl脚本有bug于是去/ 换了稳定版本由于本人钟爱最新版本所以下载 openssl-1.0.2-stable-SNAP-20130614.tar.gz然后发现在编译sha512模块的汇编文件时又报错
. tmp32dllsha512-586.asm:515: error: mismatch in operand sizes

没办法老老实实下载 openssl-0.9.8-stable-SNAP-20130611.tar.gz编译通过。

7.  neon 模块报错因为我们没有添加 neon'模块

Traceback (most recent call last):
  File "gen-make.py", line 317, in <module>
    main(conf, gentype, skip_depends=skip, other_options=rest.list)
  File "gen-make.py", line 65, in main
    generator.write()
  File "buildgeneratorgen_msvc_dsp.py", line 133, in write
    self.write_neon_project_file('neon.dsp')
  File "buildgeneratorgen_win.py", line 1183, in write_neon_project_file
    ('project_guid', self.makeguid('neon')),
  File "buildgeneratorgen_win.py", line 1232, in move_proj_file
    self.write_with_template(dest_file, source_template, data)
  File "buildgeneratorgen_win.py", line 1144, in write_with_template
    self.write_file_if_changed(fname, fout.getvalue())
  File "buildgeneratorgen_win.py", line 1135, in write_file_if_changed
    open(fname, 'wb').write(new_contents)
IOError: [Errno 2] No such file or directory: 'neon\neon.dsp'

在生成 neon.dsp时将报错neon不是必须的可以修改SVNsrc-trunkuildgeneratorgen_win.py 解决当没找到neon模块时设置 self.without_neon = True因为这个标志初始化时值为False。

      except:
        msg = 'WARNING: Error while determining neon version
'
        self.neon_lib = None
        self.without_neon = True

你也可以在 vc6-build.bat 中执行gen_win.py的命令中显式添加 --without-neon参数。

python gen-make.py -t dsp --with-httpd=..\%HTTPDDIR% --with-berkeley-db=db4-win32 --with-openssl=..\%OPENSSLDIR% --with-zlib=..\%ZLIBDIR% --enable-nls --enable-bdb-in --without-neon

8. SVNsrc-trunk 目录下生成 subversion_msvc.dsw 成功后用VC6.0编译报错

8.1 cache-membuffer.c

E:workdirSVNsrc-trunksubversionlibsvn_subrcache-membuffer.c(552) : warning C4013: 'UINT64_C' undefined; assuming extern returning int

E:workdirSVNsrc-trunksubversionlibsvn_subrcache-membuffer.c(999) : error C2059: syntax error : 'bad suffix on number'

E:workdirSVNsrc-trunksubversionlibsvn_subrcache-membuffer.c(999) : error C2146: syntax error : missing ')' before identifier 'l'

解决方法把 MIN_SEGMENT_SIZE定义改为 #define MIN_SEGMENT_SIZE UINT64_C(0x2000000)

8.2 cache.c
Generating Code...
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(216) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(216) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(218) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(218) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(220) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(220) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(222) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64
E:workdirSVNsrc-trunksubversionlibsvn_subrcache.c(222) : error C2520: conversion from unsigned __int64 to double not implemented, use signed __int64

解决方法类型全改为signed __int64权宜之计。

8.3 E:workdirSVNsrc-trunksubversionlibsvn_subrconfig_win.c(55) : error C2065: 'CSIDL_COMMON_APPDATA' : undeclared identifier
E:workdirSVNsrc-trunksubversionlibsvn_subrconfig_win.c(56) : error C2065: 'CSIDL_FLAG_CREATE' : undeclared identifier
E:workdirSVNsrc-trunksubversionlibsvn_subrconfig_win.c(62) : warning C4013: 'SHGetFolderPathW' undefined; assuming extern returning int

E:workdirSVNsrc-trunksubversionlibsvn_subrconfig_win.c(62) : error C2065: 'SHGFP_TYPE_CURRENT' : undeclared identifier

解决方法Tools->Options... 将SDK include目录放最前面同样lib文件夹也放最前面

8.4 E:workdirSVNsrc-trunkuildwin32svn.rc(28) : fatal error RC1015: cannot open include file 'apr_general.h'.

解决方法



原文地址:https://www.cnblogs.com/mull/p/4477800.html