From 01bb492fafe7c6f14647b38cb5f8ceb6f6915d05 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:08:48 +0000 Subject: [PATCH 01/15] * cleanup : remove 100% garbage in Makefile.osx --- Makefile.osx | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/Makefile.osx b/Makefile.osx index f241f31e..f83dc3ff 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -12,16 +12,6 @@ LIBS = # Found no good way to detect it from command line. TODO: Might be some osx sysinfo magic CXXFLAGS += -maes -DAESNI - -${PREFIX}: - install: all mkdir -p ${PREFIX}/ cp -r i2p ${PREFIX}/ - - - -# Apple Mac OSX -UNAME_S := $(shell uname -s) -ifeq ($(UNAME_S),Darwin) -endif From 8c218bd5dfbe063e4f826500ebd77530f11cfdf5 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:38:51 +0000 Subject: [PATCH 02/15] * (1/3) update filelist.mk : 3 lists of sources: common, daemon-specific and library-specific --- Makefile | 11 +++++++++-- Makefile.bsd | 1 - Makefile.linux | 2 -- Makefile.osx | 1 - filelist.mk | 35 ++++++++++++++--------------------- 5 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Makefile b/Makefile index 594491ef..560a607a 100644 --- a/Makefile +++ b/Makefile @@ -2,12 +2,19 @@ UNAME := $(shell uname -s) SHLIB := libi2pd.so I2PD := i2p +include filelist.mk + ifeq ($(UNAME),Darwin) + DAEMON_SRC += DaemonLinux.cpp include Makefile.osx -else ifeq ($(UNAME), FreeBSD) +else ifeq ($(UNAME),FreeBSD) + DAEMON_SRC += DaemonLinux.cpp include Makefile.bsd -else +else ifeq ($(UNAME),Linux) + DAEMON_SRC += DaemonLinux.cpp include Makefile.linux +else # win32 + DAEMON_SRC += DaemonWin32.cpp endif all: obj $(SHLIB) $(I2PD) diff --git a/Makefile.bsd b/Makefile.bsd index 17f6ccd9..777e6a73 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -1,7 +1,6 @@ CXX = g++ CXXFLAGS = -O2 NEEDED_CXXFLAGS = -std=c++11 -include filelist.mk INCFLAGS = -I/usr/include/ -I/usr/local/include/ LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread diff --git a/Makefile.linux b/Makefile.linux index c9c72403..6e1987fa 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -18,7 +18,6 @@ endif LIBDIR := /usr/lib -include filelist.mk INCFLAGS = ifeq ($(STATIC),yes) LDLIBS += $(LIBDIR)/libcryptopp.a $(LIBDIR)/libboost_system.a @@ -31,7 +30,6 @@ LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_ endif LIBS = - ifeq ($(USE_AESNI),yes) ifeq ($(IS_64),1) #check if AES-NI is supported by CPU diff --git a/Makefile.osx b/Makefile.osx index f83dc3ff..d690e09c 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -1,6 +1,5 @@ CXX = clang++ CXXFLAGS = -g -Wall -std=c++11 -lstdc++ -I/usr/local/include -include filelist.mk INCFLAGS = -DCRYPTOPP_DISABLE_ASM LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread diff --git a/filelist.mk b/filelist.mk index 8f684be9..ccb79854 100644 --- a/filelist.mk +++ b/filelist.mk @@ -1,21 +1,14 @@ - - -CPP_FILES := CryptoConst.cpp base64.cpp NTCPSession.cpp RouterInfo.cpp Transports.cpp \ - RouterContext.cpp NetDb.cpp LeaseSet.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelGateway.cpp \ - TransitTunnel.cpp I2NPProtocol.cpp Log.cpp Garlic.cpp HTTPServer.cpp Streaming.cpp \ - Destination.cpp Identity.cpp SSU.cpp SSUSession.cpp SSUData.cpp util.cpp Reseed.cpp \ - DaemonLinux.cpp SSUData.cpp aes.cpp SOCKS.cpp UPnP.cpp TunnelPool.cpp HTTPProxy.cpp \ - AddressBook.cpp Daemon.cpp I2PTunnel.cpp SAM.cpp BOB.cpp ClientContext.cpp \ - Datagram.cpp i2p.cpp - - -H_FILES := CryptoConst.h base64.h NTCPSession.h RouterInfo.h Transports.h \ - RouterContext.h NetDb.h LeaseSet.h Tunnel.h TunnelEndpoint.h TunnelGateway.h \ - TransitTunnel.h I2NPProtocol.h Log.h Garlic.h HTTPServer.h Streaming.h Destination.h \ - Identity.h SSU.h SSUSession.h SSUData.h util.h Reseed.h DaemonLinux.h SSUData.h \ - aes.h SOCKS.h UPnP.h TunnelPool.h HTTPProxy.h AddressBook.h Daemon.h I2PTunnel.h \ - version.h Signature.h SAM.h BOB.h ClientContext.h TransportSession.h Datagram.h - - -OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o))) - +COMMON_SRC = \ + AddressBook.cpp CryptoConst.cpp Datagram.cpp Garlic.cpp I2NPProtocol.cpp \ + LeaseSet.cpp Log.cpp NTCPSession.cpp NetDb.cpp Reseed.cpp RouterContext.cpp \ + RouterInfo.cpp SSU.cpp SSUSession.cpp SSUData.cpp Streaming.cpp Identity.cpp \ + TransitTunnel.cpp Transports.cpp Tunnel.cpp TunnelEndpoint.cpp TunnelPool.cpp \ + TunnelGateway.cpp Destination.cpp util.cpp aes.cpp base64.cpp + +# also: Daemon{Linux,Win32}.cpp will be added later +DAEMON_SRC = $(COMMON_SRC) \ + BOB.cpp ClientContext.cpp Daemon.cpp I2PTunnel.cpp SAM.cpp SOCKS.cpp UPnP.cpp \ + HTTPServer.cpp HTTPProxy.cpp i2p.cpp + +LIB_SRC := $(COMMON_SRC) \ + api.cpp From 9552edf82dbdf643640f8ed95ab4777ff3e96841 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:39:35 +0000 Subject: [PATCH 03/15] * (2/3) update main Makefile --- Makefile | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 560a607a..bb17530f 100644 --- a/Makefile +++ b/Makefile @@ -19,19 +19,20 @@ endif all: obj $(SHLIB) $(I2PD) -.SUFFIXES: -.SUFFIXES: .c .cc .C .cpp .o +obj: + mkdir -p obj +# weaker rule for building files without headers obj/%.o : %.cpp $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< -obj: - mkdir -p obj +obj/%.o : %.cpp %.h + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< -$(I2PD): $(OBJECTS:obj/%=obj/%) +$(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) $(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS) $(LIBS) -$(SHLIB): $(OBJECTS:obj/%=obj/%) api.cpp +$(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -shared -o $@ $^ clean: From bc0f0e96a3ae5349cb398e8a074ef5a26775410c Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:40:35 +0000 Subject: [PATCH 04/15] * (3/3) 2nd try : drop api/ subdir --- api/Makefile | 23 ----------------------- api/filelist.mk | 13 ------------- 2 files changed, 36 deletions(-) delete mode 100644 api/Makefile delete mode 100644 api/filelist.mk diff --git a/api/Makefile b/api/Makefile deleted file mode 100644 index 8320cb4f..00000000 --- a/api/Makefile +++ /dev/null @@ -1,23 +0,0 @@ -UNAME := $(shell uname -s) -ifeq ($(UNAME),Darwin) -include ../Makefile.osx -else ifeq ($(UNAME), FreeBSD) -include ../Makefile.bsd -else -include ../Makefile.linux -endif -SHARED_LIB = libi2pd.so -all: obj $(SHARED_LIB) -$(SHARED_LIB): $(OBJECTS:obj/%=obj/%) - $(CXX) -shared -o $(SHARED_LIB) $^ -.SUFFIXES: -.SUFFIXES: .c .cc .C .cpp .o -obj/%.o : ../%.cpp - $(CXX) -o $@ $< -c $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -I.. -fPIC $(CPU_FLAGS) -obj: - mkdir -p obj -clean: - rm -fr obj $(SHARED_LIB) -.PHONY: all -.PHONY: clean - diff --git a/api/filelist.mk b/api/filelist.mk deleted file mode 100644 index 88f68204..00000000 --- a/api/filelist.mk +++ /dev/null @@ -1,13 +0,0 @@ -CPP_FILES := ../CryptoConst.cpp ../base64.cpp ../NTCPSession.cpp ../RouterInfo.cpp \ -../Transports.cpp ../RouterContext.cpp ../NetDb.cpp ../LeaseSet.cpp Tunnel.cpp \ -../TunnelEndpoint.cpp ../TunnelGateway.cpp ../TransitTunnel.cpp ../I2NPProtocol.cpp \ -../Log.cpp ../Garlic.cpp ../Streaming.cpp ../Destination.cpp ../Identity.cpp \ -../SSU.cpp ../SSUSession.cpp ../SSUData.cpp ../util.cpp ../Reseed.cpp ../SSUData.cpp \ -../aes.cpp ../TunnelPool.cpp ../AddressBook.cpp ../Datagram.cpp ../api.cpp -H_FILES := ../CryptoConst.h ../base64.h ../NTCPSession.h ../RouterInfo.h ../Transports.h \ -../RouterContext.h ../NetDb.h ../LeaseSet.h ../Tunnel.h ../TunnelEndpoint.h \ -../TunnelGateway.h ../TransitTunnel.h ../I2NPProtocol.h ../Log.h ../Garlic.h \ -../Streaming.h ../Destination.h ../Identity.h ../SSU.h ../SSUSession.h ../SSUData.h \ -../util.h ../Reseed.h ../SSUData.h ../aes.h ../TunnelPool.h ../AddressBook.h ../version.h \ -../Signature.h ../TransportSession.h ../Datagram.h ../api.h -OBJECTS = $(addprefix obj/, $(notdir $(CPP_FILES:.cpp=.o))) From 4e94bc9efc6b3ae97b67140d2042c2974cdc56f4 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:48:13 +0000 Subject: [PATCH 05/15] * (1/3) cleanup : use $CXXFLAGS instead $CPU_FLAGS --- Makefile | 6 +++--- Makefile.linux | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index bb17530f..d250f091 100644 --- a/Makefile +++ b/Makefile @@ -24,16 +24,16 @@ obj: # weaker rule for building files without headers obj/%.o : %.cpp - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -c -o $@ $< obj/%.o : %.cpp %.h - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -c -o $@ $< $(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) $(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS) $(LIBS) $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) $(CPU_FLAGS) -shared -o $@ $^ + $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -shared -o $@ $^ clean: rm -fr obj $(I2PD) $(SHLIB) diff --git a/Makefile.linux b/Makefile.linux index 6e1987fa..5fbaa815 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -34,7 +34,7 @@ ifeq ($(USE_AESNI),yes) ifeq ($(IS_64),1) #check if AES-NI is supported by CPU ifneq ($(shell grep -c aes /proc/cpuinfo),0) - CPU_FLAGS = -maes -DAESNI + CXXFLAGS += -maes -DAESNI endif endif endif From d6ec412422f2e8b53c16c838513bd85a35924d33 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 07:58:01 +0000 Subject: [PATCH 06/15] * (2/3) cleanup : use $CXXFLAGS instead $NEEDED_FLAGS --- Makefile | 8 ++++---- Makefile.bsd | 3 +-- Makefile.linux | 8 ++++---- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index d250f091..db38b237 100644 --- a/Makefile +++ b/Makefile @@ -24,16 +24,16 @@ obj: # weaker rule for building files without headers obj/%.o : %.cpp - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< obj/%.o : %.cpp %.h - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -c -o $@ $< + $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< $(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) - $(CXX) -o $@ $^ $(LDLIBS) $(LDFLAGS) $(LIBS) + $(CXX) -o $@ $(LDLIBS) $(LDFLAGS) $(LIBS) $^ $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) - $(CXX) $(CXXFLAGS) $(NEEDED_CXXFLAGS) $(INCFLAGS) -shared -o $@ $^ + $(CXX) -o $@ -shared $(CXXFLAGS) $(INCFLAGS) $^ clean: rm -fr obj $(I2PD) $(SHLIB) diff --git a/Makefile.bsd b/Makefile.bsd index 777e6a73..b160f0c8 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -1,6 +1,5 @@ CXX = g++ -CXXFLAGS = -O2 -NEEDED_CXXFLAGS = -std=c++11 +CXXFLAGS = -g -Wall -O2 -std=c++11 INCFLAGS = -I/usr/include/ -I/usr/local/include/ LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread diff --git a/Makefile.linux b/Makefile.linux index 5fbaa815..84d47e68 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -5,13 +5,13 @@ FGREP = fgrep IS_64 := $(shell $(CXX) -dumpmachine 2>&1 | $(FGREP) -c "64") USE_AESNI := yes ifeq ($(shell expr match ${CXXVER} "4\.[0-9][0-9]"),4) # >= 4.10 -NEEDED_CXXFLAGS += -std=c++11 +CXXFLAGS += -std=c++11 else ifeq ($(shell expr match ${CXXVER} "4\.[7-9]"),3) # >= 4.7 -NEEDED_CXXFLAGS += -std=c++11 +CXXFLAGS += -std=c++11 else ifeq ($(shell expr match ${CXXVER} "4\.6"),3) # = 4.6 -NEEDED_CXXFLAGS += -std=c++0x +CXXFLAGS += -std=c++0x else ifeq ($(shell expr match $(CXX) 'clang'),5) -NEEDED_CXXFLAGS += -std=c++11 +CXXFLAGS += -std=c++11 else # not supported $(error Compiler too old) endif From aa0cb6b2c4db5a1d6909a2a0ce807e2addf5c18f Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:01:43 +0000 Subject: [PATCH 07/15] * (3/3) cleanup : unused variable --- Makefile | 2 +- Makefile.bsd | 1 - Makefile.linux | 1 - Makefile.osx | 1 - 4 files changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index db38b237..2296867a 100644 --- a/Makefile +++ b/Makefile @@ -30,7 +30,7 @@ obj/%.o : %.cpp %.h $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< $(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) - $(CXX) -o $@ $(LDLIBS) $(LDFLAGS) $(LIBS) $^ + $(CXX) -o $@ $(LDLIBS) $(LDFLAGS) $^ $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) $(CXX) -o $@ -shared $(CXXFLAGS) $(INCFLAGS) $^ diff --git a/Makefile.bsd b/Makefile.bsd index b160f0c8..12370c3b 100644 --- a/Makefile.bsd +++ b/Makefile.bsd @@ -3,4 +3,3 @@ CXXFLAGS = -g -Wall -O2 -std=c++11 INCFLAGS = -I/usr/include/ -I/usr/local/include/ LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread -LIBS = diff --git a/Makefile.linux b/Makefile.linux index 84d47e68..9f24f709 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -28,7 +28,6 @@ USE_AESNI := no else LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread endif -LIBS = ifeq ($(USE_AESNI),yes) ifeq ($(IS_64),1) diff --git a/Makefile.osx b/Makefile.osx index d690e09c..d7aa9362 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -3,7 +3,6 @@ CXXFLAGS = -g -Wall -std=c++11 -lstdc++ -I/usr/local/include INCFLAGS = -DCRYPTOPP_DISABLE_ASM LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread -LIBS = # OSX Notes # http://www.hutsby.net/2011/08/macs-with-aes-ni.html From 8a43e070d88c843557feaa5e0c263eb8072dbd61 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:02:58 +0000 Subject: [PATCH 08/15] * Makefile.osx : exchange options --- Makefile.osx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile.osx b/Makefile.osx index d7aa9362..331119a9 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -1,6 +1,6 @@ CXX = clang++ -CXXFLAGS = -g -Wall -std=c++11 -lstdc++ -I/usr/local/include -INCFLAGS = -DCRYPTOPP_DISABLE_ASM +CXXFLAGS = -g -Wall -std=c++11 -lstdc++ -DCRYPTOPP_DISABLE_ASM +INCFLAGS = -I/usr/local/include LDFLAGS = -Wl,-rpath,/usr/local/lib -L/usr/local/lib LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread From 5ee49693225a71413fb4ba21b46d3665eb412170 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:05:27 +0000 Subject: [PATCH 09/15] * Makefile.linux : reorder checks --- Makefile.linux | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Makefile.linux b/Makefile.linux index 9f24f709..bcac24f5 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -1,9 +1,8 @@ CXXFLAGS = -g -Wall -fPIC -CXXVER := $(shell $(CXX) -dumpversion) +INCFLAGS = -FGREP = fgrep -IS_64 := $(shell $(CXX) -dumpmachine 2>&1 | $(FGREP) -c "64") -USE_AESNI := yes +# detect proper flag for c++11 support by gcc +CXXVER := $(shell $(CXX) -dumpversion) ifeq ($(shell expr match ${CXXVER} "4\.[0-9][0-9]"),4) # >= 4.10 CXXFLAGS += -std=c++11 else ifeq ($(shell expr match ${CXXVER} "4\.[7-9]"),3) # >= 4.7 @@ -18,7 +17,7 @@ endif LIBDIR := /usr/lib -INCFLAGS = +USE_AESNI := yes ifeq ($(STATIC),yes) LDLIBS += $(LIBDIR)/libcryptopp.a $(LIBDIR)/libboost_system.a LDLIBS += $(LIBDIR)/libboost_date_time.a $(LIBDIR)/libboost_filesystem.a @@ -29,6 +28,8 @@ else LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread endif +FGREP = fgrep +IS_64 := $(shell $(CXX) -dumpmachine 2>&1 | $(FGREP) -c "64") ifeq ($(USE_AESNI),yes) ifeq ($(IS_64),1) #check if AES-NI is supported by CPU From 56c404e6c1bf75fd959b5b57ddda6c5e539c3d5d Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:10:33 +0000 Subject: [PATCH 10/15] * Makefile.linux : use idents with spaces --- Makefile.linux | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/Makefile.linux b/Makefile.linux index bcac24f5..621fa8af 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -4,28 +4,30 @@ INCFLAGS = # detect proper flag for c++11 support by gcc CXXVER := $(shell $(CXX) -dumpversion) ifeq ($(shell expr match ${CXXVER} "4\.[0-9][0-9]"),4) # >= 4.10 -CXXFLAGS += -std=c++11 + CXXFLAGS += -std=c++11 else ifeq ($(shell expr match ${CXXVER} "4\.[7-9]"),3) # >= 4.7 -CXXFLAGS += -std=c++11 + CXXFLAGS += -std=c++11 else ifeq ($(shell expr match ${CXXVER} "4\.6"),3) # = 4.6 -CXXFLAGS += -std=c++0x + CXXFLAGS += -std=c++0x else ifeq ($(shell expr match $(CXX) 'clang'),5) -CXXFLAGS += -std=c++11 + CXXFLAGS += -std=c++11 else # not supported -$(error Compiler too old) + $(error Compiler too old) endif -LIBDIR := /usr/lib - USE_AESNI := yes ifeq ($(STATIC),yes) -LDLIBS += $(LIBDIR)/libcryptopp.a $(LIBDIR)/libboost_system.a -LDLIBS += $(LIBDIR)/libboost_date_time.a $(LIBDIR)/libboost_filesystem.a -LDLIBS += $(LIBDIR)/libboost_regex.a $(LIBDIR)/libboost_program_options.a -LDLIBS += -lpthread -static-libstdc++ -static-libgcc -USE_AESNI := no + LIBDIR := /usr/lib + LDLIBS = $(LIBDIR)/libcryptopp.a + LDLIBS += $(LIBDIR)/libboost_system.a + LDLIBS += $(LIBDIR)/libboost_date_time.a + LDLIBS += $(LIBDIR)/libboost_filesystem.a + LDLIBS += $(LIBDIR)/libboost_regex.a + LDLIBS += $(LIBDIR)/libboost_program_options.a + LDLIBS += -lpthread -static-libstdc++ -static-libgcc + USE_AESNI := no else -LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread + LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread endif FGREP = fgrep From 05a62af99b5112e3adf98931ca7d49f3350af509 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:22:03 +0000 Subject: [PATCH 11/15] * move USE_* to main Makefile --- Makefile | 3 +++ Makefile.linux | 12 ++++++------ Makefile.osx | 4 +++- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 2296867a..7cfdd921 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,9 @@ I2PD := i2p include filelist.mk +USE_AESNI := yes +USE_STATIC := no + ifeq ($(UNAME),Darwin) DAEMON_SRC += DaemonLinux.cpp include Makefile.osx diff --git a/Makefile.linux b/Makefile.linux index 621fa8af..ffb89ee0 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -15,8 +15,7 @@ else # not supported $(error Compiler too old) endif -USE_AESNI := yes -ifeq ($(STATIC),yes) +ifeq ($(USE_STATIC),yes) LIBDIR := /usr/lib LDLIBS = $(LIBDIR)/libcryptopp.a LDLIBS += $(LIBDIR)/libboost_system.a @@ -30,14 +29,15 @@ else LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread endif -FGREP = fgrep -IS_64 := $(shell $(CXX) -dumpmachine 2>&1 | $(FGREP) -c "64") +GREP = fgrep +IS_64 := $(shell $(CXX) -dumpmachine 2>&1 | $(GREP) -c "64") ifeq ($(USE_AESNI),yes) ifeq ($(IS_64),1) #check if AES-NI is supported by CPU -ifneq ($(shell grep -c aes /proc/cpuinfo),0) +ifneq ($(shell $(GREP) -c aes /proc/cpuinfo),1) CXXFLAGS += -maes -DAESNI +else + $(warning "AESNI support enabled requested but not supported by this CPU") endif endif endif - diff --git a/Makefile.osx b/Makefile.osx index 331119a9..ca5fabaf 100644 --- a/Makefile.osx +++ b/Makefile.osx @@ -8,7 +8,9 @@ LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_ # http://www.hutsby.net/2011/08/macs-with-aes-ni.html # Seems like all recent Mac's have AES-NI, after firmware upgrade 2.2 # Found no good way to detect it from command line. TODO: Might be some osx sysinfo magic -CXXFLAGS += -maes -DAESNI +ifeq ($(USE_AESNI),yes) + CXXFLAGS += -maes -DAESNI +endif install: all mkdir -p ${PREFIX}/ From cf8e229098e04c1f13dd5fd92846df4745976312 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 08:53:17 +0000 Subject: [PATCH 12/15] * almost fixed static linking --- Makefile | 4 ++-- Makefile.linux | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 7cfdd921..482ea81f 100644 --- a/Makefile +++ b/Makefile @@ -33,10 +33,10 @@ obj/%.o : %.cpp %.h $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< $(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC)) - $(CXX) -o $@ $(LDLIBS) $(LDFLAGS) $^ + $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS) $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) - $(CXX) -o $@ -shared $(CXXFLAGS) $(INCFLAGS) $^ + $(CXX) -o $@ $^ $(LDFLAGS) $(LDLIBS) clean: rm -fr obj $(I2PD) $(SHLIB) diff --git a/Makefile.linux b/Makefile.linux index ffb89ee0..85a63ac0 100644 --- a/Makefile.linux +++ b/Makefile.linux @@ -17,16 +17,16 @@ endif ifeq ($(USE_STATIC),yes) LIBDIR := /usr/lib - LDLIBS = $(LIBDIR)/libcryptopp.a - LDLIBS += $(LIBDIR)/libboost_system.a + LDLIBS = $(LIBDIR)/libboost_system.a LDLIBS += $(LIBDIR)/libboost_date_time.a LDLIBS += $(LIBDIR)/libboost_filesystem.a LDLIBS += $(LIBDIR)/libboost_regex.a LDLIBS += $(LIBDIR)/libboost_program_options.a + LDLIBS += $(LIBDIR)/libcryptopp.a LDLIBS += -lpthread -static-libstdc++ -static-libgcc USE_AESNI := no else - LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread + LDLIBS = -lcryptopp -lboost_system -lboost_date_time -lboost_filesystem -lboost_regex -lboost_program_options -lpthread -shared endif GREP = fgrep From cd3a7040b063d9a33bd4beb56003cb0f4c6dc6e8 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 13:51:23 +0000 Subject: [PATCH 13/15] * Makefile : add dist target --- Makefile | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Makefile b/Makefile index 482ea81f..48de56da 100644 --- a/Makefile +++ b/Makefile @@ -41,5 +41,12 @@ $(SHLIB): $(patsubst %.cpp,obj/%.o,$(LIB_SRC)) clean: rm -fr obj $(I2PD) $(SHLIB) +LATEST_TAG=$(shell git describe --tags --abbrev=0 master) +dist: + git archive --format=tar.gz -9 --worktree-attributes \ + --prefix=i2pd_$(LATEST_TAG)/ $(LATEST_TAG) -o i2pd_$(LATEST_TAG).tar.gz + + .PHONY: all .PHONY: clean +.PHONY: dist From 0e212f29d076a0bd0cc80b35d8efa81b0aba9539 Mon Sep 17 00:00:00 2001 From: hagen Date: Fri, 12 Dec 2014 13:46:07 +0000 Subject: [PATCH 14/15] * update build/CMakeLists.txt --- build/CMakeLists.txt | 60 +++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 23 deletions(-) diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index 6e483014..893ce8f7 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -4,21 +4,18 @@ project ( "i2pd" ) # configurale options option(WITH_AESNI "Use AES-NI instructions set" OFF) option(WITH_HARDENING "Use hardening compiler flags" OFF) -option(WITH_SHLIB "Build shared library" OFF) +option(WITH_LIBRARY "Build library" ON) +option(WITH_STATIC "Static build" OFF) # paths set ( CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) set ( CMAKE_SOURCE_DIR ".." ) -set (SOURCES +set (COMMON_SRC "${CMAKE_SOURCE_DIR}/AddressBook.cpp" "${CMAKE_SOURCE_DIR}/CryptoConst.cpp" - "${CMAKE_SOURCE_DIR}/Daemon.cpp" "${CMAKE_SOURCE_DIR}/Garlic.cpp" - "${CMAKE_SOURCE_DIR}/HTTPProxy.cpp" - "${CMAKE_SOURCE_DIR}/HTTPServer.cpp" "${CMAKE_SOURCE_DIR}/I2NPProtocol.cpp" - "${CMAKE_SOURCE_DIR}/I2PTunnel.cpp" "${CMAKE_SOURCE_DIR}/Identity.cpp" "${CMAKE_SOURCE_DIR}/LeaseSet.cpp" "${CMAKE_SOURCE_DIR}/Log.cpp" @@ -27,10 +24,9 @@ set (SOURCES "${CMAKE_SOURCE_DIR}/Reseed.cpp" "${CMAKE_SOURCE_DIR}/RouterContext.cpp" "${CMAKE_SOURCE_DIR}/RouterInfo.cpp" - "${CMAKE_SOURCE_DIR}/SOCKS.cpp" "${CMAKE_SOURCE_DIR}/SSU.cpp" "${CMAKE_SOURCE_DIR}/SSUData.cpp" - "${CMAKE_SOURCE_DIR}/SSUSession.cpp" + "${CMAKE_SOURCE_DIR}/SSUSession.cpp" "${CMAKE_SOURCE_DIR}/Streaming.cpp" "${CMAKE_SOURCE_DIR}/Destination.cpp" "${CMAKE_SOURCE_DIR}/TransitTunnel.cpp" @@ -39,22 +35,34 @@ set (SOURCES "${CMAKE_SOURCE_DIR}/Transports.cpp" "${CMAKE_SOURCE_DIR}/TunnelEndpoint.cpp" "${CMAKE_SOURCE_DIR}/TunnelPool.cpp" - "${CMAKE_SOURCE_DIR}/UPnP.cpp" "${CMAKE_SOURCE_DIR}/aes.cpp" "${CMAKE_SOURCE_DIR}/base64.cpp" - "${CMAKE_SOURCE_DIR}/i2p.cpp" "${CMAKE_SOURCE_DIR}/util.cpp" - "${CMAKE_SOURCE_DIR}/SAM.cpp" + "${CMAKE_SOURCE_DIR}/Datagram.cpp" +) + +set (DAEMON_SRC "${CMAKE_SOURCE_DIR}/BOB.cpp" "${CMAKE_SOURCE_DIR}/ClientContext.cpp" - "${CMAKE_SOURCE_DIR}/Datagram.cpp" + "${CMAKE_SOURCE_DIR}/Daemon.cpp" + "${CMAKE_SOURCE_DIR}/HTTPProxy.cpp" + "${CMAKE_SOURCE_DIR}/HTTPServer.cpp" + "${CMAKE_SOURCE_DIR}/I2PTunnel.cpp" + "${CMAKE_SOURCE_DIR}/SAM.cpp" + "${CMAKE_SOURCE_DIR}/SOCKS.cpp" + "${CMAKE_SOURCE_DIR}/UPnP.cpp" + "${CMAKE_SOURCE_DIR}/i2p.cpp" +) + +set (LIBRARY_SRC + "${CMAKE_SOURCE_DIR}/api.cpp" ) file (GLOB HEADERS "${CMAKE_SOURCE_DIR}/*.h") # MSVS grouping source_group ("Header Files" FILES ${HEADERS}) -source_group ("Source Files" FILES ${SOURCES}) +source_group ("Source Files" FILES ${COMMON_SRC} ${DAEMON_SRC} ${LIBRARY_SRC}) # Default build is Debug if (CMAKE_BUILD_TYPE STREQUAL "Release") @@ -64,7 +72,7 @@ else () endif () # compiler flags customization (by vendor) -add_definitions ( "-Wall -Wextra" ) +add_definitions ( "-Wall -Wextra -fPIC" ) # check for c++11 support include(CheckCXXCompilerFlag) @@ -83,7 +91,6 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") add_definitions( "-D_FORTIFY_SOURCE=2" ) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wformat -Wformat-security -Werror=format-security" ) set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstack-protector --param ssp-buffer-size=4" ) - set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIE -pie" ) endif () elseif (CMAKE_CXX_COMPILER_ID STREQUAL "Clang") # more tweaks @@ -91,13 +98,15 @@ endif () # compiler flags customization (by system) if (CMAKE_SYSTEM_NAME STREQUAL "Linux") - list (APPEND SOURCES "../DaemonLinux.cpp") + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") elseif (CMAKE_SYSTEM_NAME STREQUAL "FreeBSD") - list (APPEND SOURCES "../DaemonLinux.cpp") + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") # "'sleep_for' is not a member of 'std::this_thread'" in gcc 4.7/4.8 add_definitions( "-D_GLIBCXX_USE_NANOSLEEP=1" ) +elseif (CMAKE_SYSTEM_NAME STREQUAL "Darwin") + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonLinux.cpp") elseif (CMAKE_SYSTEM_NAME STREQUAL "Windows") - list (APPEND SOURCES "../DaemonWin32.cpp") + list (APPEND DAEMON_SRC "${CMAKE_SOURCE_DIR}/DaemonWin32.cpp") endif () if (WITH_AESNI) @@ -130,21 +139,26 @@ message(STATUS "Install prefix: : ${CMAKE_INSTALL_PREFIX}") message(STATUS "Options:") message(STATUS " AESNI : ${WITH_AESNI}") message(STATUS " HARDENING : ${WITH_HARDENING}") -message(STATUS " SHARED LIB : ${WITH_SHLIB}") +message(STATUS " LIBRARY : ${WITH_LIBRARY}") +message(STATUS " STATIC BUILD : ${WITH_STATIC}") message(STATUS "---------------------------------------") -add_executable ( ${PROJECT_NAME} ${SOURCES} ) +add_executable ( ${PROJECT_NAME} ${COMMON_SRC} ${DAEMON_SRC}) if (WITH_HARDENING AND CMAKE_CXX_COMPILER_ID STREQUAL "GNU") set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-z relro -z now" ) endif () +if (WITH_STATIC) + set(BUILD_SHARED_LIBS OFF) + set_target_properties(${PROJECT_NAME} PROPERTIES LINK_FLAGS "-static" ) +endif () + target_link_libraries( ${PROJECT_NAME} ${Boost_LIBRARIES} ${CRYPTO++_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ) install(TARGETS i2pd RUNTIME DESTINATION "bin") -if (WITH_SHLIB) - list(APPEND SOURCES "${CMAKE_SOURCE_DIR}/api.cpp") - add_library("lib${PROJECT_NAME}" SHARED ${SOURCES}) +if (WITH_LIBRARY) + add_library("lib${PROJECT_NAME}" SHARED ${COMMON_SRC} ${LIBRARY_SRC}) install(TARGETS "lib${PROJECT_NAME}" LIBRARY DESTINATION "lib") endif () From ca2566e778b35955835af7f31a4e73f82bc54276 Mon Sep 17 00:00:00 2001 From: hagen Date: Sat, 13 Dec 2014 13:39:57 +0000 Subject: [PATCH 15/15] * reorder makefile rules : fix depends on header --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 48de56da..bd3c1e9d 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,11 @@ all: obj $(SHLIB) $(I2PD) obj: mkdir -p obj -# weaker rule for building files without headers -obj/%.o : %.cpp +obj/%.o : %.cpp %.h $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< -obj/%.o : %.cpp %.h +# weaker rule for building files without headers +obj/%.o : %.cpp $(CXX) $(CXXFLAGS) $(INCFLAGS) -c -o $@ $< $(I2PD): $(patsubst %.cpp,obj/%.o,$(DAEMON_SRC))