Skip to content

Commit 565c545

Browse files
committed
[Fix #104] support for clang, makefile cleaned from 'rmusial-master'
2 parents 906e40c + c3e1c9c commit 565c545

6 files changed

Lines changed: 41 additions & 59 deletions

File tree

Makefile

Lines changed: 15 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,36 @@
1-
COMPILER=G++
1+
COMPILER=cc
22

3-
# todo: object files into output path, processing c / c++ files in the same time (?), nested directories for source files (?)
43
C = c
54
OUTPUT_PATH = bin/
65
SOURCE_PATH = src/
7-
EXE = bin/mbpfan
6+
BIN = bin/mbpfan
87
CONF = mbpfan.conf
98
DOC = README.md
109
MAN = mbpfan.8.gz
1110

12-
ifeq ($(COMPILER), G++)
13-
ifeq ($(OS),Windows_NT)
14-
OBJ = obj
15-
else
16-
OBJ = o
17-
endif
18-
COPT =
19-
CCMD = g++
20-
OBJFLAG = -o
21-
EXEFLAG = -o
22-
# INCLUDES = -I../.includes
23-
INCLUDES =
24-
# LIBS = -lgc
25-
LIBS = -lm
26-
# LIBPATH = -L../gc/.libs
27-
LIBPATH =
28-
CPPFLAGS += $(COPT) -g $(INCLUDES) #-Wall
29-
LDFLAGS += $(LIBPATH) -g $(LIBS) #-Wall
30-
DEP = dep
31-
else
32-
OBJ = obj
33-
COPT = /O2
34-
CCMD = cl
35-
OBJFLAG = /Fo
36-
EXEFLAG = /Fe
37-
# INCLUDES = /I..\\.includes
38-
INCLUDES =
39-
# LIBS = ..\\.libs\\libgc.lib
40-
LIBS =
41-
CPPFLAGS = $(COPT) /DEBUG $(INCLUDES)
42-
LDFLAGS = /DEBUG
43-
endif
11+
COPT =
12+
CC = cc
13+
OBJFLAG = -o
14+
BINFLAG = -o
15+
INCLUDES =
16+
LIBS = -lm
17+
LIBPATH =
18+
CFLAGS += $(COPT) -g $(INCLUDES) #-Wall
19+
LDFLAGS += $(LIBPATH) -g $(LIBS) #-Wall
4420

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

4723
%.$(OBJ):%.$(C)
4824
mkdir -p bin
4925
@echo Compiling $(basename $<)...
50-
$(CCMD) -c $(CPPFLAGS) $(CXXFLAGS) $< $(OBJFLAG)$@
26+
$(CC) -c $(CFLAGS) $< $(OBJFLAG)$@
5127

5228
all: $(OBJS)
5329
@echo Linking...
54-
$(CCMD) $(LDFLAGS) $^ $(LIBS) $(EXEFLAG) $(EXE)
30+
$(CC) $(LDFLAGS) $^ $(LIBS) $(BINFLAG) $(BIN)
5531

5632
clean:
57-
rm -rf $(SOURCE_PATH)*.$(OBJ) $(EXE)
33+
rm -rf $(SOURCE_PATH)*.$(OBJ) $(BIN)
5834

5935
tests:
6036
make install
@@ -73,7 +49,7 @@ install:
7349
install -d $(DESTDIR)/etc
7450
install -d $(DESTDIR)/lib/systemd/system
7551
install -d $(DESTDIR)/usr/share/doc/mbpfan
76-
install $(EXE) $(DESTDIR)/usr/sbin
52+
install $(BIN) $(DESTDIR)/usr/sbin
7753
install -m644 $(CONF) $(DESTDIR)/etc
7854
install -m644 $(DOC) $(DESTDIR)/usr/share/doc/mbpfan
7955
install -d $(DESTDIR)/usr/share/man/man8

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ Supported distributions:
3030
- RedHat
3131
- CentOS
3232
- Gentoo
33-
33+
- Alpine
34+
- Trisquel
3435

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

113114
Run the tests now, see two sections below.
114115

115-
If you would like to compile with Clang instead of GCC, see the next section.
116-
117-
Compile with Clang (experimental)
118-
---------------------------------
119-
We are providing an initial experimental support for [Clang and LLVM](http://clang.llvm.org/).
120-
Please go to the next section if you are following a standard installation procedure (most people do).
121-
122-
Edit the 'Makefile' and replace G++ with clang++
123-
124-
Please run
125-
126-
make clean
127-
128-
Before attempting to compile again with Clang.
129-
130-
Tested and working with Clang 3.8 and 3.9.
116+
If you would like to compile with Clang instead of GCC, simply set your system's
117+
default compiler to be Clang. Tested with Clang 3.8 and 3.9. Tested with Clang
118+
4.0 along with llvm-lld (The LLVM Linker).
131119

132120

133121
Run The Tests (Recommended)

src/daemon.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright (C) 2012 Peter Lombardo <http://peterlombardo.wikidot.com/linux-daemon-in-c>
33
* Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
44
* Modifications (2012-present) by Daniel Graziotin <daniel@ineed.coffee>
5+
* Modifications (2017-present) by Robert Musial <rmusial@fastmail.com>
56
*
67
* This program is free software: you can redistribute it and/or modify
78
* it under the terms of the GNU General Public License as published by
@@ -20,6 +21,7 @@
2021
#include <sys/stat.h>
2122
#include <stdio.h>
2223
#include <stdlib.h>
24+
#include <stdbool.h>
2325
#include <fcntl.h>
2426
#include <errno.h>
2527
#include <syslog.h>
@@ -77,7 +79,7 @@ static void cleanup_and_exit(int exit_code)
7779
delete_pid();
7880
set_fans_auto(fans);
7981

80-
s_fans *next_fan;
82+
struct s_fans *next_fan;
8183
while (fans != NULL) {
8284
next_fan = fans->next;
8385
free(fans->fan_output_path);
@@ -86,7 +88,7 @@ static void cleanup_and_exit(int exit_code)
8688
fans = next_fan;
8789
}
8890

89-
s_sensors *next_sensor;
91+
struct s_sensors *next_sensor;
9092
while (sensors != NULL) {
9193
next_sensor = sensors->next;
9294
free(sensors->path);

src/main.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/**
22
* Copyright (C) (2012-present) Daniel Graziotin <daniel@ineed.coffee>
3+
* Modifications (2017-present) by Robert Musial <rmusial@fastmail.com>
34
*
45
* This program is free software: you can redistribute it and/or modify
56
* it under the terms of the GNU General Public License as published by
@@ -21,6 +22,7 @@
2122
#include <stdlib.h>
2223
#include <unistd.h>
2324
#include <syslog.h>
25+
#include <stdbool.h>
2426
#include <sys/types.h>
2527
#include <dirent.h>
2628
#include <errno.h>
@@ -145,4 +147,4 @@ int main(int argc, char *argv[])
145147
void (*fan_control)() = mbpfan;
146148
go_daemon(fan_control);
147149
exit(EXIT_SUCCESS);
148-
}
150+
}

src/mbpfan.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Modifications by Rafael Vega <rvega@elsoftwarehamuerto.org>
55
* Modifications (2012) by Ismail Khatib <ikhatib@gmail.com>
66
* Modifications (2012-present) by Daniel Graziotin <daniel@ineed.coffee> [CURRENT MAINTAINER]
7+
* Modifications (2017-present) by Robert Musial <rmusial@fastmail.com>
78
*
89
* This program is free software: you can redistribute it and/or modify
910
* it under the terms of the GNU General Public License as published by
@@ -32,6 +33,7 @@
3233
#include <string.h>
3334
#include <math.h>
3435
#include <syslog.h>
36+
#include <stdbool.h>
3537
#include <sys/utsname.h>
3638
#include <sys/errno.h>
3739
#include "mbpfan.h"
@@ -73,6 +75,17 @@ bool is_legacy_kernel()
7375
exit(EXIT_FAILURE);
7476
}
7577

78+
// possible fix for https://github.com/dgraziotin/mbpfan/issues/92
79+
// to be soon investigated.
80+
// thanks http://stackoverflow.com/questions/18192998/plain-c-opening-a-directory-with-fopen
81+
// fopen("/sys/devices/platform/coretemp.0/hwmon", "wb");
82+
83+
// if (errno == EISDIR) {
84+
// return 0;
85+
// } else {
86+
// return 1;
87+
// }
88+
7689
str_kernel_version = strtok(NULL, ".");
7790
int kernel_version = atoi(str_kernel_version);
7891

src/minunit.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <time.h>
55
#include <limits.h>
66
#include <signal.h>
7+
#include <stdbool.h>
78
#include <sys/utsname.h>
89
#include "global.h"
910
#include "mbpfan.h"

0 commit comments

Comments
 (0)