-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
executable file
·171 lines (142 loc) · 5.28 KB
/
Makefile
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#<copyright notice="lm-source" pids="" years="2007,2022">
#***************************************************************************
# Copyright (c) 2007,2019 IBM Corp.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Contributors:
# Jerry Stevens - Initial implementation
# Various members of the WebSphere MQ Performance Team at IBM Hursley UK
#***************************************************************************
#*</copyright>
############################################################################
# #
# Performance Harness for IBM MQ C-MQI interface #
# #
############################################################################
# Determine OS type
ifeq ($(OS),Windows_NT)
OSTYPE = $(OS)
else
OSTYPE = $(shell uname -s)
UNIX = 1
endif
###########################################################################
# Include file to set OS-specific options
#
# There are several variables that these files should set,
# which specifiy compiler and linker programs, file extensions,
# command line flags to specify various option, amongst others.
#
# In addition the following vraibles can be appended to to add
# add-hoc options:
#
# CPPDEFS - Preprocessor definitions (specified WITHOUT the appropriate
# command-line option flag (e.g. -D))
# CCFLAGS - Additional compiler flags for both C and C++ files
# CFLAGS - Additional compiler flags for C files only
# CXXFLAGS - Additional compiler flags for C++ files only
# LDFLAGS - Additional linker flags
#
# Additionally, the variables release_<X> and debug_<X> can be appended to,
# where X is one of CCFLAGS, CFLAGS, or CXXFALGS, which will set
# those additional flags only for a release or debug build respectively.
###########################################################################
CPPDEFS = __STDC_FORMAT_MACROS
ifeq ($(OSTYPE),Windows_NT)
include cygwin.mk
endif
ifeq ($(OSTYPE),Linux)
include linux.mk
endif
ifeq ($(OSTYPE),AIX)
include aix.mk
endif
# Program to build
CPH = cph$(EXE)
INSTALL = install
# Source directory
SRC = src
# Properties directory
PROPS = props
#C source file extension
CSRC = c
#C++ source file extension
CPPSRC = cpp
# Full list of object files to be created (one for each source file)
OBJS = $(patsubst $(SRC)/%.$(CSRC), %$(OBJ), $(wildcard $(SRC)/*.$(CSRC))) $(patsubst $(SRC)/%.$(CPPSRC), %$(OBJ), $(wildcard $(SRC)/*.$(CPPSRC)))
# List of include directories
INCLUDE += $(MQ_INSTALLATION_PATH)/inc
# OS-arch subolder name to put build outputs
BTYPE = $(OSTYPE)_$(ARCH)
$(info Platform sub-directory: $(BTYPE))
# Client applications to build
.DEFAULT_GOAL := Release
GOALS = \
Debug \
Release
# Make debug a trace build
Debug_CCFLAGS += $(SYM)CPH_DOTRACE -g
Release_CCFLAGS += $(SYM)NDEBUG
# Include dependency files
DEPS = $(patsubst $(SRC)/%.$(CSRC), %$(DEP), $(wildcard $(SRC)/*.$(CSRC))) $(patsubst $(SRC)/%.$(CPPSRC), %$(DEP), $(wildcard $(SRC)/*.$(CPPSRC)))
ifeq ($(MAKECMDGOALS),)
-include $(DEPS:%=$(.DEFAULT_GOAL)/$(BTYPE)/%)
else
-include $(DEPS:%=$(MAKECMDGOALS)/$(BTYPE)/%)
endif
# Don't delete binary or dependecy files
.PRECIOUS: %$(OBJ) %/$(CPH)
# Conditionally set additional compiler flags depending on the type of goal (release or debug)
define EXTRA
$(1)%$(OBJ): $(2)FLAGS += $$($(1)_$(2)FLAGS)
endef
$(foreach goal,$(GOALS),$(foreach ftype,CC C CXX,$(eval $(call EXTRA,$(goal),$(ftype)))))
# Rule to make 'Debug' or 'Release' version of cph
$(GOALS): %: %/$(BTYPE)/install
# Chaining rule to allow CPH to be 'installed' if installdir is specified
ifdef installdir
$(info Installation directory: $(installdir))
# Recipe to copy built executable and properties file to install directory,
# if installdir was specified on the command line
%/install: %/$(CPH)
@echo "Copying files to install directory $(installdir)"
$(MKDIR) $(installdir)
$(CP) $(@D)/$(CPH) $(installdir)/$(CPH)
$(CP) $(PROPS)/* $(installdir)
else
%/install: %/$(CPH)
@echo "No install dir specified (see mq-cph manual on how to set this)."
@echo "cph executable created in $(@D) directory."
endif
# Rule to link executable from object files
%/$(CPH): $(OBJS:%=\%/%)
@$(MKDIRPART)
@echo "Linking executable: $@"
$(LD) $(OUT) $(@D)/*$(OBJ) $(LIBS:%=$(LIB)%) $(LDFLAGS)
@echo " "
.SECONDEXPANSION:
# Rule to build C objects
%$(OBJ):: $(SRC)/$$(notdir $$*).$(CSRC)
@$(MKDIRPART)
@echo "Building C object: $< -> $@"
$(cc) $(OUT) $< $(CPPDEFS:%=$(SYM)%) $(INCLUDE:%=$(INC)%) $(CCFLAGS) $(CFLAGS)
@echo " "
# Rule to build C++ objects
%$(OBJ):: $(SRC)/$$(notdir $$*).$(CPPSRC)
@$(MKDIRPART)
@echo "Building C++ object: $< -> $@"
$(CC) $(OUT) $< $(CPPDEFS:%=$(SYM)%) $(INCLUDE:%=$(INC)%) $(CCFLAGS) $(CXXFLAGS)
@echo " "
clean:
$(RMDIR) $(GOALS:%=%/$(BTYPE))