Skip to content

Commit

Permalink
More ARG_MAX hack cleanups to Makefile.
Browse files Browse the repository at this point in the history
Details:
- Disabled the previous rule for shared library linking (based on
  "sleep 3") in favor of the backup rule based on $(AR_OBJ_LIST_FILE).
- Moved the creation of $(AR_OBJ_LIST_FILE) to a separate rule and added
  it as a prerequisite to the relevant rules (which also necessitated
  that those rules no longer use the automatic variable $^). Also
  reduced the value of $(AR_CHUCK_SIZE) to 256. This tweaked Makefile
  should still work on all systems on which it worked before.
- Whitespace changes, mostly in the form of removing trailing spaces.
  • Loading branch information
fgvanzee committed Jul 22, 2018
1 parent c37b349 commit d2c48fd
Showing 1 changed file with 71 additions and 53 deletions.
124 changes: 71 additions & 53 deletions Makefile
Expand Up @@ -3,7 +3,7 @@
# Makefile
#
# Field G. Van Zee
#
#
# Top-level makefile for libflame linear algebra library.
#
#
Expand Down Expand Up @@ -89,18 +89,18 @@ ALL_FLAMEC_DLL_NAME := libflame.so
MK_ALL_FLAMEC_LIB := $(BASE_LIB_DIR)/$(ALL_FLAMEC_LIB_NAME)
MK_ALL_FLAMEC_DLL := $(BASE_LIB_DIR)/$(ALL_FLAMEC_DLL_NAME)

MK_BASE_FLAMEC_SRC :=
MK_BASE_FLAMEC_OBJS :=
MK_BASE_FLAMEC_SRC :=
MK_BASE_FLAMEC_OBJS :=

MK_BLAS_FLAMEC_SRC :=
MK_BLAS_FLAMEC_OBJS :=
MK_BLAS_FLAMEC_SRC :=
MK_BLAS_FLAMEC_OBJS :=

MK_LAPACK_FLAMEC_SRC :=
MK_LAPACK_FLAMEC_OBJS :=
MK_LAPACK_FLAMEC_SRC :=
MK_LAPACK_FLAMEC_OBJS :=


MK_MAP_LAPACK2FLAMEC_SRC :=
MK_MAP_LAPACK2FLAMEC_OBJS :=
MK_MAP_LAPACK2FLAMEC_SRC :=
MK_MAP_LAPACK2FLAMEC_OBJS :=

MK_MAP_LAPACK2FLAMEC_F2C_SRC :=
MK_MAP_LAPACK2FLAMEC_F2C_OBJS :=
Expand All @@ -111,8 +111,8 @@ MK_MAP_LAPACK2FLAMEC_F2C_FLAMEC_OBJS :=
MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_SRC :=
MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS :=

MK_FLABLAS_F2C_SRC :=
MK_FLABLAS_F2C_OBJS :=
MK_FLABLAS_F2C_SRC :=
MK_FLABLAS_F2C_OBJS :=

# --- Define install target names for static libraries ---
MK_FLAMEC_LIBS := $(MK_ALL_FLAMEC_LIB)
Expand Down Expand Up @@ -242,6 +242,7 @@ FFLAGS := $(FFLAGS) $(INCLUDE_PATHS)
# Convert source file paths to object file paths by replaying the base source
# directory with the base object directory, and also replacing the source file
# suffix (ie: '.c' or '.f') with '.o'.

MK_FLABLAS_F2C_OBJS := $(patsubst $(SRC_DIR)/%.c, $(BASE_OBJ_DIR)/%.o, \
$(filter %.c, $(MK_FLABLAS_F2C_SRC)))

