-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
107 lines (80 loc) · 3.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
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
104
105
106
107
SHELL=/bin/sh
CC = gcc
LINK ?= $(CC)
DLL_EXT ?= .so
top_src_dir = .
top_build_dir = build
vpath %.c $(top_src_dir)/src
vpath %.h $(top_src_dir)/include
variant = debug
build_dir = $(top_build_dir)/$(variant)
pass_dir = $(top_build_dir)/$(variant)/passes
libstats_dir = $(top_build_dir)/stats
# set compile flags
CFLAGS += -Wall -g
# set link flags
LINK_FLAGS += $(FIRM_LIBS)
passes_SOURCES = $(wildcard $(top_src_dir)/src/passes/*.c)
passes_OBJECTS = $(patsubst %.c,%.o,$(passes_SOURCES))
passes_OBJS = $(wildcard $(pass_dir)/obj/*.o)
passes_DLL =$(patsubst %.o,%.so,$(passes_OBJS))
pass_util_SRC = $(top_src_dir)/src/pass_utils.c
pass_util_INCLUDE_FLAGS = -I$(top_src_dir)/include/
pass_util_OBJ = $(pass_dir)/pass_utils.o
firmreduce_SOURCES = $(top_src_dir)/src/main.c $(top_src_dir)/src/passes.c $(top_src_dir)/src/logging.c
firmreduce_OBJECTS = $(firmreduce_SOURCES:%.c=%(build_dir)/%.o)
firmreduce_DEPENDS = $(firmreduce_OBJECTS:%.o=%.d)
firmreduce_TARGET = $(build_dir)/firmreduce
firmreduce_INCLUDE_FLAGS = -I$(top_src_dir)/include
libstats_SRC = $(top_src_dir)/src/ir_stats.c
libstats_INCLUDE_FLAGS = -I$(top_src_dir)/include
libstats_OBJ = $(libstats_dir)
libstats_TARGET = $(build_dir)/libstats
libfirm_HOME = $(top_src_dir)/libfirm
libfirm_INCLUDE_FLAGS = -I$(libfirm_HOME)/include -I$(libfirm_HOME)/include/libfirm -I$(libfirm_HOME)/build/gen/include/libfirm
libfirm_STATIC = $(libfirm_HOME)/build/$(variant)/libfirm.a
libfirm_STATIC_PATH = -L$(libfirm_HOME)/build/$(variant)/libfirm
libfirm_DYNAMIC_PATH = $(libfirm_HOME)/build/$(variant)/libfirm
libfirm_DYNAMIC = $(libfirm_HOME)/build/$(variant)/libfirm.$(DLL_EXT)
# include headers
SYSTEM_INCLUDE ?= /usr/include
LOCAL_INCLUDE ?= /usr/local/include
# clear implicit suffix rules
.SUFFIXES:
.PHONY: all clean clean-all makedir passes libstats install uninstall
all: makedir libstats $(firmreduce_TARGET) passes
@echo Target make all complete
makedir:
@mkdir -p $(pass_dir)/obj
@mkdir -p $(pass_dir)/exe
@mkdir -p $(build_dir)
@mkdir -p $(libstats_dir)
libstats: makedir $(libfirm_STATIC)
@$(CC) -o $(libstats_TARGET) $(libstats_SRC) $(libstats_INCLUDE_FLAGS) $(libfirm_INCLUDE_FLAGS) $(libfirm_STATIC_PATH) $(libfirm_STATIC) -lm -ldl
$(firmreduce_TARGET): $(firmreduce_SOURCES)
@echo Build firmreduce
@$(CC) $(CFLAGS) -o $@ $(firmreduce_SOURCES) $(firmreduce_INCLUDE_FLAGS) -ldl
$(libfirm_STATIC):
@cd libfirm && make
clean:
@$(Q)rm -rf $(top_build_dir)/*
@echo Target make clean done
clean-all: clean
@cd libfirm && make clean
passes: makedir $(passes_OBJECTS)
@echo Target make passes complete
%.o: %.c
@$(CC) -c $(CFLAGS) $(pass_util_SRC) $(libfirm_INCLUDE_FLAGS) $(pass_util_INCLUDE_FLAGS) -o $(pass_util_OBJ)
@$(CC) -c $(CFLAGS) $< $(pass_util_INCLUDE_FLAGS) $(libfirm_INCLUDE_FLAGS) -o $(pass_dir)/obj/$(notdir $@)
@$(CC) -o $(pass_dir)/exe/$(basename $(notdir $<)) $(pass_dir)/obj/$(basename $(notdir $<)).o $(pass_util_OBJ) $(libfirm_STATIC_PATH) $(libfirm_STATIC) -lm -ldl
@echo Build $(basename $(notdir $<))
INSTALL_PREFIX = /usr/local/bin/
install: all
@install $(firmreduce_TARGET) "$(INSTALL_PREFIX)firmreduce"
@install -d $(pass_dir) "$(INSTALL_PREFIX)passes"
@install $(pass_dir)/exe/* "$(INSTALL_PREFIX)passes"
@install $(libstats_TARGET) "$(INSTALL_PREFIX)libstats"
@echo "Target install complete"
uninstall: clean-all
@rm -r $(INSTALL_PREFIX)firmreduce $(INSTALL_PREFIX)libstats $(INSTALL_PREFIX)passes
@echo Target uninstall complete