Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make: use -M to generate dependencies #980

Merged
merged 5 commits into from
Jun 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Tools/GNUMake/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,8 @@ CHECKFORT = $(AMREX_HOME)/Tools/typechecker/typechecker.py
MKCONFIG = $(AMREX_HOME)/Tools/libamrex/mkconfig.py
MKPKGCONFIG = $(AMREX_HOME)/Tools/libamrex/mkpkgconfig.py

DEPFLAGS = -M

RANLIB = ranlib

EXE_OUTPUT_OPTION = -o $(objEXETempDir)/$*.o
Expand Down
67 changes: 38 additions & 29 deletions Tools/GNUMake/Make.rules
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ else
endif
endif

CXXDEPFLAGS = $(DEPFLAGS) $(filter-out -dc,$(CXXFLAGS)) $(CPPFLAGS) $(includes)
CDEPFLAGS = $(DEPFLAGS) $(filter-out -dc,$(CFLAGS)) -DBL_LANG_C -DAMREX_LANG_C $(CPPFLAGS) $(includes)

#
# Rules for building executable.
#
Expand Down Expand Up @@ -287,12 +290,38 @@ endif
# Rules for dependencies in bare object files.
#

$(depEXETempDir)/%.d: %.cpp
@echo Depending $< ...
ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
endif
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
ifeq ($(USE_DPCPP),TRUE)
$(CXX) $(CXXDEPFLAGS) $< -o $@
else
$(CXX) $(CXXDEPFLAGS) $< > $@
endif
@$(SHELL) -ec 'sed -i -e '\''s,$*\.o,$(objEXETempDir)/& $@,g'\'' $@'

$(depEXETempDir)/%.d: %.c
@echo Depending $< ...
ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
endif
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
ifeq ($(USE_DPCPP),TRUE)
$(CC) $(CDEPFLAGS) $< -o $@
else
$(CC) $(CDEPFLAGS) $< > $@
endif
@$(SHELL) -ec 'sed -i -e '\''s,$*\.o,$(objEXETempDir)/& $@,g'\'' $@'

#
# The sed foo below:
#
# First it starts a shell that runs `$MKDEP` command on `$<`, the
# first prerequisite of make rule, say `/path/to/y.H`. The output
# of `$MKDEP` are lines like `/path/to/x.o: /path/to/y.H`.
# first prerequisite of make rule, say `/path/to/y.cpp`. The output
# of `$MKDEP` are lines like `/path/to/x.o: /path/to/y.cpp`.
#
# It is then piped into two `sed` commands and then into the target
# (i.e., `$(depEXETempDir)/x.d`). We need sed to modify the output
Expand All @@ -301,57 +330,37 @@ endif
#
# The command of `sed` needs to be inside a pair of `'`s. But the
# whole `sed -e '......'` is already inside a pair of `'`s for the
# shell. So we have to use escape, thus `'\''mycommand'\''`.
# shell. So we have to use escape, thus `'\''mycommand'\''`.
#
# The sed command is search and replace, `s,X,Y` that replaces `X` by
# `Y`.
# `Y`.
#
# In the first sed, `X` is `^[^:]*\/`. This matches the beginning
# of the line to the last `/` before `:`. The `Y` contains nothing.
# So the matched string is removed, and the line becomes `x.o: /path/to/x.xpp`.
# So the matched string is removed, and the line becomes `x.o: /path/to/x.xpp`.
#
# In the second sed, we replace `x.o` with `$(objEXETempDir)/o`. Note
# that `$*` is make variable set to `%` (i.e., `x` in our example).
# `&` is sed variable meaning the whole matched string. The
# replacement string also includes the target of the make rule (i.e.,
# `$(depEXETempDir)/x.d`).
# `$(depEXETempDir)/x.d`).
#
# The final result is `$(objEXETempDir)/x.o $(depEXETempDir)/x.d: /path/to/y.H`.
# The final result is `$(objEXETempDir)/x.o $(depEXETempDir)/x.d: /path/to/y.cpp`.
#

$(depEXETempDir)/%.d: %.cpp
@echo Depending $< ...
ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
endif
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
@$(SHELL) -ec '$(MKDEP) $(includes) $< | \
sed -e '\''s,^[^:]*\/,,'\'' | \
sed -e '\''s,$*.o,$(objEXETempDir)/& $@,'\'' > $@'

$(depEXETempDir)/%.d: %.c
@echo Depending $< ...
ifeq ($(USE_GPU_PRAGMA),TRUE)
@if [ ! -d $(srcTempDir) ]; then mkdir -p $(srcTempDir); fi
endif
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
@$(SHELL) -ec '$(MKDEP) $(includes) $< | \
sed -e '\''s,^[^:]*\/,,'\'' | \
sed -e '\''s,$*.o,$(objEXETempDir)/& $@,'\'' > $@'

$(depEXETempDir)/%.d: %.F
@echo Depending $< ...
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
@$(SHELL) -ec '$(MKDEP) -fortran $(fincludes) $< | \
sed -e '\''s,^[^:]*\/,,'\'' | \
sed -e '\''s,$*.o,$(objEXETempDir)/& $@,'\'' > $@'
sed -e '\''s,$*\.o,$(objEXETempDir)/& $@,'\'' > $@'

$(depEXETempDir)/%.d: %.f
@echo Depending $< ...
@if [ ! -d $(depEXETempDir) ]; then mkdir -p $(depEXETempDir); fi
@$(SHELL) -ec '$(MKDEP) -fortran $(fincludes) $< | \
sed -e '\''s,^[^:]*\/,,'\'' | \
sed -e '\''s,$*.o,$(objEXETempDir)/& $@,'\'' > $@'
sed -e '\''s,$*\.o,$(objEXETempDir)/& $@,'\'' > $@'

DEP_CHECK_OPTS :=

Expand Down
4 changes: 2 additions & 2 deletions Tools/GNUMake/comps/cray.mak
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ else
# CCE <= 8. So we adjust some flags to achieve similar optimization. See
# this page:
# http://pubs.cray.com/content/S-5212/9.0/cray-compiling-environment-cce-release-overview/cce-900-software-enhancements
CXXFLAGS += -O2 -ffast-math -fsave-loopmark -fsave-decompile
CFLAGS += -O2 -ffast-math -fsave-loopmark -fsave-decompile
CXXFLAGS += -O2 -ffast-math #-fsave-loopmark -fsave-decompile
CFLAGS += -O2 -ffast-math #-fsave-loopmark -fsave-decompile
FFLAGS += -O2 -h list=a
F90FLAGS += -O2 -h list=a
else
Expand Down
2 changes: 1 addition & 1 deletion Tools/GNUMake/comps/nvcc.mak
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ ifeq ($(lowercase_nvcc_host_comp),gnu)

NVCC_CCBIN ?= g++

CXXFLAGS_FROM_HOST := -ccbin=$(NVCC_CCBIN) -Xcompiler='$(CXXFLAGS) --std=$(CXXSTD)' --std=$(CXXSTD)
CXXFLAGS_FROM_HOST := -ccbin=$(NVCC_CCBIN) -Xcompiler='$(CXXFLAGS)' --std=$(CXXSTD)
CFLAGS_FROM_HOST := $(CXXFLAGS_FROM_HOST)
ifeq ($(USE_OMP),TRUE)
LIBRARIES += -lgomp
Expand Down