2023-06-01 22:03:15 +02:00
|
|
|
# TRAGET may be "x86_64" or "x86" or "aarch64" or "riscv64"
|
|
|
|
TARGET = riscv64
|
2022-10-26 18:52:14 +02:00
|
|
|
# BUILD can be "debug" or "release"
|
|
|
|
BUILD = debug
|
|
|
|
BUILD_DIR = .
|
|
|
|
SRC_DIR = .
|
2023-04-26 01:47:47 +02:00
|
|
|
EXAMPLES_SRC_DIR = $(SRC_DIR)/examples
|
|
|
|
EXAMPLES_BUILD_DIR = $(BUILD_DIR)/examples
|
2022-10-26 18:52:14 +02:00
|
|
|
|
2022-04-05 23:19:23 +02:00
|
|
|
CC = gcc
|
2023-03-08 00:06:54 +01:00
|
|
|
CXX = g++
|
2022-10-26 18:52:14 +02:00
|
|
|
BUILD_CC = gcc
|
2022-11-08 21:09:35 +01:00
|
|
|
CFLAGS = -Wall -Wextra -Wno-unused-parameter
|
2023-05-05 09:22:31 +02:00
|
|
|
LDFLAGS = -lm -ldl
|
2022-04-05 23:19:23 +02:00
|
|
|
PHP = php
|
2022-10-26 20:26:24 +02:00
|
|
|
LLK = llk
|
|
|
|
#LLK = $(PHP) $(HOME)/php/llk/llk.php
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2022-10-26 18:52:14 +02:00
|
|
|
ifeq (debug, $(BUILD))
|
|
|
|
CFLAGS += -O0 -g -DIR_DEBUG=1
|
|
|
|
endif
|
|
|
|
ifeq (release, $(BUILD))
|
|
|
|
CFLAGS += -O2 -g
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq (x86_64, $(TARGET))
|
|
|
|
CFLAGS += -DIR_TARGET_X64
|
|
|
|
DASM_ARCH = x86
|
|
|
|
DASM_FLAGS = -D X64=1
|
|
|
|
endif
|
|
|
|
ifeq (x86, $(TARGET))
|
2023-03-28 12:20:54 +02:00
|
|
|
CFLAGS += -m32 -DIR_TARGET_X86
|
2022-10-26 18:52:14 +02:00
|
|
|
DASM_ARCH = x86
|
|
|
|
DASM_FLAGS =
|
|
|
|
endif
|
|
|
|
ifeq (aarch64, $(TARGET))
|
2022-10-26 20:26:24 +02:00
|
|
|
CC= aarch64-linux-gnu-gcc --sysroot=$(HOME)/php/ARM64
|
2022-10-26 18:52:14 +02:00
|
|
|
CFLAGS += -DIR_TARGET_AARCH64
|
|
|
|
DASM_ARCH = aarch64
|
|
|
|
DASM_FLAGS =
|
|
|
|
endif
|
|
|
|
|
2023-06-01 22:03:15 +02:00
|
|
|
ifeq (riscv64, $(TARGET))
|
|
|
|
CC= riscv64-linux-gnu-gcc --sysroot=$(HOME)/php/RISCV64
|
|
|
|
CFLAGS += -DIR_TARGET_RISCV64
|
|
|
|
DASM_ARCH = riscv64
|
|
|
|
DASM_FLAGS =
|
|
|
|
endif
|
|
|
|
|
2023-02-08 01:28:36 +01:00
|
|
|
OBJS_COMMON = $(BUILD_DIR)/ir.o $(BUILD_DIR)/ir_strtab.o $(BUILD_DIR)/ir_cfg.o \
|
2022-10-26 21:06:07 +02:00
|
|
|
$(BUILD_DIR)/ir_sccp.o $(BUILD_DIR)/ir_gcm.o $(BUILD_DIR)/ir_ra.o $(BUILD_DIR)/ir_emit.o \
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/ir_load.o $(BUILD_DIR)/ir_save.o $(BUILD_DIR)/ir_emit_c.o $(BUILD_DIR)/ir_dump.o \
|
2023-04-10 03:02:35 +02:00
|
|
|
$(BUILD_DIR)/ir_disasm.o $(BUILD_DIR)/ir_gdb.o $(BUILD_DIR)/ir_perf.o $(BUILD_DIR)/ir_check.o \
|
|
|
|
$(BUILD_DIR)/ir_cpuinfo.o
|
2023-02-08 01:28:36 +01:00
|
|
|
OBJS_IR = $(BUILD_DIR)/ir_main.o
|
|
|
|
OBJS_IR_TEST = $(BUILD_DIR)/ir_test.o
|
2023-05-18 22:41:14 +02:00
|
|
|
EXAMPLE_EXES = $(EXAMPLES_BUILD_DIR)/0001-basic $(EXAMPLES_BUILD_DIR)/0001-while $(EXAMPLES_BUILD_DIR)/0005-basic-runner-func
|
2023-02-08 01:28:36 +01:00
|
|
|
|
|
|
|
all: $(BUILD_DIR) $(BUILD_DIR)/ir $(BUILD_DIR)/ir_test
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
|
|
|
@mkdir -p $(BUILD_DIR)
|
|
|
|
|
2023-04-26 01:47:47 +02:00
|
|
|
$(EXAMPLES_BUILD_DIR):
|
|
|
|
@mkdir -p $(EXAMPLES_BUILD_DIR)
|
|
|
|
|
2023-02-08 01:28:36 +01:00
|
|
|
$(BUILD_DIR)/ir: $(OBJS_COMMON) $(OBJS_IR)
|
2022-11-19 16:26:16 +01:00
|
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lcapstone
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2023-02-08 01:28:36 +01:00
|
|
|
$(BUILD_DIR)/ir_test: $(OBJS_COMMON) $(OBJS_IR_TEST)
|
2022-11-19 16:26:16 +01:00
|
|
|
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) -lcapstone
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2023-03-02 22:03:50 +01:00
|
|
|
$(OBJS_COMMON): $(SRC_DIR)/ir.h $(SRC_DIR)/ir_private.h
|
|
|
|
|
|
|
|
$(BUILD_DIR)/ir_main.o: $(SRC_DIR)/ir.h
|
|
|
|
$(BUILD_DIR)/ir_test.o: $(SRC_DIR)/ir.h $(SRC_DIR)/ir_builder.h
|
2023-02-08 01:28:36 +01:00
|
|
|
$(BUILD_DIR)/ir.o: $(SRC_DIR)/ir_fold.h $(BUILD_DIR)/ir_fold_hash.h
|
2023-03-02 22:03:50 +01:00
|
|
|
$(BUILD_DIR)/ir_ra.o: $(SRC_DIR)/ir_$(DASM_ARCH).h
|
|
|
|
$(BUILD_DIR)/ir_emit.o: $(SRC_DIR)/ir_$(DASM_ARCH).h $(BUILD_DIR)/ir_emit_$(DASM_ARCH).h
|
|
|
|
$(BUILD_DIR)/ir_gdb.o: $(SRC_DIR)/ir_elf.h
|
|
|
|
$(BUILD_DIR)/ir_perf.o: $(SRC_DIR)/ir_elf.h
|
|
|
|
$(BUILD_DIR)/ir_disasm.o: $(SRC_DIR)/ir_elf.h
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2022-10-26 18:52:14 +02:00
|
|
|
$(SRC_DIR)/ir_load.c: $(SRC_DIR)/ir.g
|
2022-10-26 20:26:24 +02:00
|
|
|
$(LLK) ir.g
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/ir_fold_hash.h: $(BUILD_DIR)/gen_ir_fold_hash $(SRC_DIR)/ir_fold.h $(SRC_DIR)/ir.h
|
|
|
|
$(BUILD_DIR)/gen_ir_fold_hash < $(SRC_DIR)/ir_fold.h > $(BUILD_DIR)/ir_fold_hash.h
|
|
|
|
$(BUILD_DIR)/gen_ir_fold_hash: $(SRC_DIR)/gen_ir_fold_hash.c $(SRC_DIR)/ir_strtab.c
|
|
|
|
$(BUILD_CC) $(CFLAGS) $(LDFALGS) -o $@ $^
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/minilua: $(SRC_DIR)/dynasm/minilua.c
|
|
|
|
$(BUILD_CC) $(SRC_DIR)/dynasm/minilua.c -lm -o $@
|
2022-10-26 21:06:07 +02:00
|
|
|
$(BUILD_DIR)/ir_emit_$(DASM_ARCH).h: $(SRC_DIR)/ir_$(DASM_ARCH).dasc $(SRC_DIR)/dynasm/*.lua $(BUILD_DIR)/minilua
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/minilua $(SRC_DIR)/dynasm/dynasm.lua $(DASM_FLAGS) -o $@ $(SRC_DIR)/ir_$(DASM_ARCH).dasc
|
2023-02-08 01:28:36 +01:00
|
|
|
|
|
|
|
$(OBJS_COMMON) $(OBJS_IR) $(OBJS_IR_TEST): $(BUILD_DIR)/$(notdir %.o): $(SRC_DIR)/$(notdir %.c)
|
2022-10-26 21:06:07 +02:00
|
|
|
$(CC) $(CFLAGS) -I$(BUILD_DIR) -o $@ -c $<
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2023-04-26 01:47:47 +02:00
|
|
|
$(EXAMPLE_EXES): $(EXAMPLES_BUILD_DIR)/$(notdir %): $(EXAMPLES_SRC_DIR)/$(notdir %.c)
|
2023-05-23 09:24:27 +02:00
|
|
|
$(CC) $(CFLAGS) -I$(SRC_DIR) $< -o $@ $(OBJS_COMMON) $(LDFLAGS) -lcapstone
|
2023-04-26 01:47:47 +02:00
|
|
|
|
2023-03-08 00:06:54 +01:00
|
|
|
$(BUILD_DIR)/ir-test: $(SRC_DIR)/ir-test.cxx
|
|
|
|
$(CXX) -O3 -std=c++17 $(SRC_DIR)/ir-test.cxx -o $(BUILD_DIR)/ir-test
|
|
|
|
|
|
|
|
test: $(BUILD_DIR)/ir $(BUILD_DIR)/ir-test
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/ir $(SRC_DIR)/test.ir --dump --save 2>$(BUILD_DIR)/test.log
|
|
|
|
$(BUILD_DIR)/ir $(SRC_DIR)/test.ir --dot $(BUILD_DIR)/ir.dot
|
|
|
|
dot -Tpdf $(BUILD_DIR)/ir.dot -o $(BUILD_DIR)/ir.pdf
|
2023-04-17 09:13:05 +02:00
|
|
|
$(BUILD_DIR)/ir-test $(SRC_DIR)/tests
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2023-03-08 00:06:54 +01:00
|
|
|
test-ci: $(BUILD_DIR)/ir $(BUILD_DIR)/ir-test
|
2023-04-17 09:13:05 +02:00
|
|
|
$(BUILD_DIR)/ir-test --show-diff $(SRC_DIR)/tests
|
2022-11-19 16:26:16 +01:00
|
|
|
|
2023-04-26 01:47:47 +02:00
|
|
|
examples: $(OBJS_COMMON) $(EXAMPLES_BUILD_DIR) $(EXAMPLE_EXES)
|
|
|
|
|
2022-04-05 23:19:23 +02:00
|
|
|
clean:
|
2022-10-26 18:52:14 +02:00
|
|
|
rm -rf $(BUILD_DIR)/ir $(BUILD_DIR)/ir_test $(BUILD_DIR)/*.o \
|
2022-10-26 21:06:07 +02:00
|
|
|
$(BUILD_DIR)/minilua $(BUILD_DIR)/ir_emit_$(DASM_ARCH).h \
|
2022-10-26 18:52:14 +02:00
|
|
|
$(BUILD_DIR)/ir_fold_hash.h $(BUILD_DIR)/gen_ir_fold_hash \
|
2023-03-08 00:06:54 +01:00
|
|
|
$(BUILD_DIR)/ir.dot $(BUILD_DIR)/ir.pdf $(BUILD_DIR)/test.log \
|
|
|
|
$(BUILD_DIR)/ir-test
|
2022-10-26 18:52:14 +02:00
|
|
|
find $(SRC_DIR)/tests -type f -name '*.diff' -delete
|
|
|
|
find $(SRC_DIR)/tests -type f -name '*.out' -delete
|
|
|
|
find $(SRC_DIR)/tests -type f -name '*.exp' -delete
|
|
|
|
find $(SRC_DIR)/tests -type f -name '*.ir' -delete
|