I have a makefile with 2 different targets – one builds for LINUX executable and the other builds for WINDOWS executable.
linux: $(LINUX_OBJS)
@echo Linking: $@
@mkdir -p $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)/$@
@$(CC) $(LFLAGS) app.c $+ -o $(BUILD_DIR)/$@/app $(INCLUDES) $(LINUX_INCS)
win: $(WIN_OBJS)
@echo Linking: $@
@mkdir -p $(BUILD_DIR)
@mkdir -p $(BUILD_DIR)/$@
@$(CC) $(LFLAGS) app.c $+ -o $(BUILD_DIR)/$@/app.exe $(INCLUDES) $(WIN_INCS)
## compiling
$(BUILD_DIR)/linux/%.o $(BUILD_DIR)/win/%.o: $(ROOT_PATH)/%.c
@echo target: $? ($@)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) $(WFLAGS) -c -o $@ $^ $(INCLUDES) $(WIN_INCS) $(LINUX_INCS)
clean:
@rm -f -r $(BUILD_DIR)
I want to add an all option, to build both for linux and for windows, so I added:
all: clean linux win
The problem is that when I it starts building for windows, it only compiles the new files that are relevan for windows only (from $WIN_OBJS)) and therefore fails to link it all.
How can I make it build them both? (so I can keep all object files and final linked execution in corresponding build directory, without being deleted between them)?