forked from yedf2/handy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yedf
committed
Jun 15, 2015
1 parent
cb8a2b9
commit 3ea91fe
Showing
18 changed files
with
609 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,4 @@ | ||
$(shell ./build_config 1>&2) | ||
include config.mk | ||
Nothing: default | ||
default clean: | ||
@for d in $(SUBDIRS);\ | ||
do \ | ||
echo "making $@ in $$d"; \ | ||
(cd $$d && make $@ -j2) || exit 1; \ | ||
done | ||
cd handy && make $@ || exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,165 @@ | ||
#!/bin/sh | ||
LIBNAME=handy | ||
OPT="-O0 -g -std=c++11 -Wall -I. -I../$LIBNAME $OPT" | ||
#OPT ?= -O2 -DNDEBUG # (A) Production use (optimized mode) | ||
#OPT ?= -g # (B) Debug mode, w/ full line-level debugging symbols | ||
# OPT ?= -O2 -g2 -DNDEBUG # (C) Profiling mode: opt, but w/debugging symbols | ||
# | ||
# Detects OS we're compiling on and outputs a file specified by the first | ||
# argument, which in turn gets read while processing Makefile. | ||
# | ||
# The output will set the following variables: | ||
# CC C Compiler path | ||
# CXX C++ Compiler path | ||
# PLATFORM_LDFLAGS Linker flags | ||
# PLATFORM_LIBS Libraries flags | ||
# PLATFORM_SHARED_EXT Extension for shared libraries | ||
# PLATFORM_SHARED_LDFLAGS Flags for building shared library | ||
# This flag is embedded just before the name | ||
# of the shared library without intervening spaces | ||
# PLATFORM_SHARED_CFLAGS Flags for compiling objects for shared library | ||
# PLATFORM_CCFLAGS C compiler flags | ||
# PLATFORM_CXXFLAGS C++ compiler flags. Will contain: | ||
# PLATFORM_SHARED_VERSIONED Set to 'true' if platform supports versioned | ||
# shared libraries, empty otherwise. | ||
# | ||
|
||
OUTPUT=config.mk | ||
SUBDIRS="handy examples" | ||
#git clone https://github.com/yedf/handy-ut ut | ||
#git clone https://github.com/yedf/gtest.git ut/gtest | ||
[ -e app ] && SUBDIRS="$SUBDIRS app" | ||
pkg-config --cflags protobuf > /dev/null 2>&1 && SUBDIRS="$SUBDIRS protobuf" | ||
|
||
if [ -e ut/gtest ]; then | ||
echo "making gtest" | ||
cd ut/gtest/make; make; cd ../../.. | ||
SUBDIRS="$SUBDIRS ut" | ||
# Delete existing output, if it exists | ||
rm -f $OUTPUT | ||
touch $OUTPUT | ||
|
||
if test -z "$CC"; then | ||
CC=cc | ||
fi | ||
|
||
if test -z "$CXX"; then | ||
CXX=g++ | ||
fi | ||
|
||
echo '#include <openssl/ssl.h>' > /tmp/handy.test.cc | ||
g++ -c /tmp/handy.test.cc -o /tmp/handy.test.o && SUBDIRS="$SUBDIRS ssl" | ||
SSL=$? | ||
[ $SSL = 0 ] && ! [ -e ssl ] && git clone https://github.com/yedf/handy-ssl.git ssl | ||
! [ $SSL = 0 ] && echo "openssl dev not installed, ignore ssl support" | ||
|
||
CFLAGS="$CFLAGS $OPT" | ||
CXXFLAGS="$CXXFLAGS $OPT" | ||
LDFLAGS="$LDFLAGS -pthread -L../$LIBNAME -l$LIBNAME" | ||
echo '' > $OUTPUT | ||
echo "CC=cc" >> $OUTPUT | ||
echo "CXX=g++" >> $OUTPUT | ||
echo "CFLAGS=$CFLAGS" >> $OUTPUT | ||
echo "CXXFLAGS=$CXXFLAGS" >> $OUTPUT | ||
echo "LDFLAGS=$LDFLAGS" >> $OUTPUT | ||
echo "SUBDIRS=$SUBDIRS" >> $OUTPUT | ||
echo "LIBNAME=$LIBNAME" >> $OUTPUT | ||
echo "LIBFILE=../$LIBNAME/lib${LIBNAME}.a" >> $OUTPUT | ||
echo "$OUTPUT generated" | ||
if test -z "$TMPDIR"; then | ||
TMPDIR=/tmp | ||
fi | ||
|
||
# Detect OS | ||
if test -z "$TARGET_OS"; then | ||
TARGET_OS=`uname -s` | ||
fi | ||
|
||
COMMON_FLAGS= | ||
CROSS_COMPILE= | ||
PLATFORM_CCFLAGS= | ||
PLATFORM_CXXFLAGS= | ||
PLATFORM_LDFLAGS= | ||
PLATFORM_LIBS= | ||
PLATFORM_SHARED_EXT="so" | ||
PLATFORM_SHARED_LDFLAGS="-shared -Wl,-soname -Wl," | ||
PLATFORM_SHARED_CFLAGS="-fPIC" | ||
PLATFORM_SHARED_VERSIONED=true | ||
|
||
case "$TARGET_OS" in | ||
CYGWIN_*) | ||
PLATFORM=OS_LINUX | ||
COMMON_FLAGS="$MEMCMP_FLAG -lpthread -DOS_LINUX -DCYGWIN" | ||
PLATFORM_LDFLAGS="-lpthread" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
Darwin) | ||
PLATFORM=OS_MACOSX | ||
COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX -Dthread_local=__thread" | ||
PLATFORM_SHARED_EXT=dylib | ||
[ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd` | ||
PLATFORM_SHARED_LDFLAGS="-dynamiclib -install_name $INSTALL_PATH/" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
Linux) | ||
PLATFORM=OS_LINUX | ||
COMMON_FLAGS="$MEMCMP_FLAG -pthread -DOS_LINUX" | ||
PLATFORM_LDFLAGS="-pthread" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
SunOS) | ||
PLATFORM=OS_SOLARIS | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_SOLARIS" | ||
PLATFORM_LIBS="-lpthread -lrt" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
FreeBSD) | ||
PLATFORM=OS_FREEBSD | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_FREEBSD" | ||
PLATFORM_LIBS="-lpthread" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
NetBSD) | ||
PLATFORM=OS_NETBSD | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_NETBSD" | ||
PLATFORM_LIBS="-lpthread -lgcc_s" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
OpenBSD) | ||
PLATFORM=OS_OPENBSD | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_OPENBSD" | ||
PLATFORM_LDFLAGS="-pthread" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
DragonFly) | ||
PLATFORM=OS_DRAGONFLYBSD | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_DRAGONFLYBSD" | ||
PLATFORM_LIBS="-lpthread" | ||
PORT_FILE=port/port_posix.cc | ||
;; | ||
OS_ANDROID_CROSSCOMPILE) | ||
PLATFORM=OS_ANDROID | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_ANDROID -DLEVELDB_PLATFORM_POSIX" | ||
PLATFORM_LDFLAGS="" # All pthread features are in the Android C library | ||
PORT_FILE=port/port_posix.cc | ||
CROSS_COMPILE=true | ||
;; | ||
HP-UX) | ||
PLATFORM=OS_HPUX | ||
COMMON_FLAGS="$MEMCMP_FLAG -D_REENTRANT -DOS_HPUX" | ||
PLATFORM_LDFLAGS="-pthread" | ||
PORT_FILE=port/port_posix.cc | ||
# man ld: +h internal_name | ||
PLATFORM_SHARED_LDFLAGS="-shared -Wl,+h -Wl," | ||
;; | ||
IOS) | ||
PLATFORM=IOS | ||
COMMON_FLAGS="$MEMCMP_FLAG -DOS_MACOSX" | ||
[ -z "$INSTALL_PATH" ] && INSTALL_PATH=`pwd` | ||
PORT_FILE=port/port_posix.cc | ||
PLATFORM_SHARED_EXT= | ||
PLATFORM_SHARED_LDFLAGS= | ||
PLATFORM_SHARED_CFLAGS= | ||
PLATFORM_SHARED_VERSIONED= | ||
;; | ||
*) | ||
echo "Unknown platform!" >&2 | ||
exit 1 | ||
esac | ||
|
||
$CXX -x c++ - -o $TMPDIR/handy_build_config.out <<EOF | ||
int main(){ | ||
unsigned short a = 1; | ||
return *(unsigned char*)&a == 1; | ||
} | ||
EOF | ||
$TMPDIR/handy_build_config.out | ||
PLATFORM_IS_LITTLE_ENDIAN=$? | ||
|
||
$CXX -x c++ - -o $TMPDIR/handy_build_config.out >/dev/null 2>&1 <<EOF | ||
#include <sys/epoll.h> | ||
int main(){} | ||
EOF | ||
[ x$? == 0 ] && COMMON_FLAGS="$COMMON_FLAGS -DUSE_EPOLL" | ||
|
||
COMMON_FLAGS="$COMMON_FLAGS -DPLATFORM_IS_LITTLE_ENDIAN=$PLATFORM_IS_LITTLE_ENDIAN -std=c++11" | ||
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS" | ||
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS" | ||
|
||
echo "CC=$CC" >> $OUTPUT | ||
echo "CXX=$CXX" >> $OUTPUT | ||
echo "PLATFORM=$PLATFORM" >> $OUTPUT | ||
echo "PLATFORM_LDFLAGS=$PLATFORM_LDFLAGS" >> $OUTPUT | ||
echo "PLATFORM_LIBS=$PLATFORM_LIBS" >> $OUTPUT | ||
echo "PLATFORM_CCFLAGS=$PLATFORM_CCFLAGS" >> $OUTPUT | ||
echo "PLATFORM_CXXFLAGS=$PLATFORM_CXXFLAGS" >> $OUTPUT | ||
echo "PLATFORM_SHARED_CFLAGS=$PLATFORM_SHARED_CFLAGS" >> $OUTPUT | ||
echo "PLATFORM_SHARED_EXT=$PLATFORM_SHARED_EXT" >> $OUTPUT | ||
echo "PLATFORM_SHARED_LDFLAGS=$PLATFORM_SHARED_LDFLAGS" >> $OUTPUT | ||
echo "PLATFORM_SHARED_VERSIONED=$PLATFORM_SHARED_VERSIONED" >> $OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#include "conf.h" | ||
#include <algorithm> | ||
#include <memory> | ||
#include <stdlib.h> | ||
|
||
using namespace std; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.