asm_parser/Makefile
2024-10-31 13:11:08 +08:00

62 lines
1.4 KiB
Makefile

CC = gcc
CFLAGS = -Wall -Wextra -I. -g
SRC_ASSEMBLER = assembler.c
SRC_ASM_PARSER = asm_parser.c
OBJ_ASM_PARSER = asm_parser.o
TARGET = assembler
VALID_DIR = test_case/valid
INVALID_DIR = test_case/invalid
VALID_ASM_FILES := $(wildcard $(VALID_DIR)/*.asm)
INVALID_ASM_FILES := $(wildcard $(INVALID_DIR)/*.asm)
VALID_OBJ_FILES := $(VALID_ASM_FILES:.asm=.obj)
all: $(TARGET)
assembler: $(OBJ_ASM_PARSER) $(SRC_ASSEMBLER)
$(CC) $(CFLAGS) -o $(TARGET) $(OBJ_ASM_PARSER) $(SRC_ASSEMBLER)
asm_parser.o: $(SRC_ASM_PARSER)
$(CC) $(CFLAGS) -c $(SRC_ASM_PARSER)
test-valid: $(TARGET)
@for file in $(VALID_ASM_FILES); do \
echo "Testing valid case $$file..."; \
if ./$(TARGET) $$file 0; then \
echo "Assembler completed $$file"; \
else \
echo "Assembler reported an error for $$file"; \
fi \
done
@echo "All valid test cases assembled successfully."
test-invalid: $(TARGET)
@for file in $(INVALID_ASM_FILES); do \
echo "Testing invalid case $$file..."; \
if ./$(TARGET) $$file 2 > null; then \
echo "Error: Assembler did not report an error for $$file"; \
exit 1; \
else \
echo "Assembler correctly reported an error for $$file"; \
fi \
done
test: $(TARGET) test-valid test-invalid
@echo "All tests completed."
clean:
rm -f $(OBJ_ASM_PARSER)
clobber: clean
rm -f $(TARGET)
rm -f *~
rm -f *.bak
rm -f *.tmp
rm -f *.o
rm -f *.obj
rm -f core
rm -f $(VALID_OBJ_FILES)
.PHONY: all clean clobber