Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 15 additions & 39 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,60 +1,36 @@
COMPILER=G++
COMPILER=cc

# todo: object files into output path, processing c / c++ files in the same time (?), nested directories for source files (?)
C = c
OUTPUT_PATH = bin/
SOURCE_PATH = src/
EXE = bin/mbpfan
BIN = bin/mbpfan
CONF = mbpfan.conf
DOC = README.md
MAN = mbpfan.8.gz

ifeq ($(COMPILER), G++)
ifeq ($(OS),Windows_NT)
OBJ = obj
else
OBJ = o
endif
COPT =
CCMD = g++
OBJFLAG = -o
EXEFLAG = -o
# INCLUDES = -I../.includes
INCLUDES =
# LIBS = -lgc
LIBS = -lm
# LIBPATH = -L../gc/.libs
LIBPATH =
CPPFLAGS += $(COPT) -g $(INCLUDES) #-Wall
LDFLAGS += $(LIBPATH) -g $(LIBS) #-Wall
DEP = dep
else
OBJ = obj
COPT = /O2
CCMD = cl
OBJFLAG = /Fo
EXEFLAG = /Fe
# INCLUDES = /I..\\.includes
INCLUDES =
# LIBS = ..\\.libs\\libgc.lib
LIBS =
CPPFLAGS = $(COPT) /DEBUG $(INCLUDES)
LDFLAGS = /DEBUG
endif
COPT =
CC = cc
OBJFLAG = -o
BINFLAG = -o
INCLUDES =
LIBS = -lm
LIBPATH =
CFLAGS += $(COPT) -g $(INCLUDES) #-Wall
LDFLAGS += $(LIBPATH) -g $(LIBS) #-Wall

OBJS := $(patsubst %.$(C),%.$(OBJ),$(wildcard $(SOURCE_PATH)*.$(C)))

%.$(OBJ):%.$(C)
mkdir -p bin
@echo Compiling $(basename $<)...
$(CCMD) -c $(CPPFLAGS) $(CXXFLAGS) $< $(OBJFLAG)$@
$(CC) -c $(CFLAGS) $< $(OBJFLAG)$@

all: $(OBJS)
@echo Linking...
$(CCMD) $(LDFLAGS) $^ $(LIBS) $(EXEFLAG) $(EXE)
$(CC) $(LDFLAGS) $^ $(LIBS) $(BINFLAG) $(BIN)

clean:
rm -rf $(SOURCE_PATH)*.$(OBJ) $(EXE)
rm -rf $(SOURCE_PATH)*.$(OBJ) $(BIN)

tests:
make install
Expand All @@ -73,7 +49,7 @@ install:
install -d $(DESTDIR)/etc
install -d $(DESTDIR)/lib/systemd/system
install -d $(DESTDIR)/usr/share/doc/mbpfan
install $(EXE) $(DESTDIR)/usr/sbin
install $(BIN) $(DESTDIR)/usr/sbin
install -m644 $(CONF) $(DESTDIR)/etc
install -m644 $(DOC) $(DESTDIR)/usr/share/doc/mbpfan
install -d $(DESTDIR)/usr/share/man/man8
Expand Down
22 changes: 5 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Supported distributions:
- RedHat
- CentOS
- Gentoo

- Alpine
- Trisquel

Tested Macbook Models
---------------------
Expand Down Expand Up @@ -112,22 +113,9 @@ README.md to /usr/share/doc/mbpfan, and mbpfan.8.gz to /usr/share/man/man8

Run the tests now, see two sections below.

If you would like to compile with Clang instead of GCC, see the next section.

