-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
101 lines (67 loc) · 2.03 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
# Makefile for Insanity Standard Library (libins)
CC=gcc
INCLUDES=-IICC/dev
CFLAGS=-O3 -fPIC $(INCLUDES) -Wall -Wno-unused-function -Wno-unused-result
DEPFLAGS=-MD -MF $(@:$(OBJD)/%=$(DEPD)/%.d) -MT $@ -MP
LIBS=-lpthread
# Library to compile
# lib<Library>.so = Production library
# lib<Library>d.so = Debug library
LIBRARY=icc
# Directories
# SRCD = Source directory (where to put the actual code)
# OBJD = Object directory (where to put all .o and .do files)
# LIBD = Library directory (where to put .so file)
# DEPD = Dependency directory (where to put all .d files)
SRCD=src
OBJD=obj
LIBD=lib
DEPD=obj
$(shell mkdir -p $(OBJD) $(LIBD) $(DEPD))
# C sources
CSRC=\
Insanity-Dev.c \
\
args/init_data.c \
args/Argc.c \
args/Argv.c \
args/ArgvReset.c
# Insanity sources
ISRC=\
stdio/PrintNumber.ins \
# Computer library name, objects, debug objects, dependency files, etc.
LIB = $(LIBD)/lib$(LIBRARY).so
DLIB = $(LIBD)/lib$(LIBRARY)d.so
OBJS = $(addprefix $(OBJD)/,$(CSRC:%.c=%.o) $(ISRC:%=%.o))
DEB_OBJS = $(OBJS:%.o=%.do)
DEPENDS = $(addprefix $(DEPD)/,$(OBJS:$(OBJD)/%=%.d) $(DEB_OBJS:$(OBJD)/%=%.d))
ICFILES = $(ISRC:%=$(SRCD)/%.c)
.PHONY: all
all: $(LIB) $(DLIB)
# Compile the library
$(LIB): $(OBJS)
$(CC) -shared $^ -o $@ $(LIBS)
# Compile the debug shared library
$(DLIB): $(DEB_OBJS)
$(CC) -shared $^ -o $@ $(LIBS)
# Bring in the dependency info for *existing* .o files, and ignore default rules
-include $(DEPENDS)
.SUFFIXES:
# Compile C object files
$(OBJD)/%.o: $(SRCD)/%.c
@mkdir -p $(dir $(@)) $(addprefix $(DEPD)/,$(dir $(@:$(OBJD)/%=%)))
$(CC) -c $(CFLAGS) $(DEPFLAGS) $< -o $@
# Compile debug C object files
$(OBJD)/%.do: $(SRCD)/%.c
@mkdir -p $(dir $(@)) $(addprefix $(DEPD)/,$(dir $(@:$(OBJD)/%=%)))
$(CC) -c -g $(CFLAGS) $(DEPFLAGS) $< -o $@
# "Compile" insanity C source files
.PRECIOUS: %.ins.c
%.ins.c: %.ins
icc $< $@
# Remove all files
.PHONY: clean
clean:
rm -f $(LIB) $(DLIB) $(OBJS) $(DEB_OBJS) $(DEPENDS) $(ICFILES)
# Print out a makefile variable
print-% : ; @echo $* = $($*)