Skip to content

Commit

Permalink
Merge pull request #266 from PRUNERS/issue253-make-support-more-exten…
Browse files Browse the repository at this point in the history
…sions

Issue253 make support more extensions
  • Loading branch information
IanBriggs authored May 21, 2019
2 parents 3d6a83d + 0ad29f8 commit 3956f48
Show file tree
Hide file tree
Showing 12 changed files with 179 additions and 116 deletions.
105 changes: 66 additions & 39 deletions data/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ IS_VER_4_OR_5 = $(shell expr $(call IS_MAJOR_VER,$1,4) \| \
DEV_LDFLAGS =
GT_LDFLAGS =

DEPFLAGS += -MMD -MP -MF $(patsubst %.o,%.d,$@)
# Note: needs dependency out filename after this variable
DEPFLAGS += -MMD -MP -MF

# TODO: deprecated. Remove in FLiT version 3.0
TESTS = $(wildcard tests/*.cpp)
SOURCE = $(wildcard *.cpp)
SOURCE += $(TESTS)

VPATH = $(dir $(SOURCE))

.PHONY: help
help:
@echo 'You can run the Makefile directly, but it is recommended to use'
Expand All @@ -224,12 +224,16 @@ help:
# to SOURCE from custom.mk
-include custom.mk

# sort and remove duplicates
# TODO: Remove in FLiT version 3.0
SOURCE := $(sort $(SOURCE))

# We are done adding to VPATH, so consolidate it for speed (removing duplicates)
VPATH := $(sort $(VPATH))

DEV_OBJ = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%.cpp=%_dev.o)))
DEV_OBJ = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%=%_dev.o)))
DEV_DEPS = $(DEV_OBJ:%.o=%.d)
GT_OBJ = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%.cpp=%_gt.o)))
GT_OBJ = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%=%_gt.o)))
GT_DEPS = $(GT_OBJ:%.o=%.d)
GT_OBJ_FPIC = $(GT_OBJ:%.o=%_fPIC.o)

Expand Down Expand Up @@ -278,6 +282,24 @@ endif
#
##########################################################

# Compiles a single object file from a source file given compiler and flags
# @param 1: source file
# @param 2: object file
# @param 3: compiler
# @param 4: optimization level
# @param 5: switches
# @param 6: target filename
# @param 7: extra compiler flags
define COMPILE_RULE
$2: $1 Makefile custom.mk | $(OBJ_DIR)
$3 $4 $5 -c $7 $(CC_REQUIRED) $(DEPFLAGS) $(2:%.o=%.d) $1 -o $2 \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(strip $3)"' \
-DFLIT_OPTL='"$(strip $4)"' \
-DFLIT_SWITCHES='"$(strip $5)"' \
-DFLIT_FILENAME='"$(notdir $(strip $6))"'
endef

# will be set internally when doing recursive calls. Get set to variable names
# containing the information (e.g. R_CUR_COMPILER=CLANG)
R_CUR_COMPILER ?=
Expand All @@ -289,7 +311,7 @@ ifdef R_IS_RECURSED

R_ID := $(R_CUR_COMPILER)_$(HOSTNAME)_$(R_CUR_SWITCHES)_$(R_CUR_OPTL)
R_TARGET := $(RESULTS_DIR)/$(R_ID)
R_OBJ := $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%.cpp=%_$(R_ID).o)))
R_OBJ := $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%=%_$(R_ID).o)))
R_DEP := $(R_OBJ:%.o=%.d)

-include $(R_DEP)
Expand All @@ -314,16 +336,15 @@ $(R_TARGET): $(R_OBJ)
$(R_OBJ) -o $@ \
$(LD_REQUIRED)

$(OBJ_DIR)/%_$(R_ID).o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$($(R_CUR_COMPILER)) $($(R_CUR_OPTL)) $($(R_CUR_SWITCHES)) \
-c $($(R_CUR_COMPILER)_REQUIRED) $(CC_REQUIRED) \
$< -o $@ \
$(DEPFLAGS) \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$($(R_CUR_COMPILER))"' \
-DFLIT_OPTL='"$($(R_CUR_OPTL))"' \
-DFLIT_SWITCHES='"$($(R_CUR_SWITCHES))"' \
-DFLIT_FILENAME='"$(R_ID)"'
$(foreach s,$(SOURCE), \
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_$(R_ID).o,\
$($(R_CUR_COMPILER)),\
$($(R_CUR_OPTL)),\
$($(R_CUR_SWITCHES)),\
$(R_ID),\
$($(R_CUR_COMPILER)_REQUIRED))))

# Otherwise, we're not in a recursion.
else # ifndef R_IS_RECURSED
Expand Down Expand Up @@ -402,7 +423,7 @@ TARGET_RESULTS := $(TARGET_OUTS:%=%-comparison.csv)
# Define the recursion rules
#

OBJ_CLEAN = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%.cpp=%_*.o)))
OBJ_CLEAN = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCE:%=%_*.o)))
DEP_CLEAN += $(OBJ_CLEAN:%.o=%.d)

.PHONY: dev gt gt-fpic groundtruth run runbuild
Expand Down Expand Up @@ -479,13 +500,15 @@ $(DEV_TARGET): $(DEV_OBJ) Makefile custom.mk
$(DEV_CXX) $(CC_REQUIRED) $(DEV_CFLAGS) \
-o $@ $(DEV_OBJ) $(LD_REQUIRED) $(DEV_LDFLAGS)

$(OBJ_DIR)/%_dev.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(DEV_CXX) $(DEV_OPTL) $(DEV_SWITCHES) $(CC_REQUIRED) $(DEV_CFLAGS) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(DEV_CXX)"' \
-DFLIT_OPTL='"$(DEV_OPTL)"' \
-DFLIT_SWITCHES='"$(DEV_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(DEV_TARGET))"'
$(foreach s,$(SOURCE),\
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_dev.o,\
$(DEV_CXX),\
$(DEV_OPTL),\
$(DEV_SWITCHES),\
$(DEV_TARGET),\
$(DEV_CFLAGS))))

# Ground truth compilation rules
$(GT_OUT): $(GT_TARGET)
Expand All @@ -495,21 +518,25 @@ $(GT_TARGET): $(GT_OBJ) Makefile custom.mk
$(GT_CXX) $(CC_REQUIRED) $(GT_CFLAGS) \
-o $@ $(GT_OBJ) $(LD_REQUIRED) $(GT_LDFLAGS)

$(OBJ_DIR)/%_gt.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(GT_CXX) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(GT_CFLAGS) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'

$(OBJ_DIR)/%_gt_fPIC.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(GT_CXX) -g $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(GT_CFLAGS) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'
$(foreach s,$(SOURCE),\
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_gt.o,\
$(GT_CXX),\
$(GT_OPTL),\
$(GT_SWITCHES),\
$(GT_TARGET),\
$(GT_CFLAGS) -g)))

$(foreach s,$(SOURCE),\
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_gt_fPIC.o,\
$(GT_CXX),\
$(GT_OPTL),\
$(GT_SWITCHES),\
$(GT_TARGET),\
$(GT_CFLAGS) -fPIC -g)))

endif # end of ifdef R_IS_RECURSED

116 changes: 69 additions & 47 deletions data/Makefile_bisect_binary.in
Original file line number Diff line number Diff line change
Expand Up @@ -140,29 +140,29 @@ endif
BUILD_GT_LOCAL := {build_gt_local}

TROUBLE_TARGET_OBJ := $(addprefix \
$(OBJ_DIR)/,$(notdir $(SOURCE:%.cpp=%_bisect_$(TROUBLE_ID).o)))
$(OBJ_DIR)/,$(notdir $(SOURCE:%=%_bisect_$(TROUBLE_ID).o)))
ALL_TROUBLE_FPIC := $(TROUBLE_TARGET_OBJ:%.o=%_fPIC.o)
BISECT_GT_OBJ := $(addprefix \
$(OBJ_DIR)/,$(notdir $(BISECT_GT_SRC:%.cpp=%_gt.o)))
$(OBJ_DIR)/,$(notdir $(BISECT_GT_SRC:%=%_gt.o)))
TROUBLE_OBJ := $(addprefix \
$(OBJ_DIR)/,$(notdir $(TROUBLE_SRC:%.cpp=%_bisect_$(TROUBLE_ID).o)))
$(OBJ_DIR)/,$(notdir $(TROUBLE_SRC:%=%_bisect_$(TROUBLE_ID).o)))
BISECT_OBJ := $(BISECT_GT_OBJ)
BISECT_OBJ += $(TROUBLE_OBJ)
TROUBLE_TARGET_DEPS := $(TROUBLE_TARGET_OBJ:%.o=%.d)
FPIC_OBJ := $(addprefix \
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%.cpp=%_gt_fPIC.o)))
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%=%_gt_fPIC.o)))
FPIC_OBJ := $(addprefix \
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%.cpp=%_bisect_$(TROUBLE_ID)_fPIC.o)))
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%=%_bisect_$(TROUBLE_ID)_fPIC.o)))
FPIC_DEPS := $(FPIC_OBJ:%.o=%.d)
SPLIT_OBJ := $(addprefix \
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%.cpp=%_gt_split_$(NUMBER).o)))
$(BISECT_OBJ_DIR)/,$(notdir $(SPLIT_SRC:%=%_gt_split_$(NUMBER).o)))
SPLIT_OBJ += $(addprefix \
$(BISECT_OBJ_DIR)/,$(notdir \
$(SPLIT_SRC:%.cpp=%_trouble_split_$(NUMBER).o)))
$(SPLIT_SRC:%=%_trouble_split_$(NUMBER).o)))
SPLIT_DEPS := $(SPLIT_OBJ:%.o=%.d)
TROUBLE_SYMBOLS := $(addprefix \
$(BISECT_OBJ_DIR)/,$(notdir \
$(SPLIT_SRC:%.cpp=%_trouble_symbols_$(NUMBER).txt)))
$(SPLIT_SRC:%=%_trouble_symbols_$(NUMBER).txt)))

TROUBLE_TARGET_OUT := $(TROUBLE_TARGET:%=%-out)
TROUBLE_TARGET_RESULT := $(TROUBLE_TARGET_OUT:%=%-comparison.csv)
Expand Down Expand Up @@ -270,56 +270,78 @@ $(BISECT_DIR):
$(BISECT_OBJ_DIR):
mkdir -p $(BISECT_OBJ_DIR)

# ground-truth files are already specified in Makefile
# but need to specify how to do the fPIC variant
$(BISECT_OBJ_DIR)/%_gt_fPIC.o: %.cpp Makefile custom.mk | $(BISECT_OBJ_DIR)
if [ -f "$(OBJ_DIR)/$*_gt_fPIC.o" ]; then \
ln -s "../../$(OBJ_DIR)/$*_gt_fPIC.o" "$@"; \
# Copied mostly from Makefile.in COMPILE_RULE, but customized for bisect
# Compiles a single object file with -fPIC, checking first for a precompiled
# version (and if so, copy it instead of recompiling).
# @param 1: source file
# @param 2: object file
# @param 3: compiler
# @param 4: optimization level
# @param 5: switches
# @param 6: target filename
# @param 7: extra compiler flags
define FPIC_COMPILE_RULE
$2: $1 Makefile custom.mk | $(BISECT_OBJ_DIR)
if [ -f "$(OBJ_DIR)/$(notdir $(strip 2))" ]; then \
ln -s "../../$(OBJ_DIR)/$(notdir $(strip 2))" "$(strip $2)"; \
else \
$(GT_CXX) $(GT_OPTL) $(GT_SWITCHES) $(CC_REQUIRED) $(GT_CFLAGS) $(DEPFLAGS) -fPIC -c $< -o $@ \
$3 $4 $5 -c $7 $(CC_REQUIRED) -fPIC $(DEPFLAGS) $(2:%.o=%.d) $1 -o $2 \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(GT_CXX)"' \
-DFLIT_OPTL='"$(GT_OPTL)"' \
-DFLIT_SWITCHES='"$(GT_SWITCHES)"' \
-DFLIT_FILENAME='"$(notdir $(GT_TARGET))"'; \
-DFLIT_COMPILER='"$(strip $3)"' \
-DFLIT_OPTL='"$(strip $4)"' \
-DFLIT_SWITCHES='"$(strip $5)"' \
-DFLIT_FILENAME='"$(notdir $(strip $6))"'; \
fi
endef

$(foreach s,$(SOURCE),\
$(eval $(call FPIC_COMPILE_RULE,\
$s,\
$(BISECT_OBJ_DIR)/$(notdir $s)_gt_fPIC.o,\
$(GT_CXX),\
$(GT_OPTL),\
$(GT_SWITCHES),\
$(GT_TARGET),\
$(GT_CFLAGS))))

# specify how to build the troublesome ones
$(OBJ_DIR)/%_bisect_$(TROUBLE_ID).o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(TROUBLE_CFLAGS) $(DEPFLAGS) -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'

# and the fPIC variant
$(BISECT_OBJ_DIR)/%_bisect_$(TROUBLE_ID)_fPIC.o: %.cpp Makefile custom.mk | $(BISECT_OBJ_DIR)
if [ -f "$(OBJ_DIR)/$*_bisect_$(TROUBLE_ID)_fPIC.o" ]; then \
ln -s "../../$(OBJ_DIR)/$*_bisect_$(TROUBLE_ID)_fPIC.o" "$@"; \
else \
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(TROUBLE_CFLAGS) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'; \
fi
$(foreach s,$(SOURCE),\
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_bisect_$(TROUBLE_ID).o,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
bisect-default-out,\
$(TROUBLE_CFLAGS))))

# and the fPIC variant
$(OBJ_DIR)/%_bisect_$(TROUBLE_ID)_fPIC.o: %.cpp Makefile custom.mk | $(OBJ_DIR)
$(TROUBLE_CXX) $(TROUBLE_OPTL) $(TROUBLE_SWITCHES) $(CC_REQUIRED) $(TROUBLE_CFLAGS) $(DEPFLAGS) -fPIC -c $< -o $@ \
-DFLIT_HOST='"$(HOSTNAME)"' \
-DFLIT_COMPILER='"$(TROUBLE_CXX)"' \
-DFLIT_OPTL='"$(TROUBLE_OPTL)"' \
-DFLIT_SWITCHES='"$(TROUBLE_SWITCHES)"' \
-DFLIT_FILENAME='"bisect-default-out"'
$(foreach s,$(SOURCE),\
$(eval $(call FPIC_COMPILE_RULE,\
$s,\
$(BISECT_OBJ_DIR)/$(notdir $s)_bisect_$(TROUBLE_ID)_fPIC.o,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
bisect-default-out,\
$(TROUBLE_CFLAGS))))

# The fPIC variant built in OBJ_DIR instead of BISECT_OBJ_DIR
$(foreach s,$(SOURCE),\
$(eval $(call COMPILE_RULE,\
$s,\
$(OBJ_DIR)/$(notdir $s)_bisect_$(TROUBLE_ID)_fPIC.o,\
$(TROUBLE_CXX),\
$(TROUBLE_OPTL),\
$(TROUBLE_SWITCHES),\
bisect-default-out,\
$(TROUBLE_CFLAGS))))

# Specify how to split symbols using objcopy

# Defines how to split the one object file into two object files using objcopy
# @param 1: src basename (e.g. for 'tests/Example01.cpp' pass in 'Example01')
# @param 1: src basename (e.g. for 'tests/Example01.cpp' pass in
# 'Example01.cpp')
define SPLIT_RULE

$$(BISECT_OBJ_DIR)/$1_gt_split_$$(NUMBER).o: $$(BISECT_OBJ_DIR)/$1_gt_fPIC.o
Expand Down Expand Up @@ -354,5 +376,5 @@ $$(BISECT_OBJ_DIR)/$1_trouble_split_$$(NUMBER).o: | $$(BISECT_OBJ_DIR)

endef

$(foreach s, $(notdir $(SPLIT_SRC:%.cpp=%)), \
$(foreach s, $(notdir $(SPLIT_SRC:%=%)), \
$(eval $(call SPLIT_RULE,$s)))
12 changes: 9 additions & 3 deletions data/custom.mk
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,15 @@
# This file is included by the generated Makefile. If you have some things you
# want to change about the Makefile, it is best to do it here.

# additional source files to compile other than what is in '.' and 'tests/'
# since those directories are added by a wildcard.
SOURCE +=
# source files to compile.
# Note:
# until version 3.0, the wildcards *.cpp and tests/*.cpp are also in the
# autogenerated Makefile. If this breaks your setup, then you can override
# and empty the SOURCE variable with
# SOURCE :=
# then add in your own source files
SOURCE += $(wildcard *.cpp)
SOURCE += $(wildcard tests/*.cpp)

# required compiler flags
# for example, include directories
Expand Down
3 changes: 1 addition & 2 deletions documentation/compiling-your-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ changes. Instead put changes in this `custom.mk` file.
The `custom.mk` file is already populated with variables that you may want to
use. Simply add to these variables to compile your application.

- `SOURCE`: This variable contains source code to compile other than the tests
that are in the `tests` directory.
- `SOURCE`: This variable contains source files to compile
- `CC_REQUIRED`: Compiler flags to use across the board, for the dev build,
ground-truth build, and all other builds. Here is where you set macro
variables, include paths, and perhaps warning flags.
Expand Down
3 changes: 2 additions & 1 deletion documentation/flit-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ There are a few other files copied over:
* `custom.mk`: a custom file that is included at the end of Makefile
* `Makefile`: an autogenerated Makefile using `flit-config.toml`
* `main.cpp`: a minimal main function. No modification necessary, but you may
if you want.
if you want. You are free to rename this file as necessary, just make sure
it is included in `custom.mk` in the `SOURCE` variable.
* `tests/Empty.cpp`: This is a template for how to write tests in this
framework

Expand Down
10 changes: 6 additions & 4 deletions documentation/writing-test-cases.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ implies - empty. It basically shows you how to create a new test and is
intended to be used as a template for creating tests.

To add a test, simply copy `Empty.cpp` and place it in the `tests` directory
with an ending of `cpp`. Rename the class inside, and you're good to go.
with an ending of `.cpp`. Rename the class inside, and you're good to go. If
you name it with a different ending than `.cpp`, then you will need to ensure
it is included from within `custom.mk` in the `SOURCE` variable.


## Test Case Requirements
Expand Down Expand Up @@ -61,9 +63,9 @@ like to override that behavior.
## Disabling Test Cases

Since all files ending with `.cpp` in the `tests` directory and the parent
directory are included in the compilation, the best way to disable a test is
simply to move it into a new directory. Suppose the test I want to disable is
called `BrokenTest.cpp`.
directory are included in the compilation by default, the best way to disable a
test is simply to move it into a new directory. Suppose the test I want to
disable is called `BrokenTest.cpp`.

```bash
mkdir disabled
Expand Down
Loading

0 comments on commit 3956f48

Please sign in to comment.