-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
63 lines (50 loc) · 1.39 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
CC = gcc
CFLAGS = -Iinclude -Iinclude/standard_libraries -Werror
SRCDIR = src
INCDIR = include
BUILDDIR = build
TEMPDIR = temp
TARGET = $(BUILDDIR)/dosato
LIB_TARGET = $(BUILDDIR)/dosato_lib
SOURCES := $(wildcard $(SRCDIR)/*.c) $(wildcard $(SRCDIR)/standard_libraries/*.c) main.c
OBJECTS := $(patsubst $(SRCDIR)/%.c,$(TEMPDIR)/%.o,$(patsubst $(SRCDIR)/standard_libraries/%.c,$(TEMPDIR)/standard_libraries/%.o,$(SOURCES:main.c=$(TEMPDIR)/main.o)))
all: $(BUILDDIR) $(TEMPDIR) $(TARGET) lib
$(TARGET): $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^
lib: $(LIB_TARGET)
ifeq ($(OS),Windows_NT)
$(LIB_TARGET): $(OBJECTS)
$(CC) -shared -o $(LIB_TARGET).dll $^
else
$(LIB_TARGET): $(OBJECTS)
$(CC) -shared -o $(LIB_TARGET).so $^
endif
$(TEMPDIR)/%.o: $(SRCDIR)/%.c
$(CC) $(CFLAGS) -c -o $@ $<
$(TEMPDIR)/standard_libraries/%.o: $(SRCDIR)/standard_libraries/%.c
$(CC) $(CFLAGS) -c -o $@ $<
$(TEMPDIR)/main.o: main.c
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILDDIR):
ifeq ($(OS),Windows_NT)
if not exist $(BUILDDIR) mkdir $(BUILDDIR)
else
mkdir -p $(BUILDDIR)
endif
$(TEMPDIR):
ifeq ($(OS),Windows_NT)
if not exist $(TEMPDIR) mkdir $(TEMPDIR)
if not exist $(TEMPDIR)\standard_libraries mkdir $(TEMPDIR)\standard_libraries
else
mkdir -p $(TEMPDIR)
mkdir -p $(TEMPDIR)/standard_libraries
endif
clean:
ifeq ($(OS),Windows_NT)
rmdir /s /q $(TEMPDIR)
else
rm -rf $(TEMPDIR)
endif
run: $(TARGET)
./$(TARGET)
.PHONY: all clean run lib