Skip to content

Commit

Permalink
Improve Makefiles
Browse files Browse the repository at this point in the history
  • Loading branch information
HiGarfield committed Dec 27, 2024
1 parent 05641f8 commit b330036
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 16 deletions.
29 changes: 21 additions & 8 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,38 @@ override CFLAGS := $(filter-out -std=% -ansi -W%, $(CFLAGS)) \
-Wstrict-prototypes \
-Werror

# If CHECK is set to 1, add stricter flags
ifeq ($(CHECK), 1)
override CFLAGS += -Wshadow \
-Wfloat-equal \
-Wformat=2 \
-Wcast-align \
-Wpointer-arith \
-Wnull-dereference \
-Wcast-qual \
-Wmissing-declarations \
-Wredundant-decls \
-Wstrict-aliasing=2 \
-Wswitch-enum \
-Wswitch-default \
-Wconversion \
-Wsign-conversion
endif

# Target binary
TARGET := cpulimit

# Detect operating system
UNAME ?= $(shell uname)

# Platform-specific linker flags
ifeq ($(UNAME), FreeBSD)
override LDFLAGS += -lkvm
endif

ifeq ($(UNAME), Darwin)
override LDFLAGS += -lproc
endif
override LDFLAGS += $(if $(findstring FreeBSD, $(UNAME)), -lkvm,) \
$(if $(findstring Darwin, $(UNAME)), -lproc,)

# Check for librt availability
override LDFLAGS += $(shell \
echo "int main(void){ return 0; }" | \
$(CC) -x c -o /dev/null -lrt - 2>/dev/null && \
$(CC) -x c -o /dev/null -lrt - >/dev/null 2>&1 && \
echo -lrt \
)

Expand Down
29 changes: 21 additions & 8 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ override CFLAGS := $(filter-out -std=% -ansi -W%, $(CFLAGS)) \
-Wstrict-prototypes \
-Werror

# If CHECK is set to 1, add stricter flags
ifeq ($(CHECK), 1)
override CFLAGS += -Wshadow \
-Wfloat-equal \
-Wformat=2 \
-Wcast-align \
-Wpointer-arith \
-Wnull-dereference \
-Wcast-qual \
-Wmissing-declarations \
-Wredundant-decls \
-Wstrict-aliasing=2 \
-Wswitch-enum \
-Wswitch-default \
-Wconversion \
-Wsign-conversion
endif

# Target binaries and source directory
TARGETS := $(patsubst %.c, %, $(wildcard *.c))
SRC := ../src
Expand All @@ -20,18 +38,13 @@ SRC := ../src
UNAME ?= $(shell uname)

# Platform-specific linker flags
ifeq ($(UNAME), FreeBSD)
override LDFLAGS += -lkvm
endif

ifeq ($(UNAME), Darwin)
override LDFLAGS += -lproc
endif
override LDFLAGS += $(if $(findstring FreeBSD, $(UNAME)), -lkvm,) \
$(if $(findstring Darwin, $(UNAME)), -lproc,)

# Check for librt availability
override LDFLAGS += $(shell \
echo "int main(void){ return 0; }" | \
$(CC) -x c -o /dev/null -lrt - 2>/dev/null && \
$(CC) -x c -o /dev/null -lrt - >/dev/null 2>&1 && \
echo -lrt \
)

Expand Down

0 comments on commit b330036

Please sign in to comment.