Files
CS-LABS/mine/lab_4/kirill's/Makefile
2025-12-10 16:50:28 +07:00

100 lines
3.5 KiB
Makefile
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Makefile for lab 4 - FIFO (named pipes) only
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
# Default target - build FIFO programs
all: fifo
# ===== FIFO targets =====
fifo: fifo_server fifo_client
fifo_server: fifo_server.c
$(CC) $(CFLAGS) -o $@ $<
fifo_client: fifo_client.c
$(CC) $(CFLAGS) -o $@ $<
# ===== Test files =====
test_files:
@echo "Создание тестовых файлов..."
echo "abbaabbaabbaabbaabbaabbaabbaabba" > input1.txt
echo "xyzxyzxyzxyzxyzxyzxyzxyz" >> input1.txt
echo "hello world hello" >> input1.txt
echo "testtest" > input2.txt
echo "aaaaaaa" >> input2.txt
echo "programming" > input3.txt
echo "ppppython" >> input3.txt
# ===== FIFO tests =====
test_fifo_server: fifo test_files
@echo "=== Запуск FIFO сервера ==="
@echo "В другом терминале выполните: make test_fifo_client"
./fifo_server 10
test_fifo_client: fifo test_files
@echo "=== Запуск FIFO клиента ===" & \
./fifo_client input1.txt output1_fifo.txt; \
./fifo_client input2.txt output2_fifo.txt; \
./fifo_client input3.txt output3_fifo.txt;
@echo "\n=== Результаты FIFO ==="
@echo "--- output1_fifo.txt ---"
@cat output1_fifo.txt || true
@echo "\n--- output2_fifo.txt ---"
@cat output2_fifo.txt || true
@echo "\n--- output3_fifo.txt ---"
@cat output3_fifo.txt || true
# Automatic FIFO test (server in background)
test_all: fifo test_files
@echo "=== Автоматический тест FIFO ==="
@./fifo_server 10 & \
SERVER_PID=$$!; \
sleep 1; \
./fifo_client input1.txt output1_fifo.txt; \
./fifo_client input2.txt output2_fifo.txt; \
./fifo_client input3.txt output3_fifo.txt; \
kill $$SERVER_PID 2>/dev/null || true; \
wait $$SERVER_PID 2>/dev/null || true
@echo "\n=== Результаты FIFO ==="
@echo "--- output1_fifo.txt ---"
@cat output1_fifo.txt || true
@echo "\n--- output2_fifo.txt ---"
@cat output2_fifo.txt || true
@echo "\n--- output3_fifo.txt ---"
@cat output3_fifo.txt || true
# Error handling test for FIFO
test_error: fifo
@echo "\n=== Тест обработки ошибки (несуществующий файл) - FIFO ==="
@./fifo_server 5 & \
SERVER_PID=$$!; \
sleep 1; \
./fifo_client nonexistent.txt output_error.txt || true; \
kill $$SERVER_PID 2>/dev/null || true; \
wait $$SERVER_PID 2>/dev/null || true
# Cleanup
clean:
@echo "Очистка..."
rm -f fifo_server fifo_client
rm -f input1.txt input2.txt input3.txt
rm -f output*.txt
rm -f /tmp/fifo_request /tmp/fifo_response
# Help
help:
@echo "Доступные цели:"
@echo " all - Скомпилировать FIFO программы"
@echo " fifo - Скомпилировать fifo_server и fifo_client"
@echo " test_files - Создать тестовые входные файлы"
@echo " test_fifo_server - Запустить FIFO сервер (использовать с клиентом в другом терминале)"
@echo " test_fifo_client - Запустить FIFO клиент и показать результат"
@echo " test_fifo_auto - Автоматический тест FIFO (сервер в фоне)"
@echo " test_all - Запустить все тесты (FIFO)"
@echo " test_error_fifo - Тест обработки ошибок (несуществующий файл)"
@echo " clean - Удалить скомпилированные файлы и тесты"
.PHONY: all fifo test_files test_fifo_server test_fifo_client test_all \
test_error clean help