2022-10-26 18:52:14 +02:00
|
|
|
# TRAGET may be "x86_64" or "x86" or "aarch64"
|
|
|
|
TARGET = x86_64
|
|
|
|
# BUILD can be "debug" or "release"
|
|
|
|
BUILD = debug
|
|
|
|
BUILD_DIR = .
|
|
|
|
SRC_DIR = .
|
|
|
|
|
2022-04-05 23:19:23 +02:00
|
|
|
CC = gcc
|
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
|
2022-04-05 23:19:23 +02:00
|
|
|
LDFLAGS = -lm
|
|
|
|
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))
|
|
|
|
CC= gcc -m32
|
|
|
|
CFLAGS += -DIR_TARGET_X86
|
|
|
|
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-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 \
|
|
|
|
$(BUILD_DIR)/ir_disasm.o $(BUILD_DIR)/ir_gdb.o $(BUILD_DIR)/ir_perf.o $(BUILD_DIR)/ir_check.o
|
2023-02-08 01:28:36 +01:00
|
|
|
OBJS_IR = $(BUILD_DIR)/ir_main.o
|
|
|
|
OBJS_IR_TEST = $(BUILD_DIR)/ir_test.o
|
|
|
|
|
|
|
|
all: $(BUILD_DIR) $(BUILD_DIR)/ir $(BUILD_DIR)/ir_test
|
|
|
|
|
|
|
|
$(BUILD_DIR):
|
|
|
|
@mkdir -p $(BUILD_DIR)
|
|
|
|
|
|
|
|
$(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
|
|
|
|
2022-10-26 18:52:14 +02:00
|
|
|
test: $(BUILD_DIR)/ir
|
|
|
|
$(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
|
|
|
|
BUILD_DIR=$(BUILD_DIR) SRC_DIR=$(SRC_DIR) $(PHP) $(SRC_DIR)/ir-test.php
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2022-11-19 16:26:16 +01:00
|
|
|
test-ci: $(BUILD_DIR)/ir
|
|
|
|
BUILD_DIR=$(BUILD_DIR) SRC_DIR=$(SRC_DIR) $(PHP) $(SRC_DIR)/ir-test.php --show-diff
|
|
|
|
|
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 \
|
|
|
|
$(BUILD_DIR)/ir.dot $(BUILD_DIR)/ir.pdf $(BUILD_DIR)/test.log
|
|
|
|
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
|