summaryrefslogtreecommitdiffstats
path: root/common.mk
blob: c8d7387c0a4cdb81e941ca40a430e0afa986a4e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# Compiler and default flags
CC ?= gcc
CFLAGS ?= -O0


# Defaults for directories
ROOTDIR ?= $(shell pwd)

INCDIR ?= $(ROOTDIR)
BINDIR ?= $(ROOTDIR)
LIBDIR ?= $(ROOTDIR)
OBJDIR ?= $(ROOTDIR)
DEPENDDIR ?= $(ROOTDIR)

CXXFLAGS += $(addprefix -I ,$(INCDIR)) -fPIC
CFLAGS += $(addprefix -I ,$(INCDIR)) -fPIC -std=c99

# Source files in this directory
SRC = $(wildcard *.cpp)
SRCC = $(wildcard *.c)

SRC += $(wildcard ipecamera/*.cpp)
SRCC += $(wildcard ipecamera/*.c)

SRC += $(wildcard dma/*.cpp)
SRCC += $(wildcard dma/*.c)

# Corresponding object files 
OBJ = $(addprefix $(OBJDIR)/,$(SRC:.cpp=.o))
OBJ += $(addprefix $(OBJDIR)/,$(SRCC:.c=.o))

# Corresponding dependency files
DEPEND = $(addprefix $(DEPENDDIR)/,$(SRC:.cpp=.d)) 
DEPEND += $(addprefix $(DEPENDDIR)/,$(SRCC:.c=.d)) 

# This makes Verbose easier. Just prefix $(Q) to any command
ifdef VERBOSE
	Q ?= 
else
	Q ?= @
endif

###############################################################
# Target definitions

# Target for automatic dependency generation
depend: $(DEPEND) $(DEPENDC);

# This rule generates a dependency makefile for each source
$(DEPENDDIR)/%.d: %.c
	@echo -e "DEPEND \t$<"
	$(Q)$(CC) $(addprefix -I ,$(INCDIR)) -MM -MF $@ \
		-MT $(OBJDIR)/$(<:.c=.o) -MT $@ $< 

# This includes the automatically 
# generated dependency files
-include $(DEPEND)

$(OBJDIR)/%.o: %.c
	@echo -e "CC \t$<"
	$(Q)@$(CC) $(CFLAGS) -c -o $@ $<