Elaborato_SO/Makefile

90 lines
2.8 KiB
Makefile

# [--------------------DIRECTORIES--------------------]
# SRC_DIR is the source directory
# OBJ_DIR is the object directory
# INC_DIR is the header directory
SRC_DIR := src
OBJ_DIR := obj
INC_DIR := inc
BIN_DIR := bin
# [--------------------COMPILE & RUN--------------------]
# CXX is the keyword to compile .c src files
# WFLAG is a flag to detect all the warnings
# OFLAG is the flag to rename the output of the compiler
# TARGET is the name of the output
# INCLUDE add to g++ path the custom include path
CXX := gcc
WFLAGS := -Wall
OFLAG := -o
TARGET1 := $(BIN_DIR)/F4Server
TARGET2 := $(BIN_DIR)/F4Client
INCLUDE := -I $(INC_DIR)
# [--------------------FUNCTION--------------------]
# SRCS extract all file in src/
# FILES extract the name of the file
# OBJS concat obj/ + FILES + .o
SRCS := $(shell find $(SRC_DIR) -name "*.c")
FILES := $(notdir $(basename $(SRCS)))
OBJS := $(addprefix $(OBJ_DIR)/,$(addsuffix .o,$(FILES)))
#---------------------------------------------------
all: test
#---------------------------------------------------
execute: linking_s linking_c
@ echo execute...
@ ./$(TARGET1) $(ARGS)
@ echo ...terminate
#---------------------------------------------------
linking_s: $(OBJS) $(BIN_DIR)
@ echo linking
@ $(CXX) $(WFLAGS) $(OFLAG) $(TARGET1) $(OBJS)
#---------------------------------------------------
linking_c: $(OBJS) $(BIN_DIR)
@ echo linking
@ $(CXX) $(WFLAGS) $(OFLAG) $(TARGET2) $(OBJS)
#---------------------------------------------------
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)
@ echo compile $<
@ $(CXX) $(WFLAGS) -c $< $(OFLAG) $@ $(INCLUDE)
#---------------------------------------------------
$(OBJ_DIR):
@ mkdir -p $(OBJ_DIR)
#---------------------------------------------------
$(BIN_DIR):
@ mkdir -p $(BIN_DIR)
#---------------------------------------------------
clean:
@ rm -rf $(OBJ)
#---------------------------------------------------
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
MKFILE_DIR := $(dir $(mkfile_path))
ARGSSERVER := 6 7 O X
ARGSCLIENT1 := Test1
ARGSCLIENT2 := Test2
OPEN_NEW_TERMINAL := x-terminal-emulator
TERMINAL_ARGS1 := --geometry=90x30 -e
TERMINAL_ARGS2 := --geometry=10x30 -e
# OPEN_NEW_TERMINAL := kitty
test: comp
ipcrm --all=sem
ipcrm --all=msg
ipcrm --all=shm
$(OPEN_NEW_TERMINAL) $(TERMINAL_ARGS1) $(MKFILE_DIR) $(TARGET2) $(ARGSCLIENT1)
$(OPEN_NEW_TERMINAL) $(TERMINAL_ARGS2) $(MKFILE_DIR) $(TARGET2) $(ARGSCLIENT2)
./$(TARGET1) $(ARGSSERVER)
comp: server_c client_c
server_c:
gcc src/F4Server.c src/custom_sem.c src/custom_shm.c src/custom_sig.c src/custom_msgq.c src/errExit.c src/forza4.c src/client.c src/server.c -o bin/F4Server -I inc/
client_c:
gcc src/F4Client.c src/custom_sem.c src/custom_shm.c src/custom_sig.c src/custom_msgq.c src/errExit.c src/forza4.c src/client.c src/server.c -o bin/F4Client -I inc/