Skip to content

Commit

Permalink
makefile refactored
Browse files Browse the repository at this point in the history
  • Loading branch information
yedf committed Jun 15, 2015
1 parent 1f95f0e commit 6f432a6
Show file tree
Hide file tree
Showing 14 changed files with 89 additions and 42 deletions.
50 changes: 48 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,50 @@
# OPT ?= -O2 -DNDEBUG
# (B) Debug mode, w/ full line-level debugging symbols
OPT ?= -g2
# (C) Profiling mode: opt, but w/debugging symbols
# OPT ?= -O2 -g2 -DNDEBUG
$(shell ./build_config 1>&2)
include config.mk
default clean:
cd handy && make $@ || exit 1

CFLAGS += -I. -I./include $(PLATFORM_CCFLAGS) $(OPT)
CXXFLAGS += -I. -I./include $(PLATFORM_CXXFLAGS) $(OPT)

LDFLAGS += $(PLATFORM_LDFLAGS)
LIBS += $(PLATFORM_LIBS)

HANDY_SOURCES += $(shell find handy -name '*.cc')
HANDY_OBJECTS = $(HANDY_SOURCES:.cc=.o)

TEST_SOURCES = $(shell find test -name '*.cc')
TEST_OBJECTS = $(TEST_SOURCES:.cc=.o)

EXAMPLE_SOURCES += $(shell find examples -name '*.cc')
EXAMPLES = $(EXAMPLE_SOURCES:.cc=)

LIBRARY = libhandy.a

TARGETS = $(LIBRARY) handy_test $(EXAMPLES)

default: $(TARGETS)
handy_examples: $(EXAMPLES)
$(EXAMPLES): $(LIBRARY)

clean:
-rm -f $(TARGETS)
-rm -f */*.o

$(LIBRARY): $(HANDY_OBJECTS)
rm -f $@
$(AR) -rs $@ $(HANDY_OBJECTS)

handy_test: $(TEST_OBJECTS) $(LIBRARY)
$(CXX) $^ -o $@ $(LDFLAGS) $(LIBRARY) $(LIBS)

.cc.o:
$(CXX) $(CXXFLAGS) -c $< -o $@

.c.o:
$(CC) $(CFLAGS) -c $< -o $@

.cc:
$(CXX) -o $@ $< $(CXXFLAGS) $(LDFLAGS) $(LIBRARY) $(LIBS)
14 changes: 12 additions & 2 deletions build_config
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,18 @@ PLATFORM_IS_LITTLE_ENDIAN=$?

$CXX -x c++ - -o $TMPDIR/handy_build_config.out >/dev/null 2>&1 <<EOF
#include <sys/epoll.h>
int main(){}
int main() {}
EOF
[ $? = 0 ] && COMMON_FLAGS="$COMMON_FLAGS -DUSE_EPOLL"

COMMON_FLAGS="$COMMON_FLAGS -DPLATFORM_IS_LITTLE_ENDIAN=$PLATFORM_IS_LITTLE_ENDIAN -std=c++11"
$CXX -x c++ - -o $TMPDIR/handy_build_config.out >/dev/null 2>&1 <<EOF
#include <openssl/ssl.h>
int main() {}
EOF
[ $? = 0 ] && SSL=1 && ! [ -e ssl ] && git clone https://github.com/yedf/handy-ssl.git ssl
[ x$SSL = x1 ] && PLATFORM_LIBS="$PLATFORM_LIBS -lssl -lcrypto"

COMMON_FLAGS="$COMMON_FLAGS -DLITTLE_ENDIAN=$PLATFORM_IS_LITTLE_ENDIAN -std=c++11"
PLATFORM_CCFLAGS="$PLATFORM_CCFLAGS $COMMON_FLAGS"
PLATFORM_CXXFLAGS="$PLATFORM_CXXFLAGS $COMMON_FLAGS"

Expand All @@ -163,3 +170,6 @@ 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
[ x$SSL = x1 ] && echo "HANDY_SOURCES=ssl/ssl-conn.cc" >> $OUTPUT
[ x$SSL = x1 ] && echo "EXAMPLE_SOURCES=ssl/ssl-cli.cc ssl/ssl-svr.cc ssl/https-svr.cc" >> $OUTPUT

8 changes: 4 additions & 4 deletions examples/chat.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include "codec.h"
#include <handy/conn.h>
#include <handy/logging.h>
#include <handy/daemon.h>
#include <handy/codec.h>
#include <map>

using namespace std;
Expand Down
8 changes: 4 additions & 4 deletions examples/codec-cli.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include "codec.h"
#include <handy/conn.h>
#include <handy/logging.h>
#include <handy/daemon.h>
#include <handy/codec.h>

using namespace std;
using namespace handy;
Expand Down
5 changes: 2 additions & 3 deletions examples/codec-svr.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include <handy/conn.h>
#include <handy/daemon.h>

using namespace std;
using namespace handy;
Expand Down
7 changes: 3 additions & 4 deletions examples/daemon.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "conn.h"
#include "conf.h"
#include "logging.h"
#include "daemon.h"
#include <handy/conn.h>
#include <handy/conf.h>
#include <handy/daemon.h>

using namespace std;
using namespace handy;
Expand Down
5 changes: 2 additions & 3 deletions examples/echo.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include <handy/conn.h>
#include <handy/daemon.h>

using namespace std;
using namespace handy;
Expand Down
6 changes: 2 additions & 4 deletions examples/hsha.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include <signal.h>
#include <handy/conn.h>
#include <handy/daemon.h>

using namespace std;
using namespace handy;
Expand Down
5 changes: 2 additions & 3 deletions examples/http-echo.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "http.h"
#include "logging.h"
#include "daemon.h"
#include <handy/http.h>
#include <handy/daemon.h>

using namespace std;
using namespace handy;
Expand Down
8 changes: 3 additions & 5 deletions examples/log.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include "codec.h"
#include <map>
#include <handy/logging.h>
#include <unistd.h>
#include <time.h>

using namespace std;
using namespace handy;
Expand Down
7 changes: 3 additions & 4 deletions examples/stat.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "http.h"
#include "logging.h"
#include "daemon.h"
#include "stat-svr.h"
#include <handy/http.h>
#include <handy/daemon.h>
#include <handy/stat-svr.h>

using namespace std;
using namespace handy;
Expand Down
5 changes: 2 additions & 3 deletions examples/write-on-empty.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "conn.h"
#include "logging.h"
#include "daemon.h"
#include <handy/conn.h>
#include <handy/daemon.h>
#include <thread>

using namespace std;
Expand Down
1 change: 1 addition & 0 deletions handy/handy-imp.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include "logging.h"
#include "util.h"
#include "net.h"
#include "threads.h"
Expand Down
2 changes: 1 addition & 1 deletion handy/port_posix.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include <string>
namespace handy {
namespace port {
static const int kLittleEndian = PLATFORM_IS_LITTLE_ENDIAN;
static const int kLittleEndian = LITTLE_ENDIAN;
inline uint16_t htobe(uint16_t v) {
if (!kLittleEndian) {
return v;
Expand Down

0 comments on commit 6f432a6

Please sign in to comment.