blob: 97dfd467d9e5fae24dc7bbcd1eb3704124bd6943 [file] [log] [blame]
Matthias Andreas Benkardf59e0972018-04-10 22:01:34 +02001# Copyright 2015 Andrew Gottemoller.
2#
3# This software is a copyrighted work licensed under the terms of the
4# Weld license. Please consult the file "WELD_LICENSE" for
5# details.
6
7# This makefile defines the set of rules for a header list
8
9
10# This makefile is included for each component definition so clear out
11# any variables used by this makefile
12c_toolchain_path :=
13def_source_path :=
14def_obj_output_path :=
15source_file :=
16source_name :=
17def_source_file :=
18obj_alias :=
19obj_goal_list :=
20obj_goal_file_list :=
21compile_goal :=
22compile_goal_path :=
23full_compile_goal_path :=
24
25
26c_toolchain_path := $(weld_path)/toolchain/gcc
27def_source_path := $(def_path)/$(def_source_subdir)
28def_obj_output_path := $(obj_output_path)/$(name)
29
30
31# Add the weld project's lib and header paths to the specified lib
32# and include path lists
33lib_path_list := $(lib_output_path) $(global_lib_path_list) $(lib_path_list)
34include_path_list := $(header_output_path) $(global_include_path_list) $(include_path_list)
35
36# Add the global definition list to the component definition's list
37definition_list := $(global_definition_list) $(definition_list)
38
39# Specify a default set of compiler flags in addition to those
40# flags specified by the component definition
41compiler_flag_list := -g \
42 -fstrict-aliasing \
43 -funsigned-char \
44 -Wall \
45 -Winline \
46 -Wmissing-field-initializers \
47 -Wsign-compare \
48 -Wstrict-aliasing=1 \
49 -pedantic \
50 $(global_compiler_flag_list) \
51 $(compiler_flag_list)
52
53# Add the global link flags to the component definition's list
54link_flag_list := $(global_link_flag_list) $(link_flag_list)
55
56# Include settings for the specified language, platform, mode, and
57# architecture
58include $(c_toolchain_path)/lang/$(lang).mk
59include $(c_toolchain_path)/platform/$(platform).mk
60include $(c_toolchain_path)/mode/$(mode).mk
61include $(c_toolchain_path)/arch/$(arch).mk
62
63define source_file_rule
64
65 $(call debug_info,source specified: $(1))
66
67 source_file := $(1)
68 source_name := $$(notdir $(1))
69 def_source_file := $$(def_source_path)/$$(source_file)
70 obj_alias := $$(name)/$$(basename $$(source_name)).o
71
72 obj_goal_list := $$(obj_alias) $$(obj_goal_list)
73
74 # Define an alias for the object file so the user can do
75 # "make name/foo.o" on the command line
76 vpath $$(obj_alias) $$(obj_output_path)
77
78 # Try to include the object's dependency file generated by
79 # a previous compile
80 -include $$(obj_output_path)/$$(obj_alias).d
81
82 # Set the target specific variables and dependencies for this
83 # object
84 $$(obj_alias) : def_source_file := $$(def_source_file)
85 $$(obj_alias) : obj_alias := $$(obj_alias)
86 $$(obj_alias) : $$(def_deps)
87 $$(obj_alias) : $$(def_source_file)
88
89endef
90
91
92# Expand the source file rule for each source specified
93$(foreach file,$(source_list),$(eval $(call source_file_rule,$(file))))
94
95obj_goal_file_list := $(addprefix $(obj_output_path)/,$(obj_goal_list))
96source_lib_file_list := $(addsuffix .a,$(addprefix lib,$(source_lib_list)))
97full_compile_goal_path := $(dir $(compile_goal_path)/$(compile_goal))
98
99
100# Add the necessary output directories to the list of directories to create
101directory_list := $(def_obj_output_path) $(full_compile_goal_path) $(directory_list)
102
103
104# Create aliases for the compile goal and library names
105vpath %.a $(lib_path_list)
106vpath $(compile_goal) $(compile_goal_path)
107
108# Add the component's compile goal as a dependency to this component's
109# compile target
110$(name)_def_compile : $(compile_goal)
111
112# The actual recipe for an object file
113$(obj_goal_list) : compile_command := $(compile_command)
114$(obj_goal_list) : obj_output_path := $(obj_output_path)
115$(obj_goal_list) : include_path_list := $(include_path_list)
116$(obj_goal_list) : definition_list := $(definition_list)
117$(obj_goal_list) : compiler_flag_list := $(compiler_flag_list)
118$(obj_goal_list) : | headers
119$(obj_goal_list) : | $(def_obj_output_path)
120$(obj_goal_list) :
121 $(call print_progress,$(obj_alias))
122 $(strip \
123 $(compile_command) -o $(call path_to_native,$(obj_output_path)/$(obj_alias)) \
124 -MD -MP -MF $(call path_to_native,$(obj_output_path)/$(obj_alias).d) -MQ $(obj_alias) \
125 $(compiler_flag_list) \
126 $(addprefix -I,$(call path_to_native,$(include_path_list))) \
127 $(addprefix -D,$(definition_list)) \
128 -c $(call path_to_native,$(def_source_file)))
129
130# The actual recipe for linking a library or binary
131$(compile_goal) : compile_command := $(compile_command)
132$(compile_goal) : link_flag_list := $(link_flag_list)
133$(compile_goal) : compile_goal := $(compile_goal)
134$(compile_goal) : compile_goal_path := $(compile_goal_path)
135$(compile_goal) : obj_goal_file_list := $(obj_goal_file_list)
136$(compile_goal) : lib_path_list := $(lib_path_list)
137$(compile_goal) : lib_list := $(lib_list)
138$(compile_goal) : static_lib_list := $(static_lib_list)
139$(compile_goal) : source_lib_list := $(source_lib_list)
140$(compile_goal) : $(obj_goal_list)
141$(compile_goal) : $(source_lib_file_list)
142$(compile_goal) : | $(full_compile_goal_path)
143$(compile_goal) :
144 $(call print_progress,$(compile_goal))
145 ifeq ($(type), lib)
146 $(call remove_files,$(call path_to_native,$(compile_goal_path)/$(compile_goal)))
147 $(strip \
148 ar rcs \
149 $(link_flag_list) \
150 $(call path_to_native,$(compile_goal_path)/$(compile_goal)) \
151 $(call path_to_native,$(obj_goal_file_list)))
152 else
153 $(strip \
154 $(compile_command) -o $(call path_to_native,$(compile_goal_path)/$(compile_goal)) \
155 $(link_flag_list) \
156 $(addprefix -L,$(call path_to_native,$(lib_path_list))) \
157 $(call path_to_native,$(obj_goal_file_list)) \
158 -Wl,--start-group \
159 $(addprefix -l,$(lib_list) $(source_lib_list)) \
160 $(addsuffix .a,$(addprefix -l:lib,$(static_lib_list))) \
161 -Wl,--end-group)
162 endif
163
164.PHONY : clean_$(name)_def_compile
165clean_$(name)_def_compile : def_obj_output_path := $(def_obj_output_path)
166clean_$(name)_def_compile : compile_goal := $(compile_goal)
167clean_$(name)_def_compile : compile_goal_path := $(compile_goal_path)
168clean_$(name)_def_compile :
169 $(call print_progress,$@)
170 $(call remove_files,$(def_obj_output_path)/*.o)
171 $(call remove_files,$(def_obj_output_path)/*.o.*)
172 $(call remove_files,$(compile_goal_path)/$(compile_goal))