Expand Down Expand Up @@ -269,7 +270,7 @@ MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS := $(patsubst $(SRC_DIR)/%.c, $(BASE_OBJ_D
# Combine the base, blas, and lapack libraries.
MK_ALL_FLAMEC_OBJS := $(MK_BASE_FLAMEC_OBJS) \
$(MK_BLAS_FLAMEC_OBJS) \
$(MK_LAPACK_FLAMEC_OBJS)
$(MK_LAPACK_FLAMEC_OBJS)

# Prepend the flablas source code files, if requested

Expand All @@ -288,13 +289,13 @@ ifeq ($(FLA_ENABLE_LAPACK2FLAME),no)
MK_FLABLAS_F2C_OBJS := $(MK_MAP_LAPACK2FLAMEC_F2C_INSTALL_OBJS) \
$(MK_FLABLAS_F2C_OBJS)
endif

MK_ALL_FLAMEC_OBJS := $(MK_FLABLAS_F2C_OBJS) \
$(MK_ALL_FLAMEC_OBJS)
endif

### Kyungjoo 2015.10.21
AR_CHUNK_SIZE=4096
#AR_CHUNK_SIZE=4096
AR_CHUNK_SIZE=256

#
# --- Targets/rules ------------------------------------------------------------
Expand Down Expand Up @@ -331,6 +332,19 @@ endif

# --- Special source code / object code rules ---

$(AR_OBJ_LIST_FILE): $(MK_ALL_FLAMEC_OBJS)
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
ifeq ($(FLA_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
echo $^ | xargs -n$(AR_CHUNK_SIZE) echo >> $(AR_OBJ_LIST_FILE)
else
@echo "Creating temporary ARG_MAX hack file."
@echo $^ | xargs -n$(AR_CHUNK_SIZE) echo >> $(AR_OBJ_LIST_FILE)
endif
else
@touch $(AR_OBJ_LIST_FILE)
endif


FLA_SLAMCH=base/flamec/util/lapack/mch/fla_slamch
$(BASE_OBJ_DIR)/$(FLA_SLAMCH).o: $(SRC_DIR)/$(FLA_SLAMCH).c $(CONFIG_MK_FRAGMENT)
ifeq ($(FLA_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
Expand All @@ -339,9 +353,9 @@ else
@echo "Compiling $<"
@$(CC) $(CFLAGS_NOOPT) -c $< -o $@
endif
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@echo $@ >> $(AR_OBJ_LIST_FILE)
endif
#ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
# @echo $@ >> $(AR_OBJ_LIST_FILE)
#endif

FLA_DLAMCH=base/flamec/util/lapack/mch/fla_dlamch
$(BASE_OBJ_DIR)/$(FLA_DLAMCH).o: $(SRC_DIR)/$(FLA_DLAMCH).c $(CONFIG_MK_FRAGMENT)
Expand All @@ -351,9 +365,9 @@ else
@echo "Compiling $<"
@$(CC) $(CFLAGS_NOOPT) -c $< -o $@
endif
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@echo $@ >> $(AR_OBJ_LIST_FILE)
endif
#ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
# @echo $@ >> $(AR_OBJ_LIST_FILE)
#endif

# --- General source code / object code rules ---

Expand All @@ -365,85 +379,90 @@ else
@echo "Compiling $<"
@$(CC) $(CFLAGS) -c $< -o $@
endif
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@echo $@ >> $(AR_OBJ_LIST_FILE)
endif
#ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
# @echo $@ >> $(AR_OBJ_LIST_FILE)
#endif



# --- Static library archiver rules for libflame ---
$(MK_ALL_FLAMEC_LIB): $(MK_ALL_FLAMEC_OBJS)

$(MK_ALL_FLAMEC_LIB): $(MK_ALL_FLAMEC_OBJS) $(AR_OBJ_LIST_FILE)
ifeq ($(FLA_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
### Kyungjoo 2015.10.21
$(CAT) $(AR_OBJ_LIST_FILE) | xargs -n$(AR_CHUNK_SIZE) $(AR) $(ARFLAGS) $@
### Previous hack (works on linux, not on osx)
### Previous hack (works on linux, not on osx; osx's ar does not support @file)
# echo $(ARFLAGS) $@ > $(AR_ARG_LIST_FILE)
# $(CAT) $(AR_OBJ_LIST_FILE) >> $(AR_ARG_LIST_FILE)
# $(AR) @$(AR_ARG_LIST_FILE)
$(RANLIB) $@
else
$(AR) $(ARFLAGS) $@ $^
$(RANLIB) $@
# NOTE: Can't use $^ automatic variable as long as $(AR_OBJ_LIST_FILE) is in
# the list of prerequisites.
$(AR) $(ARFLAGS) $@ $(MK_ALL_FLAMEC_OBJS)
endif
$(RANLIB) $@
mkdir -p include_local
cp -f $(MK_HEADER_FILES) include_local
else
@echo "Archiving $@"
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
### Kyungjoo 2015.10.21
@$(CAT) $(AR_OBJ_LIST_FILE) | xargs -n$(AR_CHUNK_SIZE) $(AR) $(ARFLAGS) $@
### Previous hack (works on linux, not on osx)
### Previous hack (works on linux, not on osx; osx's ar does not support @file)
# @echo $(ARFLAGS) $@ > $(AR_ARG_LIST_FILE)
# @$(CAT) $(AR_OBJ_LIST_FILE) >> $(AR_ARG_LIST_FILE)
# @$(AR) @$(AR_ARG_LIST_FILE)
@$(RANLIB) $@
else
@$(AR) $(ARFLAGS) $@ $^
@$(RANLIB) $@
# NOTE: Can't use $^ automatic variable as long as $(AR_OBJ_LIST_FILE) is in
# the list of prerequisites.
@$(AR) $(ARFLAGS) $@ $(MK_ALL_FLAMEC_OBJS)
endif
@$(RANLIB) $@
@mkdir -p include_local
@cp -f $(MK_HEADER_FILES) include_local
endif



# --- Dynamic library linker rules for libflame ---
$(MK_ALL_FLAMEC_DLL): $(MK_ALL_FLAMEC_OBJS)
$(MK_ALL_FLAMEC_DLL): $(MK_ALL_FLAMEC_OBJS) $(AR_OBJ_LIST_FILE)
ifeq ($(FLA_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
$(file > $@.in,$^)
sleep 3
$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$@.in
$(RM) $@.in
$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$(AR_OBJ_LIST_FILE)
else
$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $^
# NOTE: Can't use $^ automatic variable as long as $(AR_OBJ_LIST_FILE) is in
# the list of prerequisites.
$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $(MK_ALL_FLAMEC_OBJS)
endif
else
@echo "Dynamically linking $@"
ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
@$(file > $@.in,$^)
@sleep 3
@$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$@.in
@$(RM) $@.in
@$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$(AR_OBJ_LIST_FILE)
else
@$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $^
# NOTE: Can't use $^ automatic variable as long as $(AR_OBJ_LIST_FILE) is in
# the list of prerequisites.
@$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $(MK_ALL_FLAMEC_OBJS)
endif
endif

# Alternative implementation of the above.
# Original implementation of the rule above.
# FGVZ: This rule has been observed to not work on at least one system, where
# it appears the ".in" file is not fully written out, or written out at all,
# prior to the shared library link command being executed.
#$(MK_ALL_FLAMEC_DLL): $(MK_ALL_FLAMEC_OBJS)
#ifeq ($(FLA_ENABLE_VERBOSE_MAKE_OUTPUT),yes)
#ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
# $(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$(AR_OBJ_LIST_FILE)
# $(file > $@.in,$^)
# $(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$@.in
# $(RM) $@.in
#else
# $(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $^
#endif
#else
# @echo "Dynamically linking $@"
#ifeq ($(FLA_ENABLE_MAX_ARG_LIST_HACK),yes)
# @$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$(AR_OBJ_LIST_FILE)
# @$(file > $@.in,$^)
# @$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ @$@.in
# @$(RM) $@.in
#else
# @$(LINKER) -shared -Wl,-soname,libflame.so $(LDFLAGS) -o $@ $^
#endif
Expand Down Expand Up @@ -553,11 +572,10 @@ endif

# --- Clean rules ---
cleanmost: check-config
- $(FIND) $(BASE_OBJ_DIR) -name "*.o" | $(XARGS) $(RM_F)
- $(FIND) $(BASE_LIB_DIR) -name "*.a" | $(XARGS) $(RM_F)
- $(FIND) $(BASE_LIB_DIR) -name "*.so" | $(XARGS) $(RM_F)
- $(FIND) $(BASE_OBJ_DIR) -name "*.o" | $(XARGS) $(RM_F)
- $(FIND) $(BASE_LIB_DIR) -name "*.a" | $(XARGS) $(RM_F)
- $(FIND) $(BASE_LIB_DIR) -name "*.so" | $(XARGS) $(RM_F)
- $(RM_F) $(AR_OBJ_LIST_FILE)
# - $(RM_F) $(AR_ARG_LIST_FILE)
- $(RM_F) $(INCLUDE_LOCAL)/*.h

distclean: check-config cleanmost cleanmk
Expand All @@ -571,7 +589,7 @@ distclean: check-config cleanmost cleanmk
- $(RM_RF) config.sys_type

cleanmk: check-config
- $(FIND) $(SRC_DIR) -name "$(FRAGMENT_MK)" | $(XARGS) $(RM_F)
- $(FIND) $(SRC_DIR) -name "$(FRAGMENT_MK)" | $(XARGS) $(RM_F)

cleanleaves: check-config
- $(FIND) $(SRC_DIR) -name "*.[osx]" | $(XARGS) $(RM_F)
Expand Down

0 comments on commit d2c48fd

Please sign in to comment.