Skip to content
This repository has been archived by the owner on May 27, 2020. It is now read-only.

Commit

Permalink
Modularize code: main.c -> device-cpu + device-gpu
Browse files Browse the repository at this point in the history
This patch is an initial attempt to re-structure cgminer source
code from its monolithic design (with nearly all code being
concentrated in main.c) to a more modular one.

In this first stage, the conditionally compiled functions for
GPU and CPU mining were extracted into dedicated files:
 * device-cpu.h and device-cpu.c covering WANT_CPUMINE functions
 * device-gpu.h and device-gpu.c covering HAVE_OPENCL functions

The main.c file is left untouched as reference, while the
remainder without the extracted parts is located in cgminer.c.

The Makefile.am has been updated to use the re-structured
source files for the build.

Above pure re-structuring *NO* functional modifications were
made. The sources were tested to compile and run on on a
current Linux system with working CPU and GPU mining
(Bitforce not tested due to loack of hardware).
  • Loading branch information
zefir authored and ckolivas committed Feb 3, 2012
1 parent 55f693a commit e0b0a6c
Show file tree
Hide file tree
Showing 6 changed files with 6,577 additions and 30 deletions.
69 changes: 39 additions & 30 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -17,50 +17,59 @@ INCLUDES = $(PTHREAD_FLAGS) -fno-strict-aliasing $(JANSSON_INCLUDES)

bin_PROGRAMS = cgminer

bin_SCRIPTS = phatk110817.cl poclbm110817.cl

if HAS_CPUMINE
cgminer_SOURCES = elist.h miner.h compat.h bench_block.h \
main.c util.c uthash.h \
ocl.c ocl.h findnonce.c findnonce.h \
sha256_generic.c sha256_4way.c sha256_via.c \
sha256_cryptopp.c sha256_sse2_amd64.c \
sha256_sse4_amd64.c sha256_sse2_i386.c \
sha256_altivec_4way.c \
adl.c adl.h adl_functions.h \
phatk110817.cl poclbm110817.cl \
sha2.c sha2.h api.c
else
cgminer_SOURCES = elist.h miner.h compat.h bench_block.h \
main.c util.c uthash.h \
ocl.c ocl.h findnonce.c findnonce.h \
adl.c adl.h adl_functions.h \
phatk110817.cl poclbm110817.cl \
sha2.c sha2.h api.c
endif
bin_SCRIPTS = phatk120203.cl poclbm120203.cl

cgminer_LDFLAGS = $(PTHREAD_FLAGS)
cgminer_LDADD = $(DLOPEN_FLAGS) @LIBCURL_LIBS@ @JANSSON_LIBS@ @PTHREAD_LIBS@ \
@OPENCL_LIBS@ @NCURSES_LIBS@ @PDCURSES_LIBS@ @WS2_LIBS@ \
@MATH_LIBS@ lib/libgnu.a ccan/libccan.a
cgminer_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib @OPENCL_FLAGS@

# common sources

# this is the original monolithic main.c, kept as reference
# cgminer_SOURCES := main.c

# this is the original main.c without extracted CPU and GPU code
cgminer_SOURCES := cgminer.c

cgminer_SOURCES += elist.h miner.h compat.h bench_block.h \
util.c uthash.h \
sha2.c sha2.h api.c

# GPU sources, TODO: make them selectable
# the GPU portion extracted from original main.c
cgminer_SOURCES += device-gpu.h device-gpu.c

# the original GPU related sources, unchanged
cgminer_SOURCES += ocl.c ocl.h findnonce.c findnonce.h
cgminer_SOURCES += adl.c adl.h adl_functions.h
cgminer_SOURCES += phatk120203.cl poclbm120203.cl

if HAS_CPUMINE
if HAVE_x86_64
# original CPU related sources, unchanged
cgminer_SOURCES += \
sha256_generic.c sha256_4way.c sha256_via.c \
sha256_cryptopp.c sha256_sse2_amd64.c \
sha256_sse4_amd64.c sha256_sse2_i386.c \
sha256_altivec_4way.c

# the CPU portion extracted from original main.c
cgminer_SOURCES += device-cpu.h device-cpu.c

if HAS_YASM
AM_CFLAGS = -DHAS_YASM
if HAVE_x86_64
SUBDIRS += x86_64
cgminer_LDADD += x86_64/libx8664.a
AM_CFLAGS = -DHAS_YASM
endif
else
if HAS_YASM
else # HAVE_x86_64
SUBDIRS += x86_32
cgminer_LDADD += x86_32/libx8632.a
AM_CFLAGS = -DHAS_YASM
endif
endif
endif
endif # HAVE_x86_64
endif # HAS_YASM
endif # HAS_CPUMINE

if HAS_BITFORCE
cgminer_SOURCES += bitforce.c
endif

Loading

0 comments on commit e0b0a6c

Please sign in to comment.