100 lines
3.2 KiB
Makefile
100 lines
3.2 KiB
Makefile
# 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 "Available targets:"
|
||
@echo " all - Build FIFO programs"
|
||
@echo " fifo - Compile fifo_server and fifo_client"
|
||
@echo " test_files - Create test input files"
|
||
@echo " test_fifo_server - Run FIFO server (use client in another terminal)"
|
||
@echo " test_fifo_client - Run FIFO client and show results"
|
||
@echo " test_all - Automatic FIFO test (server in background)"
|
||
@echo " test_error - Error handling test (nonexistent file)"
|
||
@echo " clean - Remove built files and test files"
|
||
@echo " help - Show this help"
|
||
|
||
.PHONY: all fifo test_files test_fifo_server test_fifo_client test_all \
|
||
test_error clean help
|