-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
73 lines (50 loc) · 1.25 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
NAME = HeliosXEmulator
INC_DIR += ./include
BUILD_DIR ?= ./build
OBJ_DIR ?= $(BUILD_DIR)/obj
BINARY ?= $(BUILD_DIR)/$(NAME)
PLATFORM ?= MACOS
.DEFAULT_GOAL = app
# Compilation flags
CC = gcc
LD = gcc
INCLUDES = $(addprefix -I, $(INC_DIR))
# CFLAGS += -O2 -MMD -Wall -Werror -ggdb3 $(INCLUDES)
# CFLAGS += -O2 -MMD -ggdb3 $(INCLUDES)
CFLAGS += -O2 -fPIC -MMD -ggdb3 $(INCLUDES)
# Files to be compiled
SRCS = $(shell find src/ -name "*.c" | grep -v "src/main.c")
# SRCS = $(shell find src/ -name "*.c")
OBJS = $(SRCS:src/%.c=$(OBJ_DIR)/%.o)
# Compilation patterns
$(OBJ_DIR)/%.o: src/%.c
@echo + CC $<
@mkdir -p $(dir $@)
@$(CC) $(CFLAGS) -c -o $@ $<
# Depencies
-include $(OBJS:.o=.d)
# Some convenient rules
.PHONY: app run gdb clean run-env
app: $(BINARY)
IMG :=
HEMU_EXEC := $(BINARY) $(ARGS) $(IMG)
$(BINARY): $(OBJS)
@echo + LD $@
@$(LD) -O2 -o $@ $^
run-env: $(BINARY)
run: run-env
$(HEMU_EXEC)
gdb: run-env
gdb -s $(BINARY) --args $(HEMU_EXEC)
$(BINARY).so: $(OBJS)
@echo + LD $@
@$(LD) -O2 -rdynamic -shared -fPIC -o $@ $^
@cp $(BINARY).so $(BUILD_DIR)/lib$(NAME).so
$(BINARY).a: $(OBJS)
@echo + AR $@
@ar rcs $@ $^
@mv $(BINARY).a $(BUILD_DIR)/lib$(NAME).a
shared: $(BINARY).so
static: $(BINARY).a
clean:
-rm -rf $(BUILD_DIR)