CC = gcc CFLAGS = -Wall -Wextra -std=c99 -g LDFLAGS_MQ = -lrt # POSIX message queues on Linux TEST_INPUT = test_input.txt TEST_OUTPUT = test_output.txt all: msg # ===== POSIX MQ targets ===== msg: mq_server mq_client mq_server: server.c $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_MQ) mq_client: client.c $(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_MQ) # ===== Ручные тесты ===== test_server: msg @echo "=== Запуск MQ сервера ===" @echo "В другом терминале выполните: make test_client_manual" ./mq_server test_client_manual: msg @echo "=== Запуск MQ клиента (ручной тест) ===" ./mq_client $(TEST_INPUT) $(TEST_OUTPUT) # ===== Автотест: сервер в фоне + клиент ===== test_all: msg @echo "=== Автотест MQ (server + client) ===" @echo "Создание тестового входного файла..." echo "aabbccddeeff" > $(TEST_INPUT) @echo "Старт сервера в фоне..." ./mq_server & \ SRV=$$!; \ sleep 1; \ echo "Запуск клиента..."; \ ./mq_client $(TEST_INPUT) $(TEST_OUTPUT); \ echo "Остановка сервера..."; \ kill $$SRV || true; \ wait $$SRV 2>/dev/null || true; \ echo "=== Содержимое $(TEST_OUTPUT) ==="; \ cat $(TEST_OUTPUT) clean: @echo "Очистка..." rm -f mq_server mq_client *.o $(TEST_INPUT) $(TEST_OUTPUT) help: @echo "Available targets:" @echo " msg - Build POSIX MQ programs" @echo " test_server - Run MQ server (client separately)" @echo " test_client_manual- Run client (server must be running)" @echo " test_all - Automatic end-to-end test (server+client)" @echo " clean - Remove built and test files" @echo " help - Show this help" .PHONY: all msg test_server test_client_manual test_all clean help