Adds more things.
This commit is contained in:
48
Makefile
Normal file
48
Makefile
Normal file
@@ -0,0 +1,48 @@
|
||||
include config.mk
|
||||
|
||||
all: $(TARGET)
|
||||
|
||||
release: clean
|
||||
release: CFLAGS = -Wall -O2
|
||||
release: $(TARGET)
|
||||
|
||||
# Run the target.
|
||||
run: $(TARGET)
|
||||
./$(TARGET)
|
||||
|
||||
# Generate grammars with bison.
|
||||
$(GRAM_FILES): $(SRC_DIR)/grammar.y
|
||||
@ mkdir -p $(GRAM_DIR)
|
||||
@ $(PRINT) "$(WHITE_BOLD)Generating grammars...$(RESETCOLOR)"
|
||||
$(BISON) $< -o$(GRAM_DIR)/grammar.tab.c -H$(GRAM_DIR)/grammar.tab.h
|
||||
|
||||
# Compile grammars.
|
||||
$(OBJ_DIR)/grammar.o: $(GRAM_DIR)/grammar.tab.c $(GRAM_DIR)/grammar.tab.h $(OBJ_DIR)/lexer.o
|
||||
@ $(PRINT) "$(WHITE_BOLD)Compiling grammars...$(RESETCOLOR)"
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Lexer depends on grammars.
|
||||
$(OBJ_DIR)/lexer.o: $(SRC_DIR)/lexer.c $(GRAM_FILES)
|
||||
@ mkdir -p $(OBJ_DIR)
|
||||
@ $(PRINT) "$(WHITE_BOLD)Compiling source object $(WHITE)$@$(WHITE_BOLD)... $(RESETCOLOR)"
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Compile project source objects.
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(INC_DIR)/%.h
|
||||
@ mkdir -p $(OBJ_DIR)
|
||||
@ $(PRINT) "$(WHITE_BOLD)Compiling source object $(WHITE)$@$(WHITE_BOLD)... $(RESETCOLOR)"
|
||||
$(CC) $(CFLAGS) -c $< -o $@
|
||||
|
||||
# Link to final binary.
|
||||
$(TARGET): $(OBJ_DIR)/grammar.o $(OBJ_FILES)
|
||||
@ $(PRINT) "$(WHITE_BOLD)Linking $(WHITE)$@$(WHITE_BOLD)...$(RESETCOLOR)"
|
||||
$(LINK) -o $(TARGET) $(OBJ_FILES) $(OBJ_DIR)/grammar.o $(LDFLAGS)
|
||||
|
||||
clean:
|
||||
@ $(PRINT) "$(WHITE_BOLD)Cleaning up...$(RESETCOLOR)"
|
||||
rm -rf $(OBJ_DIR)/*.o $(TARGET) $(GRAM_DIR)/*
|
||||
|
||||
lines:
|
||||
@ wc -l $(SRC_FILES) $(INC_FILES) $(GRAM_SRC)
|
||||
|
||||
.PHONY: all clean release run lines
|
Reference in New Issue
Block a user