Here is my Makefile. All the %.o depend on %.c and main.h, except the ones under main, event, cmd folder, which depend on $(MAIN_HEADERS).
How do I combine the below and make them simpler, as their recipes are all the same?
$(BUILD_OBJ_DIR)/%.o: %.c main.h
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
@echo "CC $(patsubst $(PWD)/%,%,$<)"
$(BUILD_OBJ_DIR)/main/%.o: main/%.c $(MAIN_HEADERS)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
@echo "CC $(patsubst $(PWD)/%,%,$<)"
$(BUILD_OBJ_DIR)/event/%.o: event/%.c $(MAIN_HEADERS)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
@echo "CC $(patsubst $(PWD)/%,%,$<)"
$(BUILD_OBJ_DIR)/cmd/%.o: cmd/%.c $(MAIN_HEADERS)
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c $< -o $@
@echo "CC $(patsubst $(PWD)/%,%,$<)"