summaryrefslogtreecommitdiffstats
path: root/openmp/runtime/tools/src/common-rules.mk
blob: c289beb4655058d7337c7a0a377626b4ceac168b (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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# common-rules.mk #

#
#//===----------------------------------------------------------------------===//
#//
#//                     The LLVM Compiler Infrastructure
#//
#// This file is dual licensed under the MIT and the University of Illinois Open
#// Source Licenses. See LICENSE.txt for details.
#//
#//===----------------------------------------------------------------------===//
#

# --------------------------------------------------------------------------------------------------
# This file contains really common definitions used by multiple makefiles. Modify it carefully!
# --------------------------------------------------------------------------------------------------

# --- Creating a directory ---
# A directory cannot be a target, because in Linux* OS directory's timestamp is updated each time a
# file is created or deleted in the directory. We use ".dir" file in place of directory. If such
# file exists, it means directory exists also.

.PRECIOUS : %/.dir                     # Do not delete automatically created files.

%/.dir :
	$(target)
	$(mkdir) $(dir $@)
	$(touch) $@

# --- Rebuilding ---
# Removing or touching .rebuild file causes rebuild.
# To let it work, .rebuild should be added as prerequisite to every rule (dependency with commands)
# except clean* and force*, in this and other makefiles.
.rebuild :
	$(target)
	$(touch) $@

# -- Creating dependency file for C/C++ ---

%.d : %.c .rebuild
	$(target)
	$(c) $(cpp-flags) $(c-flags) $(c-flags-m) $< > $@

%.d : %.cpp .rebuild
	$(target)
	$(cxx) $(cpp-flags) $(cxx-flags) $(cxx-flags-m) $< > $@

# -- Creating preprocessed file for C/C++ ---

%.i : %.c .rebuild
	$(target)
	$(c) $(cpp-flags) $(c-flags) -P $(c-out)$@ $<

%.i : %.cpp .rebuild
	$(target)
	$(cxx) $(cpp-flags) $(cxx-flags) -P $(cxx-out)$@ $<

# -- Compiling C/C++ files ---

%$(obj) : %.c .rebuild
	$(target)
	$(c) $(cpp-flags) $(c-flags) $(c-out)$@ $<

%$(obj) : %.cpp .rebuild
	$(target)
	$(cxx) $(cpp-flags) $(cxx-flags) $(cxx-out)$@ $<

# -- Generate assembly files ---

%$(asm) : %.c .rebuild
	$(target)
	$(c) $(cpp-flags) $(c-flags) -S $(c-out)$@ $<

%$(asm) : %.cpp .rebuild
	$(target)
	$(cxx) $(cpp-flags) $(cxx-flags) -S $(cxx-out)$@ $<

# -- Compiling asm files ---

%$(obj) : %$(asm) .rebuild
	$(target)
        # There is a bug on lrb: icc does not work with "-x assembler-with-cpp" option, so we have
        # to preprocess file manually and then assembly it.
        ifeq "$(os)" "lrb"
	    $(c) -E $(cpp-flags) $< > $@.tmp
	    $(as) $(as-flags) -x assembler $(as-out)$@ $@.tmp
        else
	    $(as) $(as-flags) $(as-out)$@ $<
        endif

# -- Expanding variables in template files ---

# General rule "% : %.var" does not work good, so we have to write more specific rules:
# "%.h : %.h.var", etc.

.PRECIOUS : %.h %.f %.rc               # Do not delete automatically created files.

expand-vars = $(perl) $(tools_dir)expand-vars.pl --strict $(ev-flags) $< $@

# Any generated file depends on kmp_version.c, because we extract build number from that file.

%.h  : %.h.var  \
    kmp_version.c $(tools_dir)expand-vars.pl .rebuild
	$(target)
	$(expand-vars)

%.f  : %.f.var  \
    kmp_version.c $(tools_dir)expand-vars.pl .rebuild
	$(target)
	$(expand-vars)

%.f90  : %.f90.var  \
    kmp_version.c $(tools_dir)expand-vars.pl .rebuild
	$(target)
	$(expand-vars)

%.rc : %.rc.var \
   kmp_version.c $(tools_dir)expand-vars.pl .rebuild
	$(target)
	$(expand-vars)

# -- Making static library ---

.PRECIOUS : %$(lib)                    # Do not delete automatically created files.

%$(lib) : %$(lib).lst .rebuild
	$(target)
	$(rm) $@
	$(ar) $(ar-flags) $(ar-out)$@ $$(cat $<)
        # strip debug info in case it is requested (works for Linux* OS only)
        ifneq "$(dbg_strip)" ""
            ifeq "$(DEBUG_INFO)" "off"
	        objcopy --strip-debug $@
            endif
        endif

# -- Making dynamic library ---

.PRECIOUS : %$(dll)                    # Do not delete automatically created files.

# makefile.mk should properly define imp_file, def_file, res_file, and pdb_file:
#     lin and mac: def_file and res_file should be empty, imp_file and pdb_file do not matter.
#     win: all the variabe may be empty; if a variable specified, it affects ld-flags.
# Note: imp_file and pdb_file are side effect of building this target.
# Note: to workaround CQ215229 $ld-flags-extra introduced to keep options be placed after objects
%$(dll) : %$(dll).lst $(def_file) $(res_file) .rebuild
	$(target)
	$(ld) $(ld-flags-dll) $(ld-flags) $(ld-out)$@ $$(cat $<) $(ld-flags-extra) $(res_file)
        # If stripped pdb exist, rename it to normal pdb name. See devtools.mk for explanation.
        ifneq "$(pdb_file)" ""
            ifeq "$(DEBUG_INFO)" "off"
	        mv $(pdb_file) $(pdb_file).nonstripped
	        mv $(pdb_file).stripped $(pdb_file)
            endif
        endif

%.dbg : %$(dll) .rebuild
	$(target)
	objcopy --only-keep-debug $< $@ 


.PRECIOUS: %.res                       # Do not delete automatically created files.

%.res : %.rc .rebuild
	$(target)
	rc -fo$@ $<

# --- Building helper tools from sources ---

.PRECIOUS: %$(exe)                     # Do not delete automatically created files.

%$(exe) : $(tools_dir)%.cpp .rebuild
	$(target)
	$(cxx) $(cxx-out)$@ $<

# --- Forcing a test ---

test-%/.force : test-%/.dir
	$(target)
	$(rm) $(dir $@).{test,force}

# --- Removing a file in build directory ---

rm-% :
	$(target)
	$(rm) $(patsubst rm-%,%,$@)

# end of file #
OpenPOWER on IntegriCloud