Win32 compilation fixes
[libs/core.git] / Makefile
1 NAME            = core
2
3 WORKDIR         = $(PWD)/../..
4 TMP             = $(WORKDIR)/tmp/linux
5 TGT             = $(HOME)/local
6
7 CXX             = g++
8 CC              = gcc
9 AR              = ar
10 CP              = cp
11
12 LIBFILE         = libmsp$(NAME)
13
14 MAKEFLAGS       += -s --no-print-directory
15 INCLUDE         = -Isource -I$(TMP)/include
16 LIB             = -L$(TMP)
17 DEBUG           = 
18 CFLAGS          = $(DEBUG) $(INCLUDE) -pipe -Wall 
19 CXXFLAGS        = $(CFLAGS)
20
21 PIC             = -fPIC
22 SHARED          = .so
23 STATIC          = .a
24
25 override CFLAGS         += `pkg-config --cflags sigc++-2.0`
26 override LDFLAGS        += `pkg-config --libs sigc++-2.0`
27 override CXXFLAGS       += `pkg-config --cflags sigc++-2.0`
28
29 SRC             = source
30 SUBDIRS         = core time
31 OBJS            = $(foreach SUBDIR, $(SUBDIRS), $(addprefix $(TMP)/$(SUBDIR)/, $(addsuffix .o, $(notdir $(basename $(wildcard $(SRC)/$(SUBDIR)/*.cpp))))))
32
33 pkgincludedir   = include/msp
34 libdir          = lib
35
36 foo = "echo $</$(SUBDIR); mkdir -p $</$(SUBDIR); $(CP) -r $(SRC)/$(SUBDIR)/*.h $</$(SUBDIR)"
37 .PHONY: all
38 all: $(TMP) $(TMP)/$(LIBFILE)$(SHARED) $(TMP)/$(LIBFILE)$(STATIC) tmpheaders
39
40 # Create temp directory
41 $(TMP):
42         mkdir -p $@
43
44 # Dynamic library
45 $(TMP)/$(LIBFILE)$(SHARED): $(OBJS)
46         echo "Compiling $(notdir $@)"
47         $(CXX) $^ -shared -o $@ $(LIB)
48
49 # Static library
50 $(TMP)/$(LIBFILE)$(STATIC): $(OBJS)
51         echo "Compiling $(notdir $@)"
52         $(AR) rcs $@ $^
53
54 # Copy headers to temp
55 .PHONY: tmpheaders
56 tmpheaders: $(TMP)/$(pkgincludedir)
57         $(foreach SUBDIR, $(SUBDIRS), \
58                 mkdir -p $</$(SUBDIR) ; \
59                 $(CP) -R $(SRC)/$(SUBDIR)/*.h $</$(SUBDIR) ; \
60         )
61 #       $(foreach SUBDIR, $(SUBDIRS), $(CP) -r $(SRC)/$(SUBDIR)/*.h $</$(SUBDIR))
62
63 $(TMP)/$(pkgincludedir):
64         mkdir -p $@
65
66 # Library object file
67 $(TMP)/%.o: $(SRC)/%.cpp $(wildcard $(SRC)/*.h)
68         mkdir -p $(dir $@)
69         echo "Compiling $(NAME)/$(notdir $(basename $@))"
70         $(CXX) $(PIC) $(CXXFLAGS) -c $< -o $@
71
72 # Installs
73 .PHONY: install
74 install: install_lib 
75
76 $(TGT)/$(pkgincludedir):
77         mkdir -p $@
78
79 $(TGT)/$(libdir):
80         mkdir -p $@
81
82 .PHONY: install_headers
83 install_headers: $(TGT)/$(pkgincludedir)
84         echo "Installing $(NAME) headers to $<"
85         $(foreach SUBDIR, $(SUBDIRS), $(CP) $(SRC)/$(SUBDIR)/*.h $</$(SUBDIR))
86
87 .PHONY: install_lib
88 install_lib: $(TGT)/$(libdir) $(TMP)/$(LIBFILE)$(SHARED)
89         echo "Installing dynamic library to $<"
90         $(CP) $(TMP)/$(LIBFILE)$(SHARED) $<
91
92 .PHONY: install_staticlib
93 install_staticlib: $(TGT)/$(libdir) $(TMP)/$(LIBFILE)$(STATIC)
94         echo "Installing static library to $<"
95         $(CP) $(TMP)/$(LIBFILE)$(STATIC) $<