Bugfix: dependency files

This commit is contained in:
Thomas Klaehn 2019-07-09 12:27:35 +02:00
parent dc884d51a9
commit 6aa295a9fd
3 changed files with 20 additions and 13 deletions

View File

@ -1,6 +1,6 @@
CROSS_COMPILE ?= CROSS_COMPILE ?=
TARGET_FILE ?= dnssd TARGET_FILE ?= test
CC = $(CROSS_COMPILE)gcc CC = $(CROSS_COMPILE)gcc
@ -8,6 +8,8 @@ SRC_DIR = src
OBJ_DIR = obj OBJ_DIR = obj
BIN_DIR = bin BIN_DIR = bin
C_FLAGS := -O0 -g -Iinc
C_SRCS = $(wildcard $(SRC_DIR)/*.c) C_SRCS = $(wildcard $(SRC_DIR)/*.c)
C_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(C_SRCS))) C_OBJS = $(patsubst %.c,$(OBJ_DIR)/%.o,$(notdir $(C_SRCS)))
@ -22,19 +24,19 @@ $(TARGET): $(OBJS)
@mkdir -p $(BIN_DIR) @mkdir -p $(BIN_DIR)
$(CC) $(LD_FLAGS) $(OBJS) $(LIBS) -o $@ $(CC) $(LD_FLAGS) $(OBJS) $(LIBS) -o $@
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c .PRECIOUS: $(OBJ_DIR)/%.d
$(OBJ_DIR)/%.d:
@mkdir -p $(OBJ_DIR)
$(CC) -MM -MF $@ -MP -MT $(patsubst %.d,%.o,$@) $(C_FLAGS) $(filter %$(patsubst %.d,%.c,$(notdir $@)),$(C_SRCS))
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)/%.d
@mkdir -p $(OBJ_DIR) @mkdir -p $(OBJ_DIR)
$(call makedep,$<,$@,$(patsubst %c,%d,$(OBJ_DIR)/$(notdir $<)))
$(CC) -c $(C_FLAGS) $< -o $@ $(CC) -c $(C_FLAGS) $< -o $@
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf $(OBJ_DIR) $(BIN_DIR) rm -rf $(OBJS) $(patsubst %.o,%.d,$(OBJS)) $(TARGET)
define makedep
$(CC) -MM -MF $3 -MP -MT $2 $4 $1
endef
ifneq ($(MAKECMDGOALS),clean) ifneq ($(MAKECMDGOALS),clean)
-include $($(subst .o,.d,$(OBJS))) -include $(patsubst %.o,%.d,$(OBJS))
endif endif

6
inc/test.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef __INC_TEST_H__
#define __INC_TEST_H__
#endif // __INC_TEST_H__

View File

@ -1,10 +1,9 @@
#include <stdio.h> #include <stdio.h>
#include <test.h>
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
printf("Content-type: text/plain\n");
printf('\n');
printf("Hello World\n"); printf("Hello World\n");
return 0; return 0;