From b7da6f83e1f54c197f7569b7b8d2baa4260d9c76 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 5 Jan 2025 21:37:59 -0800 Subject: [PATCH] Unify makefiles for Linux and MacOS Don't pass BITS to the compiler unless bitness is overridden. Don't try to support generic Windows. MSYS has the install command, MSVC doesn't use the Makefile. Use the install command unconditionally. Make mfakto.ini writable when installed. Set the optimization flags based on whether the compiler is clang or gcc, not based on the OS. Compile C++ files with the C++ compiler. Properly mark targets as phony, the syntax was incorrect. The "src/all" file is not created anymore. Don't override CFLAGS and LDFLAGS on MacOS in CI. --- .github/workflows/ci.yml | 2 +- src/Makefile | 86 +++++++++++++++++++++++----------------- src/Makefile.macOS | 80 ------------------------------------- 3 files changed, 50 insertions(+), 118 deletions(-) delete mode 100644 src/Makefile.macOS diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6570f6f..57e9eb6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/src/Makefile b/src/Makefile index 3aced8c..a924a34 100644 --- a/src/Makefile +++ b/src/Makefile @@ -15,14 +15,19 @@ # You should have received a copy of the GNU General Public License # along with mfaktc (mfakto). If not, see . # -# 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 @@ -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? @@ -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 ############################################################################## @@ -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 @@ -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 + ############################################################################## diff --git a/src/Makefile.macOS b/src/Makefile.macOS deleted file mode 100644 index a4c6f3b..0000000 --- a/src/Makefile.macOS +++ /dev/null @@ -1,80 +0,0 @@ -# This file is part of mfaktc (mfakto). -# Copyright (C) 2009 - 2011, 2014 Oliver Weihe (o.weihe@t-online.de) -# Bertram Franz (bertramf@gmx.net) -# -# mfaktc (mfakto) is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# mfaktc (mfakto) is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with mfaktc (mfakto). If not, see . -# -# Version 0.15 -# -# -# Run "make -f Makefile.macOS" to compile mfakto for 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) - -# compiler settings for C and C++ files -CC = gcc -CPP = $(CC) -CFLAGS = -arch $(ARCH) -Wall -CPPFLAGS = - -# Linker -LD = g++ -LDFLAGS = -arch $(ARCH) - -############################################################################## - -CSRC = sieve.c timer.c parse.c read_config.c mfaktc.c checkpoint.c \ - signal_handler.c filelocking.c output.c - -# CLSRC = barrett15.cl barrett.cl common.cl gpusieve.cl mfakto_Kernels.cl montgomery.cl mul24.cl - -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 - -../mfakto : $(COBJS) - $(LD) $^ $(LDFLAGS) -o $@ -framework OpenCL - -.PHONY clean: -clean: - rm -f *.o *~ - -sieve.o : sieve.c - $(CC) $(CFLAGS) -c $< -o $@ - -%.o : %.c - $(CC) $(CFLAGS) -c $< -o $@ - -%.o : %.cpp - $(CPP) $(CFLAGS) $(CPPFLAGS) -c $< -o $@ - -../%.cl : %.cl - cp $< .. - -../%.h : %.h - cp $< .. - -../%.ini : %.ini - cp $< .. - -##############################################################################