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
|
CC = gcc
|
||||||
CCFLAGS = -Wall -std=c99 -pedantic -g
|
CCFLAGS = -Wall -std=c99 -pedantic -g
|
||||||
|
|
||||||
CLIENT=client
|
SERVER_SOURCES=src/server.c src/errors.c src/challenges.c src/math.c src/sockets.c
|
||||||
SERVER=server
|
CLIENT_SOURCES=src/client.c src/errors.c src/sockets.c
|
||||||
ERRORS=errors.o
|
SERVER_LIBS=include/errors.h include/challenges.h include/server.h include/challengesLib.h include/sockets.h include/math.h
|
||||||
CHALLENGES=challenges.o
|
CLIENT_LIBS=include/errors.h include/client.h include/sockets.h
|
||||||
RANDOM=random.o
|
SERVER_OBJ=server
|
||||||
SOCKETS=sockets.o
|
CLIENT_OBJ=client
|
||||||
|
|
||||||
TMP := $(shell mktemp)
|
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
|
$(SERVER_OBJ): $(SERVER_SOURCES) $(SERVER_LIBS)
|
||||||
$(CC) $(CCFLAGS) src/server.c -o server $(CHALLENGES) $(ERRORS) $(RANDOM) $(SOCKETS) -lm
|
$(CC) $(CCFLAGS) -o $(SERVER_OBJ) $(SERVER_SOURCES) -lm
|
||||||
objcopy --add-section .RUN_ME="$(TMP)" --set-section-flags .mydata=noload,readonly server
|
objcopy --add-section .RUN_ME="$(TMP)" --set-section-flags .mydata=noload,readonly $(SERVER_OBJ)
|
||||||
strip --strip-debug server
|
strip --strip-debug $(SERVER_OBJ)
|
||||||
rm "$(TMP)"
|
rm "$(TMP)"
|
||||||
|
|
||||||
$(CLIENT): src/client.c src/errors.c src/sockets.c include/errors.h include/client.h include/sockets.h
|
$(CLIENT_OBJ): $(CLIENT_SOURCES) $(CLIENT_LIBS)
|
||||||
$(CC) $(CCFLAGS) src/client.c -o client $(ERRORS) $(SOCKETS)
|
$(CC) $(CCFLAGS) -o $(CLIENT_OBJ) $(CLIENT_SOURCES)
|
||||||
|
|
||||||
%.o: src/%.c
|
|
||||||
$(CC) $(CCFLAGS) -I./include -c $<
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ERRORS) $(CHALLENGES) $(CLIENT) $(SERVER) $(RANDOM) $(SOCKETS)
|
rm -f $(CLIENT_OBJ) $(SERVER_OBJ)
|
||||||
|
|
||||||
test:
|
test:
|
||||||
pvs-studio-analyzer trace -- make
|
pvs-studio-analyzer trace -- make
|
||||||
|
@ -34,6 +31,6 @@ test:
|
||||||
cppcheck --quiet --enable=all --force --inconclusive .
|
cppcheck --quiet --enable=all --force --inconclusive .
|
||||||
|
|
||||||
cleanTest:
|
cleanTest:
|
||||||
rm -rf PVS-Studio.log report.tasks strace_out
|
rm -f PVS-Studio.log report.tasks strace_out
|
||||||
|
|
||||||
.PHONY: all clean test cleanTest
|
.PHONY: all clean test cleanTest
|
||||||
|
|
|
@ -7,15 +7,10 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <math.h>
|
|
||||||
#include "errors.h"
|
#include "errors.h"
|
||||||
#include "random.h"
|
#include "math.h"
|
||||||
|
|
||||||
#define MAX_LEN 100
|
|
||||||
#define MAX_NORMALS 1000
|
#define MAX_NORMALS 1000
|
||||||
#define UPPER 2
|
|
||||||
#define LOWER 1
|
|
||||||
#define M_PI 3.14159265358979323846
|
|
||||||
#define MAGIC_VAL 0x12345678
|
#define MAGIC_VAL 0x12345678
|
||||||
|
|
||||||
typedef struct challenge_t {
|
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 "challengesLib.h"
|
||||||
#include "sockets.h"
|
#include "sockets.h"
|
||||||
|
|
||||||
#define MAX_LEN 100
|
|
||||||
#define TIME_SLEEP 2
|
#define TIME_SLEEP 2
|
||||||
|
|
||||||
void startChallenge();
|
void startChallenge();
|
||||||
|
|
|
@ -87,12 +87,6 @@ void gdbChallenge() {
|
||||||
gdbme();
|
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() {
|
void normalChallenge() {
|
||||||
for (int i = 0; i < MAX_NORMALS; i++) {
|
for (int i = 0; i < MAX_NORMALS; i++) {
|
||||||
double normal = 0;
|
double normal = 0;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// This is a personal academic project. Dear PVS-Studio, please check it.
|
// 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
|
// 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_z = 362436069;
|
||||||
static uint32_t m_w = 521288629;
|
static uint32_t m_w = 521288629;
|
||||||
|
@ -14,4 +14,10 @@ uint32_t getUint() {
|
||||||
double getUniform(uint32_t max) {
|
double getUniform(uint32_t max) {
|
||||||
uint32_t u = getUint();
|
uint32_t u = getUint();
|
||||||
return (u + 1.0) * 2.328306435454494e-10 * max;
|
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