Skip to content

Commit

Permalink
fix: Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
christiangda committed Mar 31, 2024
1 parent 040c7aa commit 96087da
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
25 changes: 24 additions & 1 deletion .github/workflows/c-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -38,4 +38,27 @@ jobs:
- name: make memcheck
run: make memcheck

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -y
sudo apt-get install -y gcc-13 valgrind
- name: Set up gcc-13
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90
- name: Check versions
run: |
gcc --version
make --version
- name: make build
run: make build

18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
TEST_APP = test_linkedlist
TARGET_LIB = linkedlistlib.so

CC_MACOS = "/opt/homebrew/bin/gcc-13"
CC_LINUX = "/usr/bin/gcc"
CC_MACOS ?= /opt/homebrew/bin/gcc-13
CC_LINUX ?= /usr/bin/gcc

AR_MACOS = "/opt/homebrew/bin/gcc-ar-13"
AR_LINUX = "/usr/bin/ar"
AR_MACOS ?= /opt/homebrew/bin/gcc-ar-13
AR_LINUX ?= /usr/bin/ar

MEMCHECK_MACOS = "/usr/bin/leaks"
MEMCHECK_LINUX = "/usr/bin/valgrind"
MEMCHECK_MACOS ?= /usr/bin/leaks
MEMCHECK_LINUX ?= /usr/bin/valgrind

# Determine OS
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Darwin)
MEMCHECK = $(MEMCHECK_MACOS)
MEMCHECK_ARGS = --atExit --
CC = $(CC_MACOS)
AR = $(AR_MACOS)
endif
ifeq ($(UNAME_S),Linux)
MEMCHECK = $(MEMCHECK_LINUX)
MEMCHECK_ARGS =
CC = $(CC_LINUX)
AR = $(AR_LINUX)
endif
Expand Down Expand Up @@ -97,8 +99,8 @@ test: clean build $(TEST_APP) ## Run tests

.PHONY: memcheck
memcheck: test ## Run tests and check for memory leaks
@echo "Running tests with valgrind..."
leaks --atExit -- ./$(BUILD_DIR)/$(TEST_APP)
@echo "Running tests with memory check..."
$(MEMCHECK) $(MEMCHECK_ARGS) ./$(BUILD_DIR)/$(TEST_APP)

##@ Clean commands
.PHONY: clean
Expand Down

0 comments on commit 96087da

Please sign in to comment.