-
Notifications
You must be signed in to change notification settings - Fork 0
/
package.mk
137 lines (104 loc) · 2.99 KB
/
package.mk
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# Package level makefile
# ----------------------
#Makefile:;
# Symbols
# -------
SHELL := /bin/bash
RM := rm -f
MV := mv -f
empty :=
space := $(empty) $(empty)
quiet := @
RELEASE_DIR := $(PWD)
build_dir := ${RELEASE_DIR}/build/psalg
# Defines which directories are being created by this makefile
incdir := $(INSTALLDIR)/psalg
libdir := $(build_dir)/lib
objdir := $(build_dir)/obj
prod_dirs := $(strip $(INSTALLDIR)/lib $(incdir))
LIBEXTNS := so
DEFINES := -fPIC -D_REENTRANT -D__pentium__ -Wall
CC := gcc
CXX := g++
LD := g++
LX := g++
ifneq ($(findstring i386-linux,$(tgt_arch)),)
CXXFLAGS := -m32
CPPFLAGS := $(CFLAGS) -m32
USRLIBDIR := /usr/lib
endif
ifneq ($(findstring x86_64,$(tgt_arch)),)
CPPFLAGS := $(CFLAGS)
USRLIBDIR := /usr/lib64
endif
ifneq ($(findstring -dbg,$(tgt_arch)),)
CPPFLAGS += -g
endif
ifneq ($(findstring -opt,$(tgt_arch)),)
CPPFLAGS += -O4
endif
override CPPFLAGS += -I$(RELEASE_DIR)
# Procedures
# ----------
# Define some procedures and create (different!) rules for libraries
# and targets. Note that 'eval' needs gmake >= 3.80.
incfiles := $(wildcard *.h *.hh *.hpp)
libraries :=
targets :=
objects :=
getobjects = $(strip \
$(patsubst %.cc,$(1)/%.o,$(filter %.cc,$(2))) \
$(patsubst %.cpp,$(1)/%.o,$(filter %.cpp,$(2))) \
$(patsubst %.c,$(1)/%.o, $(filter %.c,$(2))) \
$(patsubst %.s,$(1)/%.o, $(filter %.s,$(2))))
define library_template
library_$(1) := $$(libdir)/lib$(1).$(LIBEXTNS)
libobjs_$(1) := $$(call getobjects,$$(objdir),$$(libsrcs_$(1)))
libraries += $$(library_$(1))
objects += $$(libobjs_$(1))
ifeq ($$(LIBEXTNS),so)
ifneq ($$(ifversn_$(1)),)
ifversnflags_$(1) := -Wl,--version-script=$$(ifversn_$(1))
endif
endif
$$(library_$(1)): $$(libobjs_$(1))
endef
$(foreach lib,$(libnames),$(eval $(call library_template,$(lib))))
temp_dirs := $(strip $(sort $(foreach o,$(objects),$(dir $(o))))) $(libdir)
# Rules
# -----
rules := all dir obj lib bin clean cleanall userall userclean install print
.PHONY: $(rules) $(libnames) $(tgtnames)
.SUFFIXES: # Kills all implicit rules
all: $(temp_dirs) lib
obj: $(objects);
lib: $(libraries);
install: $(prod_dirs)
cp ${incfiles} $(incdir)
cp -rf ${libdir} $(INSTALLDIR)/.
print:
@echo "libdir = $(libdir)"
@echo "objdir = $(objdir)"
@echo "prod_dirs = $(prod_dirs)"
@echo "temp_dirs = $(temp_dirs)"
@echo "libraries = $(libraries)"
@echo "objects = $(objects)"
@echo "CXXFLAGS = $(CXXFLAGS)"
@echo "CPPFLAGS = $(CPPFLAGS)"
clean: userclean
$(quiet)$(RM) $(objects) $(libraries)
cleanall: clean userclean
# Directory structure
$(prod_dirs) $(temp_dirs):
mkdir -p $@
# Libraries
$(libdir)/lib%.$(LIBEXTNS):
@echo "[LD] Build library $*"
$(quiet)$(LD) $(CXXFLAGS) -shared $(ifversnflags_$*) $(linkflags_$*) $^ -o $@
# Objects for C++ assembly files
$(objdir)/%.o: %.cc
@echo "[CX] Compiling $<"
$(quiet)$(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) -c $< -o $@
$(objdir)/%.o: %.cpp
@echo "[CX] Compiling $<"
$(quiet)$(CXX) $(CPPFLAGS) $(DEFINES) $(CXXFLAGS) -c $< -o $@