Elaborato_SO/Makefile

63 lines
1.9 KiB
Makefile
Raw Normal View History

2023-05-14 16:05:37 +02:00
# [--------------------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
2023-05-14 17:16:12 +02:00
BIN_DIR := bin
2023-05-14 16:05:37 +02:00
# [--------------------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
2023-05-14 16:05:37 +02:00
INCLUDE := -I $(INC_DIR)
2023-05-16 18:43:56 +02:00
ARGS := 6 7 O X
2023-05-14 16:05:37 +02:00
# [--------------------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: execute
#---------------------------------------------------
execute: linking_s linking_c
2023-05-14 16:05:37 +02:00
@ echo execute...
2023-05-16 18:43:56 +02:00
@ ./$(TARGET1) $(ARGS)
2023-05-14 16:05:37 +02:00
@ echo ...terminate
#---------------------------------------------------
linking_s: $(OBJS) $(BIN_DIR)
2023-05-14 16:05:37 +02:00
@ echo linking
@ $(CXX) $(WFLAGS) $(OFLAG) $(TARGET1) $(OBJS)
#---------------------------------------------------
linking_c: $(OBJS) $(BIN_DIR)
@ echo linking
@ $(CXX) $(WFLAGS) $(OFLAG) $(TARGET2) $(OBJS)
2023-05-14 16:05:37 +02:00
#---------------------------------------------------
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(OBJ_DIR)
@ echo compile $<
@ $(CXX) $(WFLAGS) -c $< $(OFLAG) $@ $(INCLUDE)
#---------------------------------------------------
$(OBJ_DIR):
2023-05-14 17:16:12 +02:00
@ mkdir -p $(OBJ_DIR)
#---------------------------------------------------
$(BIN_DIR):
@ mkdir -p $(BIN_DIR)
2023-05-14 16:05:37 +02:00
#---------------------------------------------------
clean:
@ rm -rf $(OBJ)
#---------------------------------------------------