Skip to content

Commit

Permalink
FULL PROJECT : MAKE FILE , SOURCE AND SUB DIR
Browse files Browse the repository at this point in the history
  • Loading branch information
rhagee committed Jan 17, 2020
1 parent b1d5ae6 commit fffcf1b
Show file tree
Hide file tree
Showing 11 changed files with 85 additions and 46 deletions.
19 changes: 19 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
PROJECT README :


1. Open Terminal in the directory where the "makefile" is.
2. Digit your favourite way to execute the code :
- make all -> Just Compile and put files in sub-directories
- make run -> Compile and Execute Automatically the code
- make run_clean -> Compile and Execute Automatically, after a NORMAL termination , it deletes the Exe and .o files
- make clean -> Just Clean sub-directories

Sub-Directories :

exe : Contains Executables and Settings.txt for the game
lib : Contains the libraries
src : Source Container, contains all the C programs and the file "settings.txt" (EDIT THERE THE FILE TO GET THE NEW OPTIONS DONE IF YOU COMPILE AGAIN)

If you want to Execute the program with the "./name" command, and there is the "settings.txt" inside "exe" folder, you can change it there.

END FILE.
Binary file removed main
Binary file not shown.
66 changes: 57 additions & 9 deletions makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,63 @@

FLAGS = -std=c89 -Wpedantic #OPTION FOR EXECUTABLE FILES
OFLAGS = -c -std=c89 -Wpedantic #OPTIONS FOR .o FILE

FLAGS = -std=c89 -Wpedantic
#OBJ = src/master.c src/player.c src/pawn.c
DEPS = lib/sharedmem.c lib/sharedmem.h #DEPENDENCIES

EXECUTABLE = main #EXECUTABLE NAME
EXDIR = exe #EXE DIRECTORY
SDIR = src #SOURCE DIRECTORY

all : master.c player.c pawn.c lib/sharedmem.c lib/sharedmem.h
$(CC) $(FLAGS) master.c lib/sharedmem.c -o main
$(CC) $(FLAGS) player.c lib/sharedmem.c -o player
$(CC) $(FLAGS) pawn.c lib/sharedmem.c -o pawn
LIBDIR = lib #LIBRARY DIRECTORY
LIBNAME = sharedmem.o #LIBRARY NAME AFTER GENERATING .o


#BASIC MAKE
all : createdir $(LIBDIR)/$(LIBNAME) $(EXDIR)/$(EXECUTABLE) $(EXDIR)/player $(EXDIR)/pawn copysettings

#MAKE RUN WITHOUT DELETING AT THE END
run : createdir $(LIBDIR)/$(LIBNAME) $(EXDIR)/$(EXECUTABLE) $(EXDIR)/player $(EXDIR)/pawn copysettings execute

#MAKE RUN WITH DELETES AT THE END
run_clean : run clean

#MAKE EXECUTE CAN EXECUTE THE PROGRAM
execute :
cd $(EXDIR);./$(EXECUTABLE)

#CREATE EXE DIRECTORY IF IT DOESN'T EXISTS YET
createdir :
mkdir -p $(EXDIR)

#COPY SETTINGS FILE FROM LIB TO EXE
copysettings :
cp $(SDIR)/settings.txt $(EXDIR)

#CHECK FOR LIBRARIES TO RECOMPILE AND MOVE
$(LIBDIR)/$(LIBNAME): $(DEPS)
$(CC) $(OFLAGS) $(LIBDIR)/sharedmem.c -o $(LIBNAME)
mv $(LIBNAME) $(LIBDIR)

#CHECK FOR MAIN TO RECOMPILE (MASTER) AND MOVE
$(EXDIR)/$(EXECUTABLE) : src/master.c $(DEPS)
$(CC) $(FLAGS) $(SDIR)/master.c $(LIBDIR)/$(LIBNAME) -o $(EXECUTABLE)
mv $(EXECUTABLE) $(EXDIR)

