summaryrefslogtreecommitdiff
path: root/Makefile
blob: a5463d3f7627ccd11be823ba6e405d3e0ae2d9fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
ifeq ($(SYSTEM),)
    SYSTEM = $(shell uname)
endif

TRUESYSTEM = $(shell uname)
MACHINE = $(shell uname -m)
DISTRIB = $(shell cat /etc/issue | cut -f 1 -d\  | head -1)

CC = gcc
CXX = g++
LD = g++
AS = gcc -c
AR = ar rcs

CPPFLAGS += -DPIC -fPIC
LDFLAGS += -fPIC
ifeq ($(DEBUG),)
CPPFLAGS += -O3
else
CPPFLAGS += -g
LDFLAGS += -g
endif

INCLUDES = includes libcoro libeio

ifeq ($(SYSTEM),Darwin)
    LIBS += pthread
    CONFIG_H = darwin-config.h
    ARCH_FLAGS = -arch i386
    LIBS = -liconv
    LD = g++ -arch i386
    STRIP = strip -x
    ifeq ($(TRUESYSTEM),Linux)
        CC = i686-apple-darwin9-gcc
        CXX = i686-apple-darwin9-g++
        LD = i686-apple-darwin-g++ -arch i386 -mmacosx-version-min=10.5
        STRIP = i686-apple-darwin-strip -x
        AS = i686-apple-darwin-as -arch i386
    endif
else
ifeq ($(SYSTEM),Linux)
    LIBS += pthread
    CONFIG_H = linux-config.h
    ARCH_FLAGS = -march=i686 -m32
    ASFLAGS = -march=i686 --32
    STRIP = strip --strip-unneeded
endif
endif

CPPFLAGS_NO_ARCH += $(addprefix -I, $(INCLUDES)) -fexceptions -Wno-deprecated -imacros $(CONFIG_H)
CPPFLAGS += $(CPPFLAGS_NO_ARCH) $(ARCH_FLAGS)

LDFLAGS += $(ARCH_FLAGS) $(addprefix -l, $(LIBS))

vpath %.cc src:tests
vpath %.c libcoro:libeio

BALAU_SOURCES = \
BString.cc \
Local.cc \
Main.cc \
Printer.cc \
Task.cc \
TaskMan.cc \

LIBCORO_SOURCES = \
coro.c \

LIBEIO_SOURCES = \
eio.c \

TEST_SOURCES = \
test-Sanity.cc \
test-String.cc \
test-Tasks.cc \

LIB = libBalau.a

BALAU_OBJECTS = $(addsuffix .o, $(notdir $(basename $(BALAU_SOURCES) $(LIBCORO_SOURCES))))

WHOLE_SOURCES = $(BALAU_SOURCES) $(LIBCORO_SOURCES) $(LIBEIO_SOURCES) $(TEST_SOURCES)
TESTS = $(addsuffix .bin, $(notdir $(basename $(TEST_SOURCES))))

ALL_OBJECTS = $(addsuffix .o, $(notdir $(basename $(WHOLE_SOURCES))))
ALL_DEPS = $(addsuffix .dep, $(notdir $(basename $(WHOLE_SOURCES))))

all: dep lib

tests: $(TESTS)
	for t in $(TESTS) ; do ./$$t ; done

strip: $(TESTS)
	for t in $(TESTS) ; do $(STRIP) ./$$t ; done

lib: $(LIB)

libBalau.a: $(BALAU_OBJECTS)
	$(AR) libBalau.a $(BALAU_OBJECTS)

%.bin : %.o $(LIB)
	$(LD) $(LDFLAGS) -o $@ $< ./$(LIB)

dep: $(ALL_DEPS)

%.dep : %.cc
	$(CXX) $(CPPFLAGS_NO_ARCH) -M -MF $@ $<

%.dep : %.c
	$(CC) $(CPPFLAGS_NO_ARCH) -M -MF $@ $<

-include $(ALL_DEPS)

clean:
	rm -f $(ALL_OBJECTS) $(TESTS) $(LIB) $(ALL_DEPS)

.PHONY: lib tests clean strip