Skip to content

Commit

Permalink
Merge pull request primesearch#17 from proski/unified-makefile
Browse files Browse the repository at this point in the history
Unify makefiles for Linux and MacOS
  • Loading branch information
ixfd64 authored Feb 4, 2025
2 parents 4fc10d2 + b7da6f8 commit 1889fb9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ jobs:
brew install pocl
- name: Build
run: |
make -C src -f Makefile.macOS -j "$(sysctl -n hw.ncpu)" CC=${CC} CPP=${CPP} CFLAGS="-O3 -Wall $(pkg-config --cflags pocl)" LDFLAGS="$(pkg-config --libs pocl)"
make -C src -j "$(sysctl -n hw.ncpu)" CC=${CC} CPP=${CPP} AMD_APP_INCLUDE="$(pkg-config --cflags pocl)" AMD_APP_LIB="$(pkg-config --libs pocl)"
- name: Test
run: |
./mfakto -d 11
86 changes: 49 additions & 37 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
# You should have received a copy of the GNU General Public License
# along with mfaktc (mfakto). If not, see <http://www.gnu.org/licenses/>.
#
# Version 0.15
#
# Run "make" to compile mfakto. You can pass parameters on the make command
# line to override defaults. For example, use "make bitness=32 static=yes"
# to compile a 32-bit binary and link statically.
#
# Example: "make bitness=32 static=yes" to compile for 32 bits and link
# statically
# MacOS Users may see an "out of sync" warning when compiling mfakto. Although
# harmless, the warning can be silenced by running the following command prior
# to compilation:
#
# export SDKROOT=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk


ARCH := $(shell uname -m)
BITS := -m64

# check whether to build 32-bit version
ifdef bitness
Expand All @@ -39,18 +44,18 @@ ifdef static
endif
endif

# use OS-specific commands
ifneq (, $(shell which install))
CP = install -m 555
RM = rm -f
# OS commands
RM = rm -f
INSTALL = install

# MacOS specific flags
OS = $(shell uname -s)
ifeq ($(OS), Darwin)
ARCHFLAGS = -arch $(ARCH)
OPENCL_LIB = -framework OpenCL
else
ifeq ($(OS), Windows_NT)
CP = copy
RM = del /f
else
CP = cp
RM = rm -f
endif
ARCHFLAGS =
OPENCL_LIB = -lOpenCL
endif

# where is the OpenCL SDK installed?
Expand All @@ -61,25 +66,29 @@ AMD_APP_LIB = -L$(AMD_APP_DIR)/lib/$(ARCH)
# Change needed for compilation with amdgpu-pro
# AMD_APP_DIR = /opt/amdgpu-pro/opencl

# optimize or debug
#OPTIMIZE_FLAG = -O3
#OPTIMIZE_FLAG = -O3 -funroll-loops -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las
OPTIMIZE_FLAG = -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto
#OPTIMIZE_FLAG = -g
#OPTIMIZE_FLAG = -ggdb

# compiler settings for C and C++ files
CC = gcc
CPP = $(CC)
CFLAGS = $(BITS) -Wall $(OPTIMIZE_FLAG) $(AMD_APP_INCLUDE)
CPP = g++
CFLAGS = $(ARCHFLAGS) $(BITS) -Wall $(OPTIMIZE_FLAG) $(AMD_APP_INCLUDE)
CPPFLAGS =
#CFLAGS_EXTRA_SIEVE = -funroll-all-loops
#CFLAGS_EXTRA_SIEVE = -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -floop-parallelize-all -fvariable-expansion-in-unroller -fno-align-labels
CFLAGS_EXTRA_SIEVE = -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -fno-align-labels

# Linker
LD = g++
LDFLAGS = $(BITS) $(STATIC) $(OPTIMIZE_FLAG) $(AMD_APP_LIB) -lOpenCL
LD = $(CPP)
LDFLAGS = $(ARCHFLAGS) $(BITS) $(STATIC) $(OPTIMIZE_FLAG) $(AMD_APP_LIB) $(OPENCL_LIB)

CC_VERSION = $(shell $(CC) --version)

# optimize or debug
ifneq (, $(findstring gcc, $(CC_VERSION)))
OPTIMIZE_FLAG = -O3 -funroll-loops -ffast-math -finline-functions -frerun-loop-opt -fgcse-sm -fgcse-las -flto
CFLAGS_EXTRA_SIEVE = -funroll-all-loops -funsafe-loop-optimizations -fira-region=all -fsched-spec-load -fsched-stalled-insns=10 -fsched-stalled-insns-dep=10 -fno-align-labels
else ifneq (, $(findstring clang, $(CC_VERSION)))
OPTIMIZE_FLAG = -O3 -funroll-loops -ffast-math -finline-functions -flto
CFLAGS_EXTRA_SIEVE =
else
OPTIMIZE_FLAG = -O3
CFLAGS_EXTRA_SIEVE =
endif

##############################################################################

Expand All @@ -92,15 +101,15 @@ COBJS = $(CSRC:.c=.o) mfakto.o gpusieve.o perftest.o menu.o kbhit.o

##############################################################################

.PHONY all:
all: ../mfakto ../barrett15.cl ../barrett.cl ../common.cl ../gpusieve.cl ../mfakto_Kernels.cl ../montgomery.cl ../mul24.cl ../datatypes.h ../tf_debug.h ../mfakto.ini
#@echo OS is $(OS) and ARCH is $(ARCH) and SHELL is $(SHELL)
echo $@ > $@
ALL_TARGETS = ../mfakto ../barrett15.cl ../barrett.cl ../common.cl \
../gpusieve.cl ../mfakto_Kernels.cl ../montgomery.cl \
../mul24.cl ../datatypes.h ../tf_debug.h ../mfakto.ini

all: $(ALL_TARGETS)

../mfakto : $(COBJS)
$(LD) $^ $(LDFLAGS) -o $@

.PHONY clean:
clean:
$(RM) *.o *~ depend

Expand All @@ -114,13 +123,16 @@ sieve.o : sieve.c
$(CPP) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

../%.cl : %.cl
$(CP) $< ..
$(INSTALL) -m 444 $< ..

../%.h : %.h
$(CP) $< ..
$(INSTALL) -m 444 $< ..

../%.ini : %.ini
$(CP) $< ..
$(INSTALL) -m 644 $< ..

.PHONY: all clean


##############################################################################

Expand Down
80 changes: 0 additions & 80 deletions src/Makefile.macOS

This file was deleted.

0 comments on commit 1889fb9

Please sign in to comment.