Skip to content

Commit

Permalink
💯 ultimate makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
FelipeFTN committed Dec 23, 2022
1 parent 86b7b63 commit d8cd1c4
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
## Compile client & server

CC=gcc
PROGRAMS=bin/server bin/client
PROGRAMS=$(SERVER_BINARY) $(CLIENT_BINARY)

# Uncomment this line in case of linker error while building
# CFLAGS=-fno-use-linker-plugin
Expand All @@ -11,25 +11,22 @@ ifeq ($(OS),Windows_NT)
endif

## SERVER
BINARY=bin/server
CFILES=server/main.c server/socket/socket.c server/handler/handler.c
OBJECTS=server/main.o server/socket/socket.o server/handler/handler.o
SERVER_BINARY=bin/server
SERVER_CFILES=server/main.c server/socket/socket.c server/handler/handler.c
SERVER_OBJECTS=server/main.o server/socket/socket.o server/handler/handler.o

## CLIENT
CLIENT_BINARY=bin/client
CLIENT_CFILES=client/main.c client/socket/socket.c client/handler/handler.c
CLIENT_OBJECTS=client/main.o client/socket/socket.o client/handler/handler.o

all: $(PROGRAMS)

$(BINARY): $(OBJECTS)
$(SERVER_BINARY): $(SERVER_OBJECTS)
mkdir -p bin/
$(CC) $^ -o $@

%.o:%.c
$(CC) -c $^ -o $@ $(CFLAGS)

## CLIENT
BINARY=bin/client
CFILES=client/main.c client/socket/socket.c client/handler/handler.c
OBJECTS=client/main.o client/socket/socket.o client/handler/handler.o

$(BINARY): $(OBJECTS)
$(CLIENT_BINARY): $(CLIENT_OBJECTS)
mkdir -p bin/
$(CC) $^ -o $@

Expand All @@ -39,5 +36,5 @@ $(BINARY): $(OBJECTS)
## Global
clean:
rm -rf bin/
rm server/*.o server/handler/*.o server/socket/*.o
rm client/*.o client/handler/*.o client/socket/*.o
rm $(SERVER_OBJECTS)
rm $(CLIENT_OBJECTS)

0 comments on commit d8cd1c4

Please sign in to comment.