V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
station
V2EX  ›  Linux

如何编译 dnsmasq ? 想自定义功能实在摸不着头脑

  •  
  •   station · 2016-12-01 11:55:01 +08:00 · 4544 次点击
    这是一个创建于 2915 天前的主题,其中的信息可能已经有所发展或是发生改变。
    通常很多包提供 configure 来配置,而 dnsmasq 却没有,而且网上找到的教程都是 make 一下

    Compile time options: IPv6 GNU-getopt no-DBus no-i18n no-IDN DHCP DHCPv6 no-Lua TFTP no-conntrack ipset auth no-DNSSEC loop-detect inotify

    比方说我不需要 ipv6 dhcpv6 而却需要 dnssec


    Makefile

    # dnsmasq is Copyright (c) 2000-2016 Simon Kelley
    #
    # This program is free software; you can redistribute it and/or modify
    # it under the terms of the GNU General Public License as published by
    # the Free Software Foundation; version 2 dated June, 1991, or
    # (at your option) version 3 dated 29 June, 2007.
    #
    # This program is distributed in the hope that it will be useful,
    # but WITHOUT ANY WARRANTY; without even the implied warranty of
    # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    # GNU General Public License for more details.
    #
    # You should have received a copy of the GNU General Public License
    # along with this program. If not, see <http://www.gnu.org/licenses/>;.

    # NOTE: Building the i18n targets requires GNU-make


    # Variables you may well want to override.

    PREFIX = /usr/local
    BINDIR = $(PREFIX)/sbin
    MANDIR = $(PREFIX)/share/man
    LOCALEDIR = $(PREFIX)/share/locale
    BUILDDIR = $(SRC)
    DESTDIR =
    CFLAGS = -Wall -W -O2
    LDFLAGS =
    COPTS =
    RPM_OPT_FLAGS =
    LIBS =

    #################################################################

    # Variables you might want to override.

    PKG_CONFIG = pkg-config
    INSTALL = install
    MSGMERGE = msgmerge
    MSGFMT = msgfmt
    XGETTEXT = xgettext

    SRC = src
    PO = po
    MAN = man

    #################################################################

    # pmake way. (NB no spaces to keep gmake 3.82 happy)
    top!=pwd
    # GNU make way.
    top?=$(CURDIR)

    dbus_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --cflags dbus-1`
    dbus_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DBUS $(PKG_CONFIG) --libs dbus-1`
    idn_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --cflags libidn`
    idn_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_IDN $(PKG_CONFIG) --libs libidn`
    ct_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --cflags libnetfilter_conntrack`
    ct_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_CONNTRACK $(PKG_CONFIG) --libs libnetfilter_conntrack`
    lua_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --cflags lua5.1`
    lua_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_LUASCRIPT $(PKG_CONFIG) --libs lua5.1`
    nettle_cflags = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --cflags nettle hogweed`
    nettle_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC $(PKG_CONFIG) --libs nettle hogweed`
    gmp_libs = `echo $(COPTS) | $(top)/bld/pkg-wrapper HAVE_DNSSEC NO_GMP --copy -lgmp`
    sunos_libs = `if uname | grep SunOS >/dev/null 2>&1; then echo -lsocket -lnsl -lposix4; fi`
    version = -DVERSION='\"`$(top)/bld/get-version $(top)`\"'

    sum?=$(shell $(CC) -DDNSMASQ_COMPILE_OPTS $(COPTS) -E $(top)/$(SRC)/dnsmasq.h | ( md5sum 2>/dev/null || md5 ) | cut -f 1 -d ' ')
    sum!=$(CC) -DDNSMASQ_COMPILE_OPTS $(COPTS) -E $(top)/$(SRC)/dnsmasq.h | ( md5sum 2>/dev/null || md5 ) | cut -f 1 -d ' '
    copts_conf = .copts_$(sum)

    objs = cache.o rfc1035.o util.o option.o forward.o network.o \
    dnsmasq.o dhcp.o lease.o rfc2131.o netlink.o dbus.o bpf.o \
    helper.o tftp.o log.o conntrack.o dhcp6.o rfc3315.o \
    dhcp-common.o outpacket.o radv.o slaac.o auth.o ipset.o \
    domain.o dnssec.o blockdata.o tables.o loop.o inotify.o \
    poll.o rrfilter.o edns0.o arp.o

    hdrs = dnsmasq.h config.h dhcp-protocol.h dhcp6-protocol.h \
    dns-protocol.h radv-protocol.h ip6addr.h

    all : $(BUILDDIR)
    @cd $(BUILDDIR) && $(MAKE) \
    top="$(top)" \
    build_cflags="$(version) $(dbus_cflags) $(idn_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags)" \
    build_libs="$(dbus_libs) $(idn_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs)" \
    -f $(top)/Makefile dnsmasq

    mostly_clean :
    rm -f $(BUILDDIR)/*.mo $(BUILDDIR)/*.pot
    rm -f $(BUILDDIR)/.copts_* $(BUILDDIR)/*.o $(BUILDDIR)/dnsmasq.a $(BUILDDIR)/dnsmasq

    clean : mostly_clean
    rm -f $(BUILDDIR)/dnsmasq_baseline
    rm -f core */core
    rm -f *~ contrib/*/*~ */*~

    install : all install-common

    install-common :
    $(INSTALL) -d $(DESTDIR)$(BINDIR) -d $(DESTDIR)$(MANDIR)/man8
    $(INSTALL) -m 644 $(MAN)/dnsmasq.8 $(DESTDIR)$(MANDIR)/man8
    $(INSTALL) -m 755 $(BUILDDIR)/dnsmasq $(DESTDIR)$(BINDIR)

    all-i18n : $(BUILDDIR)
    @cd $(BUILDDIR) && $(MAKE) \
    top="$(top)" \
    i18n=-DLOCALEDIR=\'\"$(LOCALEDIR)\"\' \
    build_cflags="$(version) $(dbus_cflags) $(ct_cflags) $(lua_cflags) $(nettle_cflags) `$(PKG_CONFIG) --cflags libidn`" \
    build_libs="$(dbus_libs) $(ct_libs) $(lua_libs) $(sunos_libs) $(nettle_libs) $(gmp_libs) `$(PKG_CONFIG) --libs libidn`" \
    -f $(top)/Makefile dnsmasq
    for f in `cd $(PO); echo *.po`; do \
    cd $(top) && cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile $${f%.po}.mo; \
    done

    install-i18n : all-i18n install-common
    cd $(BUILDDIR); $(top)/bld/install-mo $(DESTDIR)$(LOCALEDIR) $(INSTALL)
    cd $(MAN); ../bld/install-man $(DESTDIR)$(MANDIR) $(INSTALL)

    merge :
    @cd $(BUILDDIR) && $(MAKE) top="$(top)" -f $(top)/Makefile dnsmasq.pot
    for f in `cd $(PO); echo *.po`; do \
    echo -n msgmerge $(PO)/$$f && $(MSGMERGE) --no-wrap -U $(PO)/$$f $(BUILDDIR)/dnsmasq.pot; \
    done

    # Cannonicalise .po file.
    %.po :
    @cd $(BUILDDIR) && $(MAKE) -f $(top)/Makefile dnsmasq.pot
    mv $(PO)/$*.po $(PO)/$*.po.orig && $(MSGMERGE) --no-wrap $(PO)/$*.po.orig $(BUILDDIR)/dnsmasq.pot >$(PO)/$*.po;

    $(BUILDDIR):
    mkdir -p $(BUILDDIR)

    # rules below are helpers for size tracking

    baseline : mostly_clean all
    @cd $(BUILDDIR) && \
    mv dnsmasq dnsmasq_baseline

    bloatcheck : $(BUILDDIR)/dnsmasq_baseline mostly_clean all
    @cd $(BUILDDIR) && \
    $(top)/bld/bloat-o-meter dnsmasq_baseline dnsmasq; \
    size dnsmasq_baseline dnsmasq

    # rules below are targets in recusive makes with cwd=$(BUILDDIR)

    $(copts_conf): $(hdrs)
    @rm -f *.o .copts_*
    @touch $@

    $(objs:.o=.c) $(hdrs):
    ln -s $(top)/$(SRC)/$@ .

    $(objs): $(copts_conf) $(hdrs)

    .c.o:
    $(CC) $(CFLAGS) $(COPTS) $(i18n) $(build_cflags) $(RPM_OPT_FLAGS) -c $<

    dnsmasq : $(objs)
    $(CC) $(LDFLAGS) -o $@ $(objs) $(build_libs) $(LIBS)

    dnsmasq.pot : $(objs:.o=.c) $(hdrs)
    $(XGETTEXT) -d dnsmasq --foreign-user --omit-header --keyword=_ -o $@ -i $(objs:.o=.c)

    %.mo : $(top)/$(PO)/%.po dnsmasq.pot
    $(MSGMERGE) -o - $(top)/$(PO)/$*.po dnsmasq.pot | $(MSGFMT) -o $*.mo -

    .PHONY : all clean mostly_clean install install-common all-i18n install-i18n merge baseline bloatcheck
    6 条回复    2016-12-06 23:33:33 +08:00
    q397064399
        1
    q397064399  
       2016-12-01 12:37:43 +08:00
    需要啥功能还是重写吧,这些老的开源项目大多有些年纪了,文档详细还好,摸清楚非常难
    lhbc
        2
    lhbc  
       2016-12-01 13:48:08 +08:00
    make dnsmasq COPTS=-DHAVE_DNSSEC
    lhbc
        3
    lhbc  
       2016-12-01 13:55:51 +08:00
    @lhbc make COPTS=-DHAVE_DNSSEC
    正确的命令是这个

    如果需要安装到 PREFIX ,用
    make COPTS=-DHAVE_DNSSEC install
    station
        4
    station  
    OP
       2016-12-01 19:00:46 +08:00
    @lhbc 测试了下你的方法确实可行 那去除我不需要的功能?
    lhbc
        5
    lhbc  
       2016-12-01 19:16:16 +08:00 via Android
    @station 配置里关掉就行了。
    又不会影响性能。
    schemacs
        6
    schemacs  
       2016-12-06 23:33:33 +08:00
    正好也碰到 raspberry pi3(jessie)上的版本太低,`make COPTS='-DHAVE_DNSSEC -DHAVE_DBUS -DHAVE_IDN -DHAVE_CONNTRACK' all-i18n` 后跟系统自带的 dnsmasq --version 显示的选项基本一致了(多了个 inotify)。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   3000 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 30ms · UTC 13:02 · PVG 21:02 · LAX 05:02 · JFK 08:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.