git subrepo clone https://github.com/agottem/weld.git weld

subrepo:
  subdir:   "weld"
  merged:   "d0cd07b"
upstream:
  origin:   "https://github.com/agottem/weld.git"
  branch:   "master"
  commit:   "d0cd07b"
git-subrepo:
  version:  "0.3.1"
  origin:   "???"
  commit:   "???"

Change-Id: I109553651e97fd93e00aa555d171ca9d04ce8585
diff --git a/weld/toolchain/gcc/arch/amd64.mk b/weld/toolchain/gcc/arch/amd64.mk
new file mode 100644
index 0000000..8b4b0d1
--- /dev/null
+++ b/weld/toolchain/gcc/arch/amd64.mk
@@ -0,0 +1,10 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the amd64 architecture
+
+
+compiler_flag_list := -march=x86-64 $(compiler_flag_list)
diff --git a/weld/toolchain/gcc/arch/i686.mk b/weld/toolchain/gcc/arch/i686.mk
new file mode 100644
index 0000000..d71e78e
--- /dev/null
+++ b/weld/toolchain/gcc/arch/i686.mk
@@ -0,0 +1,10 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the i686 architecture
+
+
+compiler_flag_list := -march=i686 $(compiler_flag_list)
diff --git a/weld/toolchain/gcc/compile.mk b/weld/toolchain/gcc/compile.mk
new file mode 100644
index 0000000..97dfd46
--- /dev/null
+++ b/weld/toolchain/gcc/compile.mk
@@ -0,0 +1,172 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines the set of rules for a header list
+
+
+# This makefile is included for each component definition so clear out
+# any variables used by this makefile
+c_toolchain_path       :=
+def_source_path        :=
+def_obj_output_path    :=
+source_file            :=
+source_name            :=
+def_source_file        :=
+obj_alias              :=
+obj_goal_list          :=
+obj_goal_file_list     :=
+compile_goal           :=
+compile_goal_path      :=
+full_compile_goal_path :=
+
+
+c_toolchain_path    := $(weld_path)/toolchain/gcc
+def_source_path     := $(def_path)/$(def_source_subdir)
+def_obj_output_path := $(obj_output_path)/$(name)
+
+
+# Add the weld project's lib and header paths to the specified lib
+# and include path lists
+lib_path_list     := $(lib_output_path) $(global_lib_path_list) $(lib_path_list)
+include_path_list := $(header_output_path) $(global_include_path_list) $(include_path_list)
+
+# Add the global definition list to the component definition's list
+definition_list := $(global_definition_list) $(definition_list)
+
+# Specify a default set of compiler flags in addition to those
+# flags specified by the component definition
+compiler_flag_list := -g                              \
+                      -fstrict-aliasing               \
+                      -funsigned-char                 \
+                      -Wall                           \
+                      -Winline                        \
+                      -Wmissing-field-initializers    \
+                      -Wsign-compare                  \
+                      -Wstrict-aliasing=1             \
+                      -pedantic                       \
+                      $(global_compiler_flag_list)    \
+                      $(compiler_flag_list)
+
+# Add the global link flags to the component definition's list
+link_flag_list := $(global_link_flag_list) $(link_flag_list)
+
+# Include settings for the specified language, platform, mode, and
+# architecture
+include $(c_toolchain_path)/lang/$(lang).mk
+include $(c_toolchain_path)/platform/$(platform).mk
+include $(c_toolchain_path)/mode/$(mode).mk
+include $(c_toolchain_path)/arch/$(arch).mk
+
+define source_file_rule
+
+    $(call debug_info,source specified: $(1))
+
+    source_file     := $(1)
+    source_name     := $$(notdir $(1))
+    def_source_file := $$(def_source_path)/$$(source_file)
+    obj_alias       := $$(name)/$$(basename $$(source_name)).o
+
+    obj_goal_list := $$(obj_alias) $$(obj_goal_list)
+
+    # Define an alias for the object file so the user can do
+    # "make name/foo.o" on the command line
+    vpath $$(obj_alias) $$(obj_output_path)
+
+    # Try to include the object's dependency file generated by
+    # a previous compile
+    -include $$(obj_output_path)/$$(obj_alias).d
+
+    # Set the target specific variables and dependencies for this
+    # object
+    $$(obj_alias) : def_source_file := $$(def_source_file)
+    $$(obj_alias) : obj_alias       := $$(obj_alias)
+    $$(obj_alias) : $$(def_deps)
+    $$(obj_alias) : $$(def_source_file)
+
+endef
+
+
+# Expand the source file rule for each source specified
+$(foreach file,$(source_list),$(eval $(call source_file_rule,$(file))))
+
+obj_goal_file_list     := $(addprefix $(obj_output_path)/,$(obj_goal_list))
+source_lib_file_list   := $(addsuffix .a,$(addprefix lib,$(source_lib_list)))
+full_compile_goal_path := $(dir $(compile_goal_path)/$(compile_goal))
+
+
+# Add the necessary output directories to the list of directories to create
+directory_list := $(def_obj_output_path) $(full_compile_goal_path) $(directory_list)
+
+
+# Create aliases for the compile goal and library names
+vpath %.a             $(lib_path_list)
+vpath $(compile_goal) $(compile_goal_path)
+
+# Add the component's compile goal as a dependency to this component's
+# compile target
+$(name)_def_compile : $(compile_goal)
+
+# The actual recipe for an object file
+$(obj_goal_list) : compile_command    := $(compile_command)
+$(obj_goal_list) : obj_output_path    := $(obj_output_path)
+$(obj_goal_list) : include_path_list  := $(include_path_list)
+$(obj_goal_list) : definition_list    := $(definition_list)
+$(obj_goal_list) : compiler_flag_list := $(compiler_flag_list)
+$(obj_goal_list) : | headers
+$(obj_goal_list) : | $(def_obj_output_path)
+$(obj_goal_list) :
+	$(call print_progress,$(obj_alias))
+	$(strip                                                                                       \
+        $(compile_command) -o $(call path_to_native,$(obj_output_path)/$(obj_alias))              \
+            -MD -MP -MF $(call path_to_native,$(obj_output_path)/$(obj_alias).d) -MQ $(obj_alias) \
+            $(compiler_flag_list)                                                                 \
+            $(addprefix -I,$(call path_to_native,$(include_path_list)))                           \
+            $(addprefix -D,$(definition_list))                                                    \
+            -c $(call path_to_native,$(def_source_file)))
+
+# The actual recipe for linking a library or binary
+$(compile_goal) : compile_command    := $(compile_command)
+$(compile_goal) : link_flag_list     := $(link_flag_list)
+$(compile_goal) : compile_goal       := $(compile_goal)
+$(compile_goal) : compile_goal_path  := $(compile_goal_path)
+$(compile_goal) : obj_goal_file_list := $(obj_goal_file_list)
+$(compile_goal) : lib_path_list      := $(lib_path_list)
+$(compile_goal) : lib_list           := $(lib_list)
+$(compile_goal) : static_lib_list    := $(static_lib_list)
+$(compile_goal) : source_lib_list    := $(source_lib_list)
+$(compile_goal) : $(obj_goal_list)
+$(compile_goal) : $(source_lib_file_list)
+$(compile_goal) : | $(full_compile_goal_path)
+$(compile_goal) :
+	$(call print_progress,$(compile_goal))
+    ifeq ($(type), lib)
+	    $(call remove_files,$(call path_to_native,$(compile_goal_path)/$(compile_goal)))
+	    $(strip                                                             \
+            ar rcs                                                          \
+                $(link_flag_list)                                           \
+                $(call path_to_native,$(compile_goal_path)/$(compile_goal)) \
+                $(call path_to_native,$(obj_goal_file_list)))
+    else
+	    $(strip                                                                                   \
+            $(compile_command) -o $(call path_to_native,$(compile_goal_path)/$(compile_goal))     \
+                $(link_flag_list)                                                                 \
+                $(addprefix -L,$(call path_to_native,$(lib_path_list)))                           \
+                $(call path_to_native,$(obj_goal_file_list))                                      \
+                -Wl,--start-group                                                                 \
+                $(addprefix -l,$(lib_list) $(source_lib_list))                                    \
+                $(addsuffix .a,$(addprefix -l:lib,$(static_lib_list)))                            \
+                -Wl,--end-group)
+    endif
+
+.PHONY : clean_$(name)_def_compile
+clean_$(name)_def_compile : def_obj_output_path := $(def_obj_output_path)
+clean_$(name)_def_compile : compile_goal        := $(compile_goal)
+clean_$(name)_def_compile : compile_goal_path   := $(compile_goal_path)
+clean_$(name)_def_compile :
+	$(call print_progress,$@)
+	$(call remove_files,$(def_obj_output_path)/*.o)
+	$(call remove_files,$(def_obj_output_path)/*.o.*)
+	$(call remove_files,$(compile_goal_path)/$(compile_goal))
diff --git a/weld/toolchain/gcc/lang/c.mk b/weld/toolchain/gcc/lang/c.mk
new file mode 100644
index 0000000..94c07ac
--- /dev/null
+++ b/weld/toolchain/gcc/lang/c.mk
@@ -0,0 +1,12 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the c language
+
+
+compile_command := $(if $(gcc_opt_use_clang),clang,gcc)
+
+compiler_flag_list := -std=c99 $(compiler_flag_list)
diff --git a/weld/toolchain/gcc/lang/cpp.mk b/weld/toolchain/gcc/lang/cpp.mk
new file mode 100644
index 0000000..4a84a12
--- /dev/null
+++ b/weld/toolchain/gcc/lang/cpp.mk
@@ -0,0 +1,12 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the cpp language
+
+
+compile_command := $(if $(gcc_opt_use_clang),clang++,g++)
+
+compiler_flag_list := -std=c++11 $(compiler_flag_list)
diff --git a/weld/toolchain/gcc/mode/debug.mk b/weld/toolchain/gcc/mode/debug.mk
new file mode 100644
index 0000000..988072c
--- /dev/null
+++ b/weld/toolchain/gcc/mode/debug.mk
@@ -0,0 +1,10 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for debug mode
+
+
+compiler_flag_list := -O0 -fno-inline-functions $(compiler_flag_list)
diff --git a/weld/toolchain/gcc/mode/release.mk b/weld/toolchain/gcc/mode/release.mk
new file mode 100644
index 0000000..09aa392
--- /dev/null
+++ b/weld/toolchain/gcc/mode/release.mk
@@ -0,0 +1,14 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for release mode
+
+
+compiler_flag_list := -O3 $(compiler_flag_list)
+
+ifeq ($(type), bin)
+    link_flag_list := -Wl,-O,1 $(link_flag_list)
+endif
diff --git a/weld/toolchain/gcc/platform/unix.mk b/weld/toolchain/gcc/platform/unix.mk
new file mode 100644
index 0000000..387529a
--- /dev/null
+++ b/weld/toolchain/gcc/platform/unix.mk
@@ -0,0 +1,22 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the unix platform (linux, bsd, etc)
+
+
+ifeq ($(type), bin)
+    compile_goal      := $(patsubst $(output_path)/%,%,$(bin_output_path))/$(name)
+    compile_goal_path := $(output_path)
+else
+    compile_goal      := lib$(name).a
+    compile_goal_path := $(lib_output_path)
+endif
+
+ifeq ($(unix_flavor), bsd)
+    definition_list := _BSD_SOURCE $(definition_list)
+else ifeq ($(unix_flavor), linux)
+    definition_list := _DEFAULT_SOURCE $(definition_list)
+endif
diff --git a/weld/toolchain/gcc/platform/win32.mk b/weld/toolchain/gcc/platform/win32.mk
new file mode 100644
index 0000000..06a12e3
--- /dev/null
+++ b/weld/toolchain/gcc/platform/win32.mk
@@ -0,0 +1,26 @@
+# Copyright 2015 Andrew Gottemoller.
+#
+# This software is a copyrighted work licensed under the terms of the
+# Weld license.  Please consult the file "WELD_LICENSE" for
+# details.
+
+# This makefile defines settings for the windows platform
+
+
+ifeq ($(type), bin)
+    compile_goal      := $(patsubst $(output_path)/%,%,$(bin_output_path))/$(name).exe
+    compile_goal_path := $(output_path)
+
+    link_flag_list := -mwindows $(link_flag_list)
+else
+    compile_goal      := lib$(name).a
+    compile_goal_path := $(lib_output_path)
+endif
+
+definition_list := WIN32                 \
+                   UNICODE               \
+                   WINVER=0x0400         \
+                   _WIN32_WINNT=0x0400   \
+                   _WIN32_WINDOWS=0x0400 \
+                   _WIN32_IE=0x0500      \
+                   $(definition_list)