Home | History | Annotate | Download | only in dropbear
      1 # This Makefile is for Dropbear SSH Server and Client
      2 # @configure_input@
      3 
      4 # invocation:
      5 # make PROGRAMS="dropbear dbclient scp" MULTI=1 STATIC=1 SCPPROGRESS=1
      6 #
      7 # to make a multiple-program statically linked binary "staticdropbearmulti".
      8 # This example will include dropbear, scp, dropbearkey, dropbearconvert, and
      9 # dbclient functionality, and includes the progress-bar functionality in scp.
     10 # Hopefully that seems intuitive.
     11 
     12 ifndef PROGRAMS
     13 	PROGRAMS=dropbear dbclient dropbearkey dropbearconvert
     14 endif
     15 
     16 LTC=libtomcrypt/libtomcrypt.a
     17 LTM=libtommath/libtommath.a
     18 
     19 COMMONOBJS=dbutil.o buffer.o \
     20 		dss.o bignum.o \
     21 		signkey.o rsa.o random.o \
     22 		queue.o \
     23 		atomicio.o compat.o  fake-rfc2553.o
     24 
     25 SVROBJS=svr-kex.o svr-algo.o svr-auth.o sshpty.o \
     26 		svr-authpasswd.o svr-authpubkey.o svr-session.o svr-service.o \
     27 		svr-chansession.o svr-runopts.o svr-agentfwd.o svr-main.o svr-x11fwd.o\
     28 		svr-tcpfwd.o svr-authpam.o
     29 
     30 CLIOBJS=cli-algo.o cli-main.o cli-auth.o cli-authpasswd.o cli-kex.o \
     31 		cli-session.o cli-service.o cli-runopts.o cli-chansession.o \
     32 		cli-authpubkey.o cli-tcpfwd.o cli-channel.o cli-authinteract.o
     33 
     34 CLISVROBJS=common-session.o packet.o common-algo.o common-kex.o \
     35 			common-channel.o common-chansession.o termcodes.o loginrec.o \
     36 			tcp-accept.o listener.o process-packet.o \
     37 			common-runopts.o circbuffer.o
     38 
     39 KEYOBJS=dropbearkey.o gendss.o genrsa.o
     40 
     41 CONVERTOBJS=dropbearconvert.o keyimport.o
     42 
     43 SCPOBJS=scp.o progressmeter.o atomicio.o scpmisc.o
     44 
     45 HEADERS=options.h dbutil.h session.h packet.h algo.h ssh.h buffer.h kex.h \
     46 		dss.h bignum.h signkey.h rsa.h random.h service.h auth.h \
     47 		debug.h channel.h chansession.h config.h queue.h sshpty.h \
     48 		termcodes.h gendss.h genrsa.h runopts.h includes.h \
     49 		loginrec.h atomicio.h x11fwd.h agentfwd.h tcpfwd.h compat.h \
     50 		listener.h fake-rfc2553.h
     51 
     52 dropbearobjs=$(COMMONOBJS) $(CLISVROBJS) $(SVROBJS) 
     53 dbclientobjs=$(COMMONOBJS) $(CLISVROBJS) $(CLIOBJS)
     54 dropbearkeyobjs=$(COMMONOBJS) $(KEYOBJS)
     55 dropbearconvertobjs=$(COMMONOBJS) $(CONVERTOBJS)
     56 scpobjs=$(SCPOBJS)
     57 
     58 VPATH=@srcdir@
     59 srcdir=@srcdir@
     60 
     61 prefix=@prefix@
     62 exec_prefix=${prefix}
     63 bindir=${exec_prefix}/bin
     64 sbindir=${exec_prefix}/sbin
     65 
     66 CC=@CC@
     67 AR=@AR@
     68 RANLIB=@RANLIB@
     69 STRIP=@STRIP@
     70 INSTALL=@INSTALL@
     71 CPPFLAGS=@CPPFLAGS@
     72 CFLAGS=-I. -I$(srcdir) -I$(srcdir)/libtomcrypt/src/headers/ $(CPPFLAGS) @CFLAGS@
     73 LIBS=$(LTC) $(LTM) @LIBS@
     74 LDFLAGS=@LDFLAGS@
     75 
     76 EXEEXT=@EXEEXT@
     77 
     78 # whether we're building client, server, or both for the common objects.
     79 # evilness so we detect 'dropbear' by itself as a word
     80 space:= $(empty) $(empty)
     81 ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdropbearZ, Z$(prog)Z))))
     82 	CFLAGS+= -DDROPBEAR_SERVER
     83 endif
     84 ifneq (,$(strip $(foreach prog, $(PROGRAMS), $(findstring ZdbclientZ, Z$(prog)Z))))
     85 	CFLAGS+= -DDROPBEAR_CLIENT
     86 endif
     87 
     88 
     89 # these are exported so that libtomcrypt's makefile will use them
     90 export CC
     91 export CFLAGS
     92 export RANLIB AR STRIP
     93 
     94 ifeq ($(STATIC), 1)
     95 	LDFLAGS+=-static
     96 endif
     97 
     98 ifeq ($(MULTI), 1)
     99 	TARGETS=dropbearmulti
    100 else
    101 	TARGETS=$(PROGRAMS)
    102 endif
    103 
    104 # for the scp progress meter. The -D doesn't affect anything else.
    105 ifeq ($(SCPPROGRESS), 1)
    106 	CFLAGS+=-DPROGRESS_METER
    107 endif
    108 
    109 #%: $(HEADERS)
    110 #%: $(HEADERS) Makefile
    111 # TODO
    112 
    113 all: $(TARGETS)
    114 
    115 strip: $(TARGETS)
    116 	$(STRIP) $(addsuffix $(EXEEXT), $(TARGETS))
    117 
    118 install: $(addprefix inst_, $(TARGETS))
    119 
    120 installdropbearmulti: insdbmulti $(addprefix insmulti, $(PROGRAMS)) 
    121 
    122 insdbmulti: dropbearmulti
    123 	$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)
    124 	$(INSTALL) -m 755 dropbearmulti$(EXEEXT) $(DESTDIR)$(bindir)
    125 	-chown root $(DESTDIR)$(bindir)/dropbearmulti$(EXEEXT)
    126 	-chgrp 0 $(DESTDIR)$(bindir)/dropbearmulti$(EXEEXT)
    127 
    128 insmultidropbear: dropbearmulti
    129 	-rm -f $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
    130 	-ln -s $(DESTDIR)$(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(sbindir)/dropbear$(EXEEXT) 
    131 
    132 insmulti%: dropbearmulti
    133 	-rm -f $(DESTDIR)$(bindir)/$*$(EXEEXT) 
    134 	-ln -s $(DESTDIR)$(bindir)/dropbearmulti$(EXEEXT) $(DESTDIR)$(bindir)/$*$(EXEEXT) 
    135 
    136 # dropbear should go in sbin, so it needs a seperate rule
    137 inst_dropbear: dropbear
    138 	$(INSTALL) -d -m 755 $(DESTDIR)$(sbindir)
    139 	$(INSTALL) -m 755 dropbear$(EXEEXT) $(DESTDIR)$(sbindir)
    140 	-chown root $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
    141 	-chgrp 0 $(DESTDIR)$(sbindir)/dropbear$(EXEEXT)
    142 
    143 inst_%: $*
    144 	$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)
    145 	$(INSTALL) -m 755 $*$(EXEEXT) $(DESTDIR)$(bindir)
    146 	-chown root $(DESTDIR)$(bindir)/$*$(EXEEXT)
    147 	-chgrp 0 $(DESTDIR)$(bindir)/$*$(EXEEXT)
    148 
    149 
    150 # for some reason the rule further down doesn't like $($@objs) as a prereq.
    151 dropbear: $(dropbearobjs)
    152 dbclient: $(dbclientobjs)
    153 dropbearkey: $(dropbearkeyobjs)
    154 dropbearconvert: $(dropbearconvertobjs)
    155 
    156 dropbear dbclient dropbearkey dropbearconvert: $(HEADERS)  $(LTC) $(LTM) \
    157 													Makefile
    158 	$(CC) $(LDFLAGS) -o $@$(EXEEXT) $($@objs) $(LIBS)
    159 
    160 # scp doesn't use the libs so is special.
    161 scp: $(SCPOBJS)  $(HEADERS) Makefile
    162 	$(CC) $(LDFLAGS) -o $@$(EXEEXT) $(SCPOBJS)
    163 
    164 
    165 # multi-binary compilation.
    166 MULTIOBJS=
    167 ifeq ($(MULTI),1)
    168 	MULTIOBJS=dbmulti.o $(sort $(foreach prog, $(PROGRAMS), $($(prog)objs)))
    169 	CFLAGS+=$(addprefix -DDBMULTI_, $(PROGRAMS)) -DDROPBEAR_MULTI
    170 endif
    171 
    172 dropbearmulti: multilink 
    173 
    174 multibinary: $(HEADERS) $(MULTIOBJS) $(LTC) $(LTM) Makefile
    175 	$(CC) $(LDFLAGS) -o dropbearmulti$(EXEEXT) $(MULTIOBJS) $(LIBS)
    176 
    177 multilink: multibinary $(addprefix link, $(PROGRAMS))
    178 
    179 link%:
    180 	-rm -f $*$(EXEEXT)
    181 	-ln -s dropbearmulti$(EXEEXT) $*$(EXEEXT)
    182 
    183 $(LTC): options.h
    184 	cd libtomcrypt && $(MAKE) clean && $(MAKE)
    185 
    186 $(LTM): options.h
    187 	cd libtommath && $(MAKE)
    188 
    189 .PHONY : clean sizes thisclean distclean tidy ltc-clean ltm-clean
    190 
    191 ltc-clean:
    192 	cd libtomcrypt && $(MAKE) clean
    193 
    194 ltm-clean:
    195 	cd libtommath && $(MAKE) clean
    196 
    197 sizes: dropbear
    198 	objdump -t dropbear|grep ".text"|cut -d "." -f 2|sort -rn
    199 
    200 clean: ltc-clean ltm-clean thisclean
    201 
    202 thisclean:
    203 	-rm -f dropbear dbclient dropbearkey dropbearconvert scp scp-progress \
    204 			dropbearmulti *.o *.da *.bb *.bbg *.prof 
    205 
    206 distclean: clean tidy
    207 	-rm -f config.h
    208 	-rm -f Makefile
    209 
    210 tidy:
    211 	-rm -f *~ *.gcov */*~
    212