Update Makefile and continue refactoring code
Co-authored-by: Ezequiel Bellver <ebellver@itba.edu.ar> Co-authored-by: Juan Barmasch <jbarmasch@itba.edu.ar>
This commit is contained in:
parent
9872bbafde
commit
e0c0ac68d9
33
Makefile
33
Makefile
|
@ -1,31 +1,28 @@
|
|||
CC = gcc
|
||||
CCFLAGS = -Wall -std=c99 -pedantic -g
|
||||
|
||||
CLIENT=client
|
||||
SERVER=server
|
||||
ERRORS=errors.o
|
||||
CHALLENGES=challenges.o
|
||||
RANDOM=random.o
|
||||
SOCKETS=sockets.o
|
||||
SERVER_SOURCES=src/server.c src/errors.c src/challenges.c src/math.c src/sockets.c
|
||||
CLIENT_SOURCES=src/client.c src/errors.c src/sockets.c
|
||||
SERVER_LIBS=include/errors.h include/challenges.h include/server.h include/challengesLib.h include/sockets.h include/math.h
|
||||
CLIENT_LIBS=include/errors.h include/client.h include/sockets.h
|
||||
SERVER_OBJ=server
|
||||
CLIENT_OBJ=client
|
||||
|
||||
TMP := $(shell mktemp)
|
||||
|
||||
all: $(ERRORS) $(CHALLENGES) $(RANDOM) $(SOCKETS) $(CLIENT) $(SERVER)
|
||||
all: $(CLIENT_OBJ) $(SERVER_OBJ)
|
||||
|
||||
$(SERVER): src/server.c src/challenges.c src/errors.c src/sockets.c include/errors.h include/challenges.h include/server.h include/challengesLib.h include/sockets.h
|
||||
$(CC) $(CCFLAGS) src/server.c -o server $(CHALLENGES) $(ERRORS) $(RANDOM) $(SOCKETS) -lm
|
||||
objcopy --add-section .RUN_ME="$(TMP)" --set-section-flags .mydata=noload,readonly server
|
||||
strip --strip-debug server
|
||||
$(SERVER_OBJ): $(SERVER_SOURCES) $(SERVER_LIBS)
|
||||
$(CC) $(CCFLAGS) -o $(SERVER_OBJ) $(SERVER_SOURCES) -lm
|
||||
objcopy --add-section .RUN_ME="$(TMP)" --set-section-flags .mydata=noload,readonly $(SERVER_OBJ)
|
||||
strip --strip-debug $(SERVER_OBJ)
|
||||
rm "$(TMP)"
|
||||
|
||||
$(CLIENT): src/client.c src/errors.c src/sockets.c include/errors.h include/client.h include/sockets.h
|
||||
$(CC) $(CCFLAGS) src/client.c -o client $(ERRORS) $(SOCKETS)
|
||||
|
||||
%.o: src/%.c
|
||||
$(CC) $(CCFLAGS) -I./include -c $<
|
||||
$(CLIENT_OBJ): $(CLIENT_SOURCES) $(CLIENT_LIBS)
|
||||
$(CC) $(CCFLAGS) -o $(CLIENT_OBJ) $(CLIENT_SOURCES)
|
||||
|
||||
clean:
|
||||
rm -f $(ERRORS) $(CHALLENGES) $(CLIENT) $(SERVER) $(RANDOM) $(SOCKETS)
|
||||
rm -f $(CLIENT_OBJ) $(SERVER_OBJ)
|
||||
|
||||
test:
|
||||
pvs-studio-analyzer trace -- make
|
||||
|
@ -34,6 +31,6 @@ test:
|
|||
cppcheck --quiet --enable=all --force --inconclusive .
|
||||
|
||||
cleanTest:
|
||||
rm -rf PVS-Studio.log report.tasks strace_out
|
||||
rm -f PVS-Studio.log report.tasks strace_out
|
||||
|
||||
.PHONY: all clean test cleanTest
|
||||
|
|
|
@ -7,15 +7,10 @@
|
|||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <math.h>
|
||||
#include "errors.h"
|
||||
#include "random.h"
|
||||
#include "math.h"
|
||||
|
||||
#define MAX_LEN 100
|
||||
#define MAX_NORMALS 1000
|
||||
#define UPPER 2
|
||||
#define LOWER 1
|
||||
#define M_PI 3.14159265358979323846
|
||||
#define MAGIC_VAL 0x12345678
|
||||
|
||||
typedef struct challenge_t {
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <math.h>
|
||||
|
||||
#define M_PI 3.14159265358979323846
|
||||
|
||||
double getUniform(uint32_t max);
|
||||
void boxMuller(double * normal);
|
||||
|
||||
#endif
|
|
@ -1,8 +0,0 @@
|
|||
#ifndef MATH_H
|
||||
#define MATH_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
double getUniform(uint32_t max);
|
||||
|
||||
#endif
|
|
@ -14,7 +14,6 @@
|
|||
#include "challengesLib.h"
|
||||
#include "sockets.h"
|
||||
|
||||
#define MAX_LEN 100
|
||||
#define TIME_SLEEP 2
|
||||
|
||||
void startChallenge();
|
||||
|
|
|
@ -87,12 +87,6 @@ void gdbChallenge() {
|
|||
gdbme();
|
||||
}
|
||||
|
||||
void boxMuller(double * normal) {
|
||||
double random1 = getUniform(1);
|
||||
double random2 = getUniform(1);
|
||||
*normal = sqrt(-2 * log(random1)) * cos(2 * M_PI * random2);
|
||||
}
|
||||
|
||||
void normalChallenge() {
|
||||
for (int i = 0; i < MAX_NORMALS; i++) {
|
||||
double normal = 0;
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "../include/random.h"
|
||||
#include "../include/math.h"
|
||||
|
||||
static uint32_t m_z = 362436069;
|
||||
static uint32_t m_w = 521288629;
|
||||
|
@ -15,3 +15,9 @@ double getUniform(uint32_t max) {
|
|||
uint32_t u = getUint();
|
||||
return (u + 1.0) * 2.328306435454494e-10 * max;
|
||||
}
|
||||
|
||||
void boxMuller(double * normal) {
|
||||
double random1 = getUniform(1);
|
||||
double random2 = getUniform(1);
|
||||
*normal = sqrt(-2 * log(random1)) * cos(2 * M_PI * random2);
|
||||
}
|
Loading…
Reference in New Issue