remove version in all files
[dpdk.git] / mk / internal / rte.compile-pre.mk
1 #   BSD LICENSE
2
3 #   Copyright(c) 2010-2012 Intel Corporation. All rights reserved.
4 #   All rights reserved.
5
6 #   Redistribution and use in source and binary forms, with or without 
7 #   modification, are permitted provided that the following conditions 
8 #   are met:
9
10 #     * Redistributions of source code must retain the above copyright 
11 #       notice, this list of conditions and the following disclaimer.
12 #     * Redistributions in binary form must reproduce the above copyright 
13 #       notice, this list of conditions and the following disclaimer in 
14 #       the documentation and/or other materials provided with the 
15 #       distribution.
16 #     * Neither the name of Intel Corporation nor the names of its 
17 #       contributors may be used to endorse or promote products derived 
18 #       from this software without specific prior written permission.
19
20 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
21 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
22 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 
23 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
24 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
25 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
26 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 
27 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 
28 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
29 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
30 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31
32
33 #
34 # Common to rte.lib.mk, rte.app.mk, rte.obj.mk
35 #
36
37 SRCS-all := $(SRCS-y) $(SRCS-n) $(SRCS-)
38
39 # convert source to obj file
40 src2obj = $(strip $(patsubst %.c,%.o,\
41         $(patsubst %.S,%_s.o,$(1))))
42
43 # add a dot in front of the file name
44 dotfile = $(strip $(foreach f,$(1),\
45         $(join $(dir $f),.$(notdir $f))))
46
47 # convert source/obj files into dot-dep filename (does not
48 # include .S files)
49 src2dep = $(strip $(call dotfile,$(patsubst %.c,%.o.d, \
50                 $(patsubst %.S,,$(1)))))
51 obj2dep = $(strip $(call dotfile,$(patsubst %.o,%.o.d,$(1))))
52
53 # convert source/obj files into dot-cmd filename
54 src2cmd = $(strip $(call dotfile,$(patsubst %.c,%.o.cmd, \
55                 $(patsubst %.S,%_s.o.cmd,$(1)))))
56 obj2cmd = $(strip $(call dotfile,$(patsubst %.o,%.o.cmd,$(1))))
57
58 OBJS-y := $(call src2obj,$(SRCS-y))
59 OBJS-n := $(call src2obj,$(SRCS-n))
60 OBJS-  := $(call src2obj,$(SRCS-))
61 OBJS-all := $(filter-out $(SRCS-all),$(OBJS-y) $(OBJS-n) $(OBJS-))
62
63 DEPS-y := $(call src2dep,$(SRCS-y))
64 DEPS-n := $(call src2dep,$(SRCS-n))
65 DEPS-  := $(call src2dep,$(SRCS-))
66 DEPS-all := $(DEPS-y) $(DEPS-n) $(DEPS-)
67 DEPSTMP-all := $(DEPS-all:%.d=%.d.tmp)
68
69 CMDS-y := $(call src2cmd,$(SRCS-y))
70 CMDS-n := $(call src2cmd,$(SRCS-n))
71 CMDS-  := $(call src2cmd,$(SRCS-))
72 CMDS-all := $(CMDS-y) $(CMDS-n) $(CMDS-)
73
74 -include $(DEPS-y) $(CMDS-y)
75
76 # command to compile a .c file to generate an object
77 ifeq ($(USE_HOST),1)
78 C_TO_O = $(HOSTCC) -Wp,-MD,$(call obj2dep,$(@)).tmp $(HOST_CFLAGS) \
79         $(CFLAGS_$(@)) $(HOST_EXTRA_CFLAGS) -o $@ -c $<
80 C_TO_O_STR = $(subst ','\'',$(C_TO_O)) #'# fix syntax highlight
81 C_TO_O_DISP = $(if $(V),"$(C_TO_O_STR)","  HOSTCC $(@)")
82 else
83 C_TO_O = $(CC) -Wp,-MD,$(call obj2dep,$(@)).tmp $(CFLAGS) \
84         $(CFLAGS_$(@)) $(EXTRA_CFLAGS) -o $@ -c $<
85 C_TO_O_STR = $(subst ','\'',$(C_TO_O)) #'# fix syntax highlight
86 C_TO_O_DISP = $(if $(V),"$(C_TO_O_STR)","  CC $(@)")
87 endif
88 C_TO_O_CMD = "cmd_$@ = $(C_TO_O_STR)"
89 C_TO_O_DO = @set -e; \
90         echo $(C_TO_O_DISP); \
91         $(C_TO_O) && \
92         echo $(C_TO_O_CMD) > $(call obj2cmd,$(@)) && \
93         sed 's,'$@':,dep_'$@' =,' $(call obj2dep,$(@)).tmp > $(call obj2dep,$(@)) && \
94         rm -f $(call obj2dep,$(@)).tmp
95
96 # return an empty string if string are equal
97 compare = $(strip $(subst $(1),,$(2)) $(subst $(2),,$(1)))
98
99 # return a non-empty string if the dst file does not exist
100 file_missing = $(call compare,$(wildcard $@),$@)
101
102 # return a non-empty string if cmdline changed
103 cmdline_changed = $(call compare,$(cmd_$@),$(1))
104
105 # return a non-empty string if a dependency file does not exist
106 depfile_missing = $(call compare,$(wildcard $(dep_$@)),$(dep_$@))
107
108 # return an empty string if no prereq is newer than target
109 #     - $^ -> names of all the prerequisites
110 #     - $(wildcard $^) -> every existing prereq
111 #     - $(filter-out $(wildcard $^),$^) -> every prereq that don't
112 #       exist (filter-out removes existing ones from the list)
113 #     - $? -> names of all the prerequisites newer than target
114 depfile_newer = $(strip $(filter-out FORCE,$? \
115         $(filter-out $(wildcard $^),$^)))
116
117 # return 1 if parameter is a non-empty string, else 0
118 boolean = $(if $1,1,0)
119
120 #
121 # Compile .c file if needed
122 # Note: dep_$$@ is from the .d file and DEP_$$@ can be specified by
123 # user (by default it is empty)
124 #
125 .SECONDEXPANSION:
126 %.o: %.c $$(wildcard $$(dep_$$@)) $$(DEP_$$(@)) FORCE
127         @[ -d $(dir $@) ] || mkdir -p $(dir $@)
128         $(if $(D),\
129                 @echo -n "$< -> $@ " ; \
130                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
131                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(C_TO_O_STR))) " ; \
132                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
133                 echo "depfile_newer=$(call boolean,$(depfile_newer))")
134         $(if $(or \
135                 $(file_missing),\
136                 $(call cmdline_changed,$(C_TO_O_STR)),\
137                 $(depfile_missing),\
138                 $(depfile_newer)),\
139                 $(C_TO_O_DO))
140
141 # command to assemble a .S file to generate an object
142 ifeq ($(USE_HOST),1)
143 S_TO_O = $(CPP) $(HOST_CPPFLAGS) $($(@)_CPPFLAGS) $(HOST_EXTRA_CPPFLAGS) $< $(@).tmp && \
144         $(HOSTAS) $(HOST_ASFLAGS) $($(@)_ASFLAGS) $(HOST_EXTRA_ASFLAGS) -o $@ $(@).tmp
145 S_TO_O_STR = $(subst ','\'',$(S_TO_O)) #'# fix syntax highlight
146 S_TO_O_DISP =  $(if $(V),"$(S_TO_O_STR)","  HOSTAS $(@)")
147 else
148 S_TO_O = $(CPP) $(CPPFLAGS) $($(@)_CPPFLAGS) $(EXTRA_CPPFLAGS) $< -o $(@).tmp && \
149         $(AS) $(ASFLAGS) $($(@)_ASFLAGS) $(EXTRA_ASFLAGS) -o $@ $(@).tmp
150 S_TO_O_STR = $(subst ','\'',$(S_TO_O)) #'# fix syntax highlight
151 S_TO_O_DISP =  $(if $(V),"$(S_TO_O_STR)","  AS $(@)")
152 endif
153
154 S_TO_O_CMD = "cmd_$@ = $(S_TO_O_STR)"
155 S_TO_O_DO = @set -e; \
156         echo $(S_TO_O_DISP); \
157         $(S_TO_O) && \
158         echo $(S_TO_O_CMD) > $(call obj2cmd,$(@))
159
160 #
161 # Compile .S file if needed
162 # Note: DEP_$$@ can be specified by user (by default it is empty)
163 #
164 %_s.o: %.S $$(DEP_$$@) FORCE
165         @[ ! -d $(dir $@) ] || mkdir -p $(dir $@)
166         $(if $(D),\
167                 @echo -n "$< -> $@ " ; \
168                 echo -n "file_missing=$(call boolean,$(file_missing)) " ; \
169                 echo -n "cmdline_changed=$(call boolean,$(call cmdline_changed,$(S_TO_O_STR))) " ; \
170                 echo -n "depfile_missing=$(call boolean,$(depfile_missing)) " ; \
171                 echo "depfile_newer=$(call boolean,$(depfile_newer)) ")
172         $(if $(or \
173                 $(file_missing),\
174                 $(call cmdline_changed,$(S_TO_O_STR)),\
175                 $(depfile_missing),\
176                 $(depfile_newer)),\
177                 $(S_TO_O_DO))