-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMakefile.dist
More file actions
158 lines (129 loc) · 4.76 KB
/
Makefile.dist
File metadata and controls
158 lines (129 loc) · 4.76 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#############################################################################
# Makefile for install: PacketLib
# Project: PacketLib
# Use make variable_name=' options ' to override the variables or make -e to
# override the file variables with the environment variables
# make CFLAGS='-g' or make prefix='/usr'
#############################################################################
SHELL = /bin/sh
####### 1) Project names and system
#SYSTEM: linux or QNX
SYSTEM = linux
PROJECT=PacketLib
####### 2) Directories for the installation
# Prefix for each installed program. Only ABSOLUTE PATH
prefix=/usr/local
exec_prefix=$(prefix)
# The directory to install the binary files in.
bindir=$(exec_prefix)/bin
# The directory to install the local configuration file.
datadir=$(exec_prefix)/share
# The directory to install the libraries in.
libdir=$(exec_prefix)/lib
# The directory to install the info files in.
infodir=$(exec_prefix)/info
# The directory to install the include files in.
includedir=$(exec_prefix)/include
####### 3) Directories for the compiler
OBJECTS_DIR = obj
SOURCE_DIR = examples
LIB_DESTDIR = lib
INCLUDE_DIR = include
LIB_NAME = libpacket
VER_FILE_NAME = PlVersion.h
####### 4) Compiler, tools and options
CC ?= gcc
CXX ?= g++
#Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user
CFLAGS ?= -O2
#Set INCPATH to add the inclusion paths
INCPATH = -I $(includedir)
#Insert the implicit parameter to the compiler:
ALL_CFLAGS = -fexceptions -Wall $(INCPATH) $(CFLAGS)
ifeq ($(SYSTEM), QNX)
ALL_CFLAGS += -Vgcc_ntox86_gpp -lang-c++
endif
#Use CPPFLAGS for the preprocessor
CPPFLAGS =
#Set LIBS for addition library
LIBS = -lstdc++ -lpacket
ifeq ($(SYSTEM), QNX)
LIBS += -lsocket
endif
LINK ?= $(CXX)
#for link
LFLAGS = -shared -Wl,-soname,$(TARGET1) -Wl,-rpath,$(DESTDIR)
AR = ar cqs
TAR = tar -cf
GZIP = gzip -9f
COPY = cp -f
COPY_FILE= $(COPY) -p
COPY_DIR = $(COPY) -pR
DEL_FILE = rm -f
SYMLINK = ln -sf
DEL_DIR = rm -rf
MOVE = mv -f
CHK_DIR_EXISTS= test -d
MKDIR = mkdir -p
####### 5) VPATH
VPATH=$(SOURCE_DIR):$(INCLUDE_DIR):
vpath %.o $(OBJECTS_DIR)
####### 6) Files of the project
INCLUDE=$(foreach dir,$(INCLUDE_DIR), $(wildcard $(dir)/*.h))
OBJECTS = in.o msgqclient.o msgqserver.o out.o
####### 7) Only for library generation
TARGET = $(LIB_NAME).so.$(shell cat version)
TARGETA = $(LIB_NAME).a
TARGETD = $(LIB_NAME).so.$(shell cat version)
TARGET0 = $(LIB_NAME).so
TARGET1 = $(LIB_NAME).so.$(shell cut version -f 1 -d '.')
TARGET2 = $(LIB_NAME).so.$(shell cut version -f 1 -d '.').$(shell cut version -f 2 -d '.')
####### 8) Preliminar operations
$(shell cut $(INCLUDE_DIR)/$(VER_FILE_NAME) -f 3 > version)
#WARNING: use -d ' ' if in the version.h the separator is a space
####### 9) Pattern rules
%.o : %.cpp
$(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@
####### 10) Build rules
all: makeobjdir $(OBJECTS)
$(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS)
$(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS)
$(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS)
$(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS)
makeobjdir:
test -d $(OBJECTS_DIR) || mkdir -p $(OBJECTS_DIR)
#clean: delete all files from the current directory that are normally created by building the program.
clean:
$(DEL_FILE) $(OBJECTS_DIR)/*.o
$(DEL_FILE) *~ core *.core
$(DEL_FILE) version
$(DEL_FILE) prefix
$(DEL_FILE) $(SOURCE_DIR)/msgqserver
$(DEL_FILE) $(SOURCE_DIR)/msgqclient
$(DEL_FILE) $(SOURCE_DIR)/in
$(DEL_FILE) $(SOURCE_DIR)/out
test $(OBJECTS_DIR) = . || $(DEL_DIR) $(OBJECTS_DIR)
#Delete all files from the current directory that are created by configuring or building the program.
distclean: clean
#install: compile the program and copy the executables, libraries,
#and so on to the file names where they should reside for actual use.
install:
$(shell echo $(prefix) > prefix)
# For library installation
$(COPY_FILE) $(LIB_DESTDIR)/$(TARGETA) $(libdir)
$(COPY_FILE) $(LIB_DESTDIR)/$(TARGET0) $(libdir)
$(COPY_FILE) $(LIB_DESTDIR)/$(TARGET1) $(libdir)
$(COPY_FILE) $(LIB_DESTDIR)/$(TARGET2) $(libdir)
$(COPY_FILE) $(LIB_DESTDIR)/$(TARGETD) $(libdir)
test -d $(includedir) || mkdir -p $(includedir)
$(COPY_FILE) $(LIB_DESTDIR)/* $(libdir)
$(COPY_FILE) $(INCLUDE) $(includedir)
#uninstall: delete all the installed files--the copies that the `install' target creates.
uninstall:
#For library uninstall
$(DEL_FILE) $(libdir)/$(TARGETA)
$(DEL_FILE) $(libdir)/$(TARGETD)
$(DEL_FILE) $(libdir)/$(TARGET0)
$(DEL_FILE) $(libdir)/$(TARGET1)
$(DEL_FILE) $(libdir)/$(TARGET2)
$(DEL_FILE) $(addprefix $(includedir)/, $(notdir $(INCLUDE)))