Files
CS-LABS/lab_6/Makefile
2025-12-10 14:23:02 +07:00

62 lines
2.0 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.
CC = gcc
CFLAGS = -Wall -Wextra -std=c99 -g
LDFLAGS_IPC = -lrt -pthread
# SHM/SEM args: <shm_name> <sem_client_name> <sem_server_name> [iterations]
SHM_NAME = /myshm
SEM_CLIENT_NAME = /sem_client
SEM_SERVER_NAME = /sem_server
SERVER_ITERS = 3
all: shm
# ===== POSIX SHM + SEM targets =====
shm: server client
server: server.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_IPC)
client: client.c
$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS_IPC)
# ===== Tests =====
test_server: shm
@echo "=== Запуск сервера POSIX SHM+SEM ==="
@echo "В другом терминале выполните: make test_clients"
./server $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) $(SERVER_ITERS)
test_clients: shm
@echo "=== Запуск нескольких клиентов ==="
echo "abacaba" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
echo "xxxxxx" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
echo "hello world" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
wait
# Автотест: сервер в фоне, несколько клиентов
test_all: shm
@echo "=== Автотест POSIX SHM+SEM ==="
./server $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) $(SERVER_ITERS) & \
SRV=$$!; \
sleep 1; \
echo "abacaba" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
echo "kekekek" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
echo "foobar" | ./client $(SHM_NAME) $(SEM_CLIENT_NAME) $(SEM_SERVER_NAME) & \
wait; \
wait $$SRV
# Очистка
clean:
@echo "Очистка..."
rm -f server client
help:
@echo "Available targets:"
@echo " shm - Build POSIX SHM+SEM programs"
@echo " test_server - Run SHM+SEM server (clients in another terminal)"
@echo " test_clients - Run several client processes"
@echo " test_all - Automatic end-to-end test"
@echo " clean - Remove built files"
@echo " help - Show this help"
.PHONY: all shm test_server test_clients test_all clean help