Compile with Clang (experimental)
---------------------------------
We are providing an initial experimental support for [Clang and LLVM](http://clang.llvm.org/).
Please go to the next section if you are following a standard installation procedure (most people do).

Edit the 'Makefile' and replace G++ with clang++

Please run

make clean

Before attempting to compile again with Clang.

Tested and working with Clang 3.8 and 3.9.
If you would like to compile with Clang instead of GCC, simply set your system's
default compiler to be Clang. Tested with Clang 3.8 and 3.9. Tested with Clang
4.0 along with llvm-lld (The LLVM Linker).


Run The Tests (Recommended)
Expand Down
6 changes: 4 additions & 2 deletions src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright (C) 2012 Peter Lombardo <http://peterlombardo.wikidot.com/linux-daemon-in-c>
* Modifications (2012) by Ismail Khatib <[email protected]>
* Modifications (2012-present) by Daniel Graziotin <[email protected]>
* Modifications (2017-present) by Robert Musial <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -20,6 +21,7 @@
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <fcntl.h>
#include <errno.h>
#include <syslog.h>
Expand Down Expand Up @@ -77,7 +79,7 @@ static void cleanup_and_exit(int exit_code)
delete_pid();
set_fans_auto(fans);

s_fans *next_fan;
struct s_fans *next_fan;
while (fans != NULL) {
next_fan = fans->next;
free(fans->fan_output_path);
Expand All @@ -86,7 +88,7 @@ static void cleanup_and_exit(int exit_code)
fans = next_fan;
}

s_sensors *next_sensor;
struct s_sensors *next_sensor;
while (sensors != NULL) {
next_sensor = sensors->next;
free(sensors->path);
Expand Down
4 changes: 3 additions & 1 deletion src/main.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Copyright (C) (2012-present) Daniel Graziotin <[email protected]>
* Modifications (2017-present) by Robert Musial <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -21,6 +22,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <syslog.h>
#include <stdbool.h>
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
Expand Down Expand Up @@ -145,4 +147,4 @@ int main(int argc, char *argv[])
void (*fan_control)() = mbpfan;
go_daemon(fan_control);
exit(EXIT_SUCCESS);
}
}
34 changes: 23 additions & 11 deletions src/mbpfan.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Modifications by Rafael Vega <[email protected]>
* Modifications (2012) by Ismail Khatib <[email protected]>
* Modifications (2012-present) by Daniel Graziotin <[email protected]> [CURRENT MAINTAINER]
* Modifications (2017-present) by Robert Musial <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -32,6 +33,7 @@
#include <string.h>
#include <math.h>
#include <syslog.h>
#include <stdbool.h>
#include <sys/utsname.h>
#include <sys/errno.h>
#include "mbpfan.h"
Expand Down Expand Up @@ -73,20 +75,30 @@ bool is_legacy_kernel()
exit(EXIT_FAILURE);
}

str_kernel_version = strtok(NULL, ".");
int kernel_version = atoi(str_kernel_version);

// thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
fopen("/sys/devices/platform/coretemp.0/hwmon", "wb");

if(verbose) {
printf("Detected kernel version: %s\n", kernel.release);
printf("Detected kernel minor revision: %s\n", str_kernel_version);

if(daemonize) {
syslog(LOG_INFO, "Kernel version: %s", kernel.release);
syslog(LOG_INFO, "Detected kernel minor revision: %s", str_kernel_version);
}
if (errno == EISDIR) {
return 0;
} else {
return 1;
}

return (atoi(kernel.release) == 3 && kernel_version < 15);
// str_kernel_version = strtok(NULL, ".");
// int kernel_version = atoi(str_kernel_version);

// if(verbose) {
// printf("Detected kernel version: %s\n", kernel.release);
// printf("Detected kernel minor revision: %s\n", str_kernel_version);

// if(daemonize) {
// syslog(LOG_INFO, "Kernel version: %s", kernel.release);
// syslog(LOG_INFO, "Detected kernel minor revision: %s", str_kernel_version);
// }
// }

// return (atoi(kernel.release) == 3 && kernel_version < 15);
}


Expand Down
1 change: 1 addition & 0 deletions src/minunit.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <time.h>
#include <limits.h>
#include <signal.h>
#include <stdbool.h>
#include <sys/utsname.h>
#include "global.h"
#include "mbpfan.h"
Expand Down