#CHECK FOR PLAYER TO RECOMPILE AND MOVE
$(EXDIR)/player : src/player.c $(DEPS)
$(CC) $(FLAGS) $(SDIR)/player.c $(LIBDIR)/$(LIBNAME) -o player
mv player $(EXDIR)

#CHECK FOR PAWN TO RECOMPILE AND MOVE
$(EXDIR)/pawn : src/pawn.c $(DEPS)
$(CC) $(FLAGS) $(SDIR)/pawn.c $(LIBDIR)/$(LIBNAME) -o pawn
mv pawn $(EXDIR)

#CLASSIC CLEAN
clean :
rm -f *.o
rm main
rm player
rm pawn
rm -f lib/*.o
rm $(EXDIR)/*



Binary file removed master
Binary file not shown.
Binary file removed pawn
Binary file not shown.
Binary file removed player
Binary file not shown.
28 changes: 0 additions & 28 deletions settings_BASE.txt

This file was deleted.

11 changes: 6 additions & 5 deletions master.c → src/master.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Includes*/
#include "lib/sharedmem.h"
#include "../lib/sharedmem.h"

/* Defines */
#define MENU "Select GameMode : \n1.Easy \n2.Hard \nDefault: Easy \nSelezione: "
Expand Down Expand Up @@ -140,7 +140,7 @@ int main()

/*Create Players*/
createPlayers();

printf("WAITING PLAYER\n");
semWaitZero(sync_id,MASTERSYNC,0);

/* Round Routine */
Expand Down Expand Up @@ -247,16 +247,16 @@ void createPlayers()
semSetAll(pawn_sync,0);
semSet(pawn_sync,0,1);
semSetAll(smap_id,1);

printf("PLAYERS %d\n",n_players);
/*Alphabet isn't that long*/
if(n_players>50)
{
WARN_NPLAYERS;
sleep(3);
}

for(i=0;i<n_players;i++)
{
printf("%d",i);
sprintf(mynumber,"%d",i);
if(i<=25)
sprintf(letter,"%d", i+97);
Expand All @@ -275,7 +275,7 @@ void createPlayers()
printf("ERRORE \n");
break;
default:
/*printf("Player %c - PID : %d\n",atoi(letter),players[i]);*/
printf("Player %c - PID : %d\n",atoi(letter),players[i]);
scores[i] = 0;
break;
}
Expand Down Expand Up @@ -316,6 +316,7 @@ void Read_Settings(int* SO_NUM_G,int* SO_NUM_P,int* SO_MAX_TIME,int* SO_BASE,int
{
fscanf(file,EASY_MODE,SO_NUM_G,SO_NUM_P,SO_MAX_TIME,SO_BASE,SO_ALTEZZA,SO_FLAG_MIN,SO_FLAG_MAX,SO_ROUND_SCORE,SO_N_MOVES,SO_MIN_HOLD_NSEC);
}
printf("READ SETTINGS \n");
}

void Init_Table()
Expand Down
2 changes: 1 addition & 1 deletion pawn.c → src/pawn.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


#include "lib/sharedmem.h"
#include "../lib/sharedmem.h"


#define intconvert(X) atoi(argv[X])
Expand Down
3 changes: 1 addition & 2 deletions player.c → src/player.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*Includes*/
#include "lib/sharedmem.h"
#include "../lib/sharedmem.h"
/*Defines*/
#define intconvert(X) atoi(argv[X]);
#define FIRSTPLAYER 0
Expand Down Expand Up @@ -672,7 +672,6 @@ int calcTotMoves()
void ClosingRoutine()
{
free(pawnPos);
free(flagPos);
free(pawnMoves);
free(pawns);
semctl(semPawn_id,0,IPC_RMID);
Expand Down
2 changes: 1 addition & 1 deletion settings.txt → src/settings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ SO_BASE 60 120
SO_ALTEZZA 20 40
SO_FLAG_MIN 5 5
SO_FLAG_MAX 5 40
SO_ROUND_SCORE 5 200
SO_ROUND_SCORE 10 200
SO_N_MOVES 20 200
SO_MIN_HOLD_NSEC 100000000 100000000

0 comments on commit fffcf1b

Please sign in to comment.