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 = .
|
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
|
2022-10-26 18:52:14 +02:00
|
|
|
BUILD_CC = gcc
|
2023-09-26 09:57:55 +02:00
|
|
|
override 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))
|
2023-09-26 09:57:55 +02:00
|
|
|
override CFLAGS += -O0 -g -DIR_DEBUG=1
|
2022-10-26 18:52:14 +02:00
|
|
|
endif
|
|
|
|
ifeq (release, $(BUILD))
|
2023-09-26 09:57:55 +02:00
|
|
|
override CFLAGS += -O2 -g
|
2022-10-26 18:52:14 +02:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq (x86_64, $(TARGET))
|
2023-09-26 09:57:55 +02:00
|
|
|
override CFLAGS += -DIR_TARGET_X64
|
2022-10-26 18:52:14 +02:00
|
|
|
DASM_ARCH = x86
|
2023-07-26 21:05:01 +02:00
|
|
|
DASM_FLAGS = -M -D X64=1
|
2022-10-26 18:52:14 +02:00
|
|
|
endif
|
|
|
|
ifeq (x86, $(TARGET))
|
2023-09-26 09:57:55 +02:00
|
|
|
override CFLAGS += -m32 -DIR_TARGET_X86
|
2022-10-26 18:52:14 +02:00
|
|
|
DASM_ARCH = x86
|
2023-07-26 21:05:01 +02:00
|
|
|
DASM_FLAGS = -M
|
2022-10-26 18:52:14 +02:00
|
|
|
endif
|
|
|
|
ifeq (aarch64, $(TARGET))
|
2022-10-26 20:26:24 +02:00
|
|
|
CC= aarch64-linux-gnu-gcc --sysroot=$(HOME)/php/ARM64
|
2023-09-26 09:57:55 +02:00
|
|
|
override CFLAGS += -DIR_TARGET_AARCH64
|
2022-10-26 18:52:14 +02:00
|
|
|
DASM_ARCH = aarch64
|
2023-07-26 21:05:01 +02:00
|
|
|
DASM_FLAGS = -M
|
2022-10-26 18:52:14 +02:00
|
|
|
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 \
|
2023-09-28 19:44:45 +02:00
|
|
|
$(BUILD_DIR)/ir_cpuinfo.o $(BUILD_DIR)/ir_emit_llvm.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-29 21:07:01 +02:00
|
|
|
EXAMPLE_EXES = $(EXAMPLES_BUILD_DIR)/0001-basic $(EXAMPLES_BUILD_DIR)/0001-while $(EXAMPLES_BUILD_DIR)/0005-basic-runner-func \
|
2023-07-02 18:39:30 +02:00
|
|
|
$(EXAMPLES_BUILD_DIR)/0001-pointer $(EXAMPLES_BUILD_DIR)/0001-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
|
2023-07-04 09:03:33 +02:00
|
|
|
$(BUILD_DIR)/gen_ir_fold_hash: $(SRC_DIR)/gen_ir_fold_hash.c $(SRC_DIR)/ir_strtab.c $(SRC_DIR)/ir.h
|
2023-08-30 14:24:12 +02:00
|
|
|
$(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-09-26 23:34:03 +02:00
|
|
|
$(BUILD_DIR)/tester: $(SRC_DIR)/tools/tester.c
|
|
|
|
$(CC) $(CFLAGS) -o $@ $<
|
2023-03-08 00:06:54 +01:00
|
|
|
|
2023-09-26 23:34:03 +02:00
|
|
|
test: $(BUILD_DIR)/ir $(BUILD_DIR)/tester
|
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-09-26 23:34:03 +02:00
|
|
|
$(BUILD_DIR)/tester --test-cmd $(BUILD_DIR)/ir --target $(TARGET) --default-args "--save" \
|
|
|
|
--test-extension ".irt" --code-extension ".ir" $(SRC_DIR)/tests
|
2022-04-05 23:19:23 +02:00
|
|
|
|
2023-09-26 23:34:03 +02:00
|
|
|
test-ci: $(BUILD_DIR)/ir $(BUILD_DIR)/tester
|
|
|
|
$(BUILD_DIR)/tester --test-cmd $(BUILD_DIR)/ir --target $(TARGET) --default-args "--save" \
|
|
|
|
--test-extension ".irt" --code-extension ".ir" --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 \
|
2023-09-26 23:34:03 +02:00
|
|
|
$(BUILD_DIR)/tester
|
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
|