0

This is in reference to the second response here: How to generate a Makefile with source in sub-directories using just one makefile

The solution works great for me except for when the make rules are called. They never seem to make any once make-goal is called since the files don't exist in the build directory yet. I tested this by creating empty files in the build directory (just anyting.o) and the make rule is then found

my conclusion is that the % wildcard character is only looking for what is in the directory, and can't find the file so it doesnt make a build rule for it, and thus fails to continue. There are two possible solutions:

1) Find a way to make dummy object files that are overwritten when the compiler actually starts

2) Make make "realize" that the wild card is for anything put into the make-goal function, not what is already in the directory

any pointers?

As far as I know, I am the first one to have this issue \

MODULES := calibration calibration/settings camera/nikon camera ommon
SRC_DIR := $(addprefix src/, $(MODULES)) src
SDK_INCLUDES := include $(addprefix include/, $(MODULES))
BUILD_DIR := build $(addprefix build/, $(MODULES))

SRC := $(foreach sdir,$(SRC_DIR),$(wildcard $(sdir)/*.cpp))
OBJ := $(patsubst src/%.cpp,build/%.o, $(SRC))

# OpenCV directories, change according to your own installation
CV_INCLUDE_DIR  = C:\Users\a0225122\Downloads\opencv\build\include
CV_LIB_DIR      = C:\Users\a0225122\Downloads\opencv\bin\lib
CV_LIBS         =   -llibopencv_core249 \
                    -llibopencv_highgui249 \
                    -llibopencv_imgproc249 \
                    -llibopencv_features2d249 \
                    -llibopencv_calib3d249
CV_FLAGS        = -I$(CV_INCLUDE_DIR) -L$(CV_LIB_DIR) $(CV_LIBS)

HID_API_INCLUDE_DIR := 3rd_party/hidapi-master/hidapi/hid.h

# Compiler instructions
CXXFLAGS = -std=c++11 -Wall -I $(SDK_INCLUDE_DIR) -I $(CV_INCLUDE_DIR) -I $(HID_API_INCLUDE_DIR) -L $(CV_LIB_DIR) $(CV_LIBS) -L $(FLYCAP_LIB_DIR) $(FLYCAP_LIBS)

# Clean up instructions
ifdef SystemRoot #This is windows
    CXX = mingw32-g++
    RM = del /Q
    FixPath = $(subst /,\,$1)
    BUILD_DIR := $(call FixPath, $(BUILD_DIR))
    SRC_DIR := $(call FixPath, $(SRC_DIR))
    SDK_INCLUDES := $(call FixPath, $(SDK_INCLUDES))
    SRC := $(call FixPath, $(SRC))
    OBJ := $(call FixPath, $(OBJ))
    CXXFLAGS := $(call FixPath, $(CV_FLAGS))


define make-goal

$1\%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $$< -o $$@

endef   
else #more ifeqs can be added for more OS's but this should be fine
    CXX = g++
    RM = rm -f

define make-goal
$(1)/%.o: %.cpp
    $(CXX) $(CXXFLAGS) -c $$< -o $$@
endef   
endif

vpath %.cpp $(SRC_DIR)

SDK_LIBS = lib_core.a           

default: SDK.exe 

.PHONY: clean

clean:
    $(RM) build *.a


#executable generation
SDK.exe: $(SDK_LIBS)
    $(CXX) $(CXXFLAGS) $^ -o $@

lib_core.a: checkdirs $(OBJ)
    ar rcs lib_core.a $(OBJ)

checkdirs: $(BUILD_DIR)

$(BUILD_DIR):
    mkdir $@

#$(OBJ): $(SRC)
#   $(CXX) $(CXXFLAGS) -c $^ -o $@

$(foreach bdir,$(BUILD_DIR),$(eval $(call make-goal,$(bdir))))
Community
  • 1
  • 1
  • Your conclusion, though, is not correct. Make doesn't scan directories for targets matching patterns. Instead, if you ask to build a target that matches a pattern it will then try to see if the pattern rule can be used, by trying to create the prerequisites. If it can, then it uses the pattern rule. If not, it won't use it. Your description is not clear enough for us to help. Rather than referring to someone else's question, please provide a cut/paste of YOUR example makefile that fails, the command line you ran, and (cut/paste) of the output you got and what you wanted to get. – MadScientist Jun 16 '14 at 23:01
  • I have added my code, sorry about that – Brandon Ross Pollack Jun 17 '14 at 13:45

1 Answers1

1

Your first problem is that you cannot use backslashes in GNU make rules, except in recipes (make just sends the recipe to the shell, it doesn't interpret the recipe except for $). All GNU make targets, prerequisites, etc. must use forward slashes, all the time, even on Windows.

Almost all Windows applications will accept forward-slashes as directory separators properly. For the few that don't, you can use your function FixPath, but you must use it inside the recipe, not in the target or prerequisite lists.

Once you've resolved that issue if you still have problems, post what you have and we'll look.

MadScientist
  • 92,819
  • 9
  • 109
  • 136