-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
103 lines (79 loc) · 2.33 KB
/
Makefile
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
SHELL := /bin/bash
TARGET = binary_name
C_SRC := $(wildcard *.c)
CPP_SRC := $(wildcard *.cpp)
H_SRC := $(wildcard *.h)
LIBRARY :=
INCLUDE_PATH := -I.
LIBRARY_PATH := -L.
CC = gcc
CC_FLAGS = -Wall -O3 -Wextra -Wpedantic
CCXX = g++
CCXX_FLAGS = -Wall -O3 -Wextra -Wpedantic
LIBRARY :=
LD = ld
LD_FLAGS =
#include makefile fragments in subdirectories if they exist
-include ./*/make.mk
OBJECTS = $(patsubst %.c, %.o, $(C_SRC))
OBJECTS += $(patsubst %.cpp, %.o, $(CPP_SRC))
RAMDISK_DIR = /mnt/ramdisk
# make ramdisj target creates and mounts a tempfs drive
#OBJ_DIR = $(RAMDISK_DIR)/objs
OBJ_DIR = objs
OBJS = $(addprefix $(OBJ_DIR)/, $(OBJECTS))
DEPS = $(patsubst %.o, %.o.d, $(OBJS))
all: $(TARGET) silent
#include all rules generated by gcc into the makefile
-include $(DEPS)
#dummy target to that we don't get unnecessary mesages ( target is up to date & co)
silent:
@:
$(TARGET): $(OBJS)
@echo Linking
@$(CCXX) $(LD_FLAGS) $(LIBRARY_PATH) -o $(TARGET) $^ $(LIBRARY)
#create output directory if it doesn't exist
#generate dependency file for current file
# .o and .d are targets of the rule
# create blank targets for each source/header file. Used to update .d files when you delete a file
$(OBJ_DIR)/%.o: %.c
@mkdir -p $(@D)
@echo Building $<
@$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@
@echo -n "$@.d $(@D)/" > $@.d
@$(CC) $(CC_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d
@cp $@.d $<.tp
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d
@rm -f $<.tp
$(OBJ_DIR)/%.o: %.cpp
@mkdir -p $(@D)
@echo Building $<
@$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -c $< -o $@
@echo -n "$@.d $(@D)/" > $@.d
@$(CCXX) $(CCXX_FLAGS) $(INCLUDE_PATH) $(ARGS) -MM $< >> $@.d
@cp $@.d $<.tp
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' -e '/^$$/ d' -e 's/$$/ :/' < $<.tp >> $@.d
@rm -f $<.tp
clean:
@echo Removing objects directory
@rm -rf $(OBJ_DIR)
@echo Removing target
@rm -f $(TARGET)
#http://blog.jgc.org/2015/04/the-one-line-you-should-add-to-every.html
print-%: ; @echo $*=$($*)
test:
@echo $(@D)
@echo $(DEPS)
@echo $(OBJECTS2)
@echo Test
@echo $(C_SRC)
@echo Test
@echo $(H_SRC)
@echo Test
@echo $(LIBRARY)
run: all
@./$(TARGET)
ramdisk:
sudo mkdir $(RAMDISK_DIR)
sudo mount -t tmpfs -o size=512m tmpfs $(RAMDISK_DIR)
.PHONY: test deploy all ramdisk