Skip to content

Commit

Permalink
Fix fatal error: math.h no such file or directory
Browse files Browse the repository at this point in the history
This fixes #3016 by conditionally adding llvm include directories
in a loop.
  • Loading branch information
winksaville committed Feb 23, 2019
1 parent 66c3947 commit e613e09
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion Makefile-ponyc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,47 @@ endif
# (3) a list of include directories for a set of libraries
# (4) a list of the libraries to link against
llvm.ldflags := -L$(CROSS_SYSROOT)$(subst -L,,$(shell $(LLVM_CONFIG) --ldflags $(LLVM_LINK_STATIC)))
llvm.include := $(CROSS_SYSROOT)$(shell sh -c "$(LLVM_CONFIG) --cflags $(LLVM_LINK_STATIC) | grep -oE -- '(^| )-I\s*\S+' | sed 's/^\s*-I\s*/-isystem /g'")

# Get cflags using llvm-config
llvm.get_cflags := $(LLVM_CONFIG) --cflags $(LLVM_LINK_STATIC)
llvm.cflags := $(shell sh -c "$(llvm.get_cflags)")

#Used for testing
#llvm.cflags := -I/usr/include -march=x86-64 -I /sec/time -I /usr/local/include -I /3/4 -mtune=generic -O2 -pipe -fstack-protector-strong -fno-plt -fPIC -Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -pedantic -Wno-long-long -Wno-comment -fdiagnostics-color -ffunction-sections -fdata-sections -O3 -DNDEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/xyz/abc

# Get include dirs using grep & sed to extract "-I x/xx" entries
llvm.get_include_dirs := "echo '$(llvm.cflags)' | grep -oE -- '(^| )-I\s*\S+' | sed 's/^\s*-I\s*//'"
llvm.include_dirs := $(shell sh -c $(llvm.get_include_dirs))

# Get the compiler output of verbose "-v" and preprocess, "-E" parameters which
# contains the search paths.
verbose_preprocess_string := $(shell echo | $(CC) -v -E - 2>&1)

# We must escape any double quotes, ", and any hash, #, characters.
quoteDblQuote := $(subst ",\",$(verbose_preprocess_string))
quoted_verbose_preprocess_string := $(subst \#,\\\#,$(quoteDblQuote))

# Now use a sed command line to extract the search paths from the
# quoted verbose preprocess string
get_search_paths := sed 's/\(.*\)search starts here:\(.*\)End of search list.\(.*\)/\2/'
search_paths := $(shell echo "$(quoted_verbose_preprocess_string)" | $(get_search_paths))

# Note: $(search_paths) is padded with a space on front and back so
# that when we iterate the ${inc_dir} variable is guaranteed to have
# a space at the beginning and end making finding a match easy. If
# there is no match we output the ${inc_dir}.
loopit := \
for inc_dir in $(llvm.include_dirs); do \
if [[ " $(search_paths) " != *" $${inc_dir} "* ]]; then \
echo "-isystem $(CROSS_SYSROOT)$${inc_dir}"; \
fi \
done

llvm.include = $(shell $(loopit))

#.PHONY: done
#done:

llvm.libs := $(shell $(LLVM_CONFIG) --libs $(LLVM_LINK_STATIC)) -lz -lncurses

ifeq ($(OSTYPE), bsd)
Expand Down

0 comments on commit e613e09

Please sign in to comment.