分类: 嵌入式
2014-10-23 16:11:31
1. 在package/ utils下创建privoxy_lib目录。在wifidog_lib目录下创建一个文件夹src和一个Makefile文件。Makefile文件编写内容如下:
#
# Copyright (C) 2006,2013 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=privoxy_lib
PKG_VERSION:=3.0.21
PKG_RELEASE:=1
PKG_LICENSE:=GPLv2
PKG_LICENSE_FILES:=LICENSE
PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)-stable
include $(INCLUDE_DIR)/package.mk
define Package/privoxy_lib
SECTION:=utils
CATEGORY:=Utilities
DEPENDS:=+libpcre +libpthread +zlib
TITLE:=web proxy with advanced filtering capabilities
endef
define Package/privoxy_lib/description
Privoxy is a web proxy with advanced filtering capabilities for
protecting privacy, modifying web page content, managing cookies,
controlling access, and removing ads, banners, pop-ups and other
obnoxious Internet junk. Privoxy has a very flexible configuration
and can be customized to suit individual needs and tastes. Privoxy
has application for both stand-alone systems and multi-user networks.
endef
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
$(CP) ./src/* $(PKG_BUILD_DIR)/
endef
define Build/Configure
endef
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
CFLAGS="$(TARGET_CFLAGS) -Wall" \
LDFLAGS="$(TARGET_LDFLAGS)"
endef
define Package/privoxy_lib/conffiles
/etc/privoxy/config
endef
define Package/privoxy_lib/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/test_libprivoxy $(1)/usr/bin/
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_BUILD_DIR)/libprivoxy.so* $(1)/usr/lib/
$(INSTALL_DIR) $(1)/etc/privoxy
$(CP) $(PKG_INSTALL_DIR)/etc/privoxy/* $(1)/etc/privoxy/
$(INSTALL_CONF) ./files/privoxy.config $(1)/etc/privoxy/config
endef
$(eval $(call BuildPackage,privoxy_lib))
2. 解压privoxy包进入src目录
Tar xzvf privoxy-3.0.21-stable-src.tar.gz –C src
3. 在src下创建Makefile文件,内容如下:
LIB_VERMAJOR = 0
LIB_VERMINOR = 1
LIB_FILENAME = libprivoxy.so
OBJEXT = o
EXTRA_CFLAGS += -pthread -MD -fPIC -DPIC
LIB_CFLAGS = $(CFLAGS) $(EXTRA_CFLAGS) -shared
LIB_LDFLAGS = $(LDFLAGS) -pthread -Wl,-soname,$(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
privoxy_OBJECTS = actions.$(OBJEXT) cgi.$(OBJEXT)\
cgiedit.$(OBJEXT) cgisimple.$(OBJEXT) deanimate.$(OBJEXT) \
encode.$(OBJEXT) errlog.$(OBJEXT) filters.$(OBJEXT) \
gateway.$(OBJEXT) jbsockets.$(OBJEXT) jcc.$(OBJEXT) \
list.$(OBJEXT) loadcfg.$(OBJEXT) loaders.$(OBJEXT) \
miscutil.$(OBJEXT) parsers.$(OBJEXT) \
ssplit.$(OBJEXT) urlmatch.$(OBJEXT) pcrs.$(OBJEXT)\
pcre/get.$(OBJEXT) pcre/maketables.$(OBJEXT) pcre/study.$(OBJEXT)\
pcre/pcre.$(OBJEXT) pcre/pcreposix.$(OBJEXT) privoxyapi.$(OBJEXT)
LIB_OBJ = $(privoxy_OBJECTS)
DEFAULT_INCLUDES = -Ipcre
AM_CPPFLAGS +=
COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
$(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
CCLD = $(CC)
LINK = $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(EXTRA_CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
LIBS = -lnsl -lz
all: Makefile libprivoxy test_libprivoxy
test_libprivoxy: main.o libprivoxy
@rm -f test_libprivoxy
$(LINK) main.o $(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR) $(LIBS)
libprivoxy:$(LIB_OBJ)
$(CC) $(LIB_CFLAGS) $(LIB_LDFLAGS) $(LIB_OBJ) $(LIBS) \
-o $(LIB_FILENAME).$(LIB_VERMAJOR).$(LIB_VERMINOR)
.c.o:
$(CC) $(DEFS) $(AM_CPPFLAGS) $(DEFAULT_INCLUDES) $(INCLUDES) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $<
clean:
rm -f $(LIB_FILENAME)* *.o
4. 修改src下对应的源代码,同时把files/privoxy.init脚本提供的功能通过lib库提供,这样 lib库需要提供int privoxy_start (),int privoxy_stop ()。make package/privoxy_lib/compile V=s进行编译生成libprivoxy.so.0.1和测试程序test_libprivoxy