本文主要是介绍移植 logrotate,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
下载需要用到的源码:
ftp://ftp.tw.freebsd.org/distfiles/popt-1.7.tar.gz
https://fedorahosted.org/releases/l/o/logrotate/logrotate-3.8.7.tar.gz
logrotate 编译是需要包含 popt.h 头文件,以及 popt 生成的库文件。先交叉编译 popt 。 并将头文件以及库文件安装到 交叉工具链下
tar xvf popt-1.7.tar.gz
cd popt-1.7/
./configure --prefix=$PWD/tmp --host=i486-openwrt-linux --build=i686-linux
make
make install
cp include/popt.h /opt/openwrt-i386-glibc-gcc/include/
cp lib/libpopt.* /opt/openwrt-i386-glibc-gcc/lib/
logrotate 源码包并没有 configure 文件可以生成 Makefile 。所以只有直接修改源码包自带的 Makefile 。修改前备份原有的 Makefile
tar xvf logrotate-3.8.7.tar.gz
cd logrotate-3.8.7/
cp Makefile Makefile.bak
修改后的 Makefile 如下:
VERSION = $(shell awk '/Version:/ { print $$2 }' logrotate.spec)
OS_NAME = $(shell uname -s)
LFS = $(shell echo `getconf LFS_CFLAGS 2>/dev/null`)
CFLAGS = -Wall -D_GNU_SOURCE -D$(OS_NAME) -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)
PROG = logrotate
MAN = logrotate.8
MAN5 = logrotate.conf.5
LOADLIBES = -lpopt
SVNURL= svn+ssh://svn.fedorahosted.org/svn/logrotate
SVNPUBURL = http://svn.fedorahosted.org/svn/logrotate
SVNTAG = r$(subst .,-,$(VERSION))ifeq ($(WITH_SELINUX),yes)
CFLAGS += -DWITH_SELINUX
LOADLIBES += -lselinux
# See pretest
TEST_SELINUX=1
else
# See pretest
TEST_SELINUX=0
endififeq ($(WITH_ACL),yes)
CFLAGS += -DWITH_ACL
LOADLIBES += -lacl
# See pretest
TEST_ACL=1
else
# See pretest
TEST_ACL=0
endif# openwrt-i386-glibc GCCCFLAGS = -D_GNU_SOURCE -D$(OS_NAME) -DVERSION=\"$(VERSION)\" $(RPM_OPT_FLAGS) $(LFS)CC = i486-openwrt-linux-gccCPP = $(CC) -E -MINSTALL = /usr/bin/installifeq ($(CC),cc)CPP = i486-openwrt-linux-gcc -xMendifBASEDIR = tmp/usr/localifneq ($(POPT_DIR),)CFLAGS += -I$(POPT_DIR)LOADLIBES += -L$(POPT_DIR)
endififneq ($(STATEFILE),)CFLAGS += -DSTATEFILE=\"$(STATEFILE)\"
endifBINDIR = $(BASEDIR)/sbin
MANDIR ?= $(BASEDIR)/man#--------------------------------------------------------------------------OBJS = logrotate.o log.o config.o basenames.o
SOURCES = $(subst .o,.c,$(OBJS) $(LIBOBJS))ifeq ($(RPM_OPT_FLAGS),)
CFLAGS += -g
LDFLAGS = -g
endifLDFLAGS += $(EXTRA_LDFLAGS) $(EXTRA_LIBS)
CFLAGS += $(EXTRA_CPPFLAGS) $(EXTRA_CFLAGS) ifeq (.depend,$(wildcard .depend))
TARGET=$(PROG)
else
TARGET=depend $(PROG)
endifRCSVERSION = $(subst .,-,$(VERSION))all: $(TARGET) pretest$(PROG): $(OBJS)clean:rm -f $(OBJS) $(PROG) core* .dependrm -f ./test/test.ACL ./test/test.SELINUX ./test/error.logdepend:$(CPP) $(CFLAGS) -M $(SOURCES) > .depend# pretest create the file ./test/test.ACL with
# 0 or 1 according to the WITH_ACL=yes presence.
# The file will be used by ./test/test to decide
# if to do the ACL tests or not.
pretest:echo "$(TEST_ACL)" > ./test/test.ACL ;echo "$(TEST_SELINUX)" > ./test/test.SELINUX ;.PHONY : test
test: $(TARGET)(cd test; ./test)install:[ -d $(PREFIX)$(BINDIR) ] || mkdir -p $(PREFIX)$(BINDIR)[ -d $(PREFIX)$(MANDIR) ] || mkdir -p $(PREFIX)$(MANDIR)[ -d $(PREFIX)$(MANDIR)/man8 ] || mkdir -p $(PREFIX)$(MANDIR)/man8[ -d $(PREFIX)$(MANDIR)/man5 ] || mkdir -p $(PREFIX)$(MANDIR)/man5$(INSTALL) -m 755 $(PROG) $(PREFIX)$(BINDIR); \$(INSTALL) -m 644 $(MAN) $(PREFIX)$(MANDIR)/man`echo $(MAN) | sed "s/.*\.//"`/$(MAN); \$(INSTALL) -m 644 $(MAN5) $(PREFIX)$(MANDIR)/man`echo $(MAN5) | sed "s/.*\.//"`/$(MAN5); \co:co RCS/*,v(cd examples; co RCS/*,v)svntag:svn copy $(SVNURL)/trunk $(SVNURL)/tags/$(SVNTAG) -m "Release $(VERSION)"create-archive:@rm -rf /tmp/logrotate-$(VERSION) /tmp/logrotate@cd /tmp; svn export $(SVNPUBURL)/tags/$(SVNTAG) logrotate-$(VERSION)@cd /tmp/logrotate-$(VERSION)@cd /tmp; tar czSpf logrotate-$(VERSION).tar.gz logrotate-$(VERSION)@rm -rf /tmp/logrotate-$(VERSION)@cp /tmp/logrotate-$(VERSION).tar.gz .@rm -f /tmp/logrotate-$(VERSION).tar.gz@echo " "@echo "The final archive is ./logrotate-$(VERSION).tar.gz."archive: clean svntag create-archiveifeq (.depend,$(wildcard .depend))
include .depend
endif
这篇关于移植 logrotate的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!