-2

This is the main part of my makefile:

#openmp
ifeq($(BLITTZ_CC), icc)
    OPENMP_OPTIONS := -fopenmp
else
    OPENMP_OPTIONS := -fopenmp
endif

#compiler options
CXXFLAGS := -WALL -Wno-unused-parameter $(OPTIMIZE_OPTIONS) $(OPENMP_OPTIONS) $(MODE)

SRC_LIST := $(wildcard $(SRC_DIR)/*.cpp)
OBJ_LIST := $(patsubst %.cpp, $(BUILD_DIR)/%.o, $(notdir $(SRC_LIST)))
TARGET := main
BIN_TARGET := $(BIN_DIR)/$(TARGET)

$(BIN_TARGET): $(OBJ_LIST)
    $(BLITZ_CC) -o $@ $(OBJ_LIST) $(CXXFLAGS)

$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.s
    $(BLITZ_CC) -o $@ -c $< $(CXXFLAGS)

$(BUILD_DIR)/%.s: $(SRC_DIR)/%.cpp
    $(BLITZ_CC) -o $@ -S $(CXXFLAGS) $<

#inc test
test:
    echo $(SRC_LIST)
    echo $(OBJ_LIST)
    echo $(BIN_TARGET)

#clean
clean:
    find $(BUILD_DIR) -name *.o -exec rm rf {} \;
    find $(BUILD_DIR) -name *.s -exec rm rf {} \;
    rm $(BIN_DIR)/*

This is what happens after make:

enter image description here

Why does rm *.s occur here? I need the assemble files and I do not want to delete them.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99
Water
  • 11
  • 7
    Post source and build logs **inside the question**. Don't post images. – StoryTeller - Unslander Monica Mar 16 '17 at 09:35
  • Maybe remove the relevant `rm` command from the makefile? – Spikatrix Mar 16 '17 at 10:11
  • Are you missing a default target in your Makefile? See [this reply](http://stackoverflow.com/a/30176470/2568607) for more details – zlig Mar 16 '17 at 15:47
  • My eyesight is not good enough to read your screenshot, but the `.s` files are all intermediate files in the generation of `.o` files from `.c` sources; so `make` will delete them all afterwards unless you specifically issued a command to make the `.s` files. You can use `.PRECIOUS: %.s` to keep them in recent versions of gmake – M.M Mar 16 '17 at 21:17

2 Answers2

3

Because you've chained rules to create your .o files from your .cpp files, make marked your .s files as intermediate files and deleted them after building your target:

[...] an intermediate file which did not exist before make also does not exist after make.

You need to either mark your files as secondary files:

.SECONDARY: $(OBJ_LIST:.o=.s)

When a file is secondary, make will not create the file merely because it does not already exist, but make does not automatically delete the file.

Or you can flag your file pattern as precious:

.PRECIOUS: %.s

You can list the target pattern of an implicit rule (such as ‘%.o’) as a prerequisite of the special target .PRECIOUS to preserve intermediate files made by implicit rules whose target patterns match that file’s name; [...]

Chnossos
  • 9,971
  • 4
  • 28
  • 40
0

find $(BUILD_DIR) -name *.s -exec rm rf {} \; will get all .s files and execute rm rf so delete that line if you want to keep .s files

amine.ahd
  • 431
  • 3
  • 11
  • Well, that's what the line will do if the only `*.s` files are under BUILD_DIR (none in the current working directory). It's buggy otherwise -- `*.s` will be expanded by the shell if any files matching it exist in the working directory. The OP probably *wants* `'*.s'` instead. – Charles Duffy Mar 16 '17 at 21:23
  • BTW, `\;` is really silly there -- it's running `rm` once per file found; `+` would be more appropriate, passing multiple filenames to a single `rm` invocation. And there's no good excuse for `-rf` (or the bug-not-a-flag `rf` actually present in the OP's code) when deleting files rather than directories. – Charles Duffy Mar 16 '17 at 21:25
  • This line is in the `clean` rule and has nothing to do with what the op is experiencing. – Chnossos Mar 16 '17 at 22:06