/ Makefile
Makefile
  1  # This software is part of libcsdr, a set of simple DSP routines for 
  2  # Software Defined Radio.
  3  #
  4  # Copyright (c) 2014, Andras Retzler <randras@sdr.hu>
  5  # All rights reserved.
  6  # 
  7  # Redistribution and use in source and binary forms, with or without
  8  # modification, are permitted provided that the following conditions are met:
  9  #    * Redistributions of source code must retain the above copyright
 10  #      notice, this list of conditions and the following disclaimer.
 11  #    * Redistributions in binary form must reproduce the above copyright
 12  #      notice, this list of conditions and the following disclaimer in the
 13  #      documentation and/or other materials provided with the distribution.
 14  #    * Neither the name of the copyright holder nor the
 15  #      names of its contributors may be used to endorse or promote products
 16  #      derived from this software without specific prior written permission.
 17  #
 18  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 19  # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 20  # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 21  # DISCLAIMED. IN NO EVENT SHALL ANDRAS RETZLER BE LIABLE FOR ANY
 22  # DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 24  # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 25  # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 26  # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 27  # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 28  
 29  LIBSOURCES =  fft_fftw.c libcsdr_wrapper.c 
 30  #SOURCES = csdr.c $(LIBSOURCES)
 31  cpufeature = $(if $(findstring $(1),$(shell cat /proc/cpuinfo)),$(2))
 32  PARAMS_SSE = $(call cpufeature,sse,-msse) $(call cpufeature,sse2,-msse2) $(call cpufeature,sse3,-msse3) $(call cpufeature,sse4a,-msse4a) $(call cpufeature,sse4_1,-msse4.1) $(call cpufeature,sse4_2,-msse4.2 -msse4) -mfpmath=sse 
 33  PARAMS_NEON = -mfloat-abi=hard -march=armv7-a -mtune=cortex-a8 -mfpu=neon -mvectorize-with-neon-quad -funsafe-math-optimizations -Wformat=0 -DNEON_OPTS
 34  #tnx Jan Szumiec for the Raspberry Pi support
 35  PARAMS_RASPI = -mfloat-abi=hard -mcpu=arm1176jzf-s -mfpu=vfp -funsafe-math-optimizations -Wformat=0
 36  PARAMS_ARM = $(if $(call cpufeature,BCM2708,dummy-text),$(PARAMS_RASPI),$(PARAMS_NEON))
 37  PARAMS_SIMD = $(if $(call cpufeature,sse,dummy-text),$(PARAMS_SSE),$(PARAMS_ARM))
 38  PARAMS_LOOPVECT = -O3 -ffast-math -fdump-tree-vect-details -dumpbase dumpvect
 39  PARAMS_LIBS = -g -lm -lrt -lfftw3f -DUSE_FFTW -DLIBCSDR_GPL -DUSE_IMA_ADPCM
 40  PARAMS_SO = -fpic  
 41  PARAMS_MISC = -Wno-unused-result
 42  #DEBUG_ON = 0 #debug is always on by now (anyway it could be compiled with `make DEBUG_ON=1`)
 43  #PARAMS_DEBUG = $(if $(DEBUG_ON),-g,)
 44  FFTW_PACKAGE = fftw-3.3.3
 45  PREFIX ?= /usr
 46  SOVERSION = 0.15
 47  PARSEVECT ?= yes
 48  
 49  .PHONY: clean-vect clean codequality checkdocs v
 50  all: codequality csdr nmux
 51  libcsdr.so: fft_fftw.c fft_rpi.c libcsdr_wrapper.c libcsdr.c libcsdr_gpl.c fastddc.c fastddc.h  fft_fftw.h  fft_rpi.h  ima_adpcm.h  libcsdr_gpl.h  libcsdr.h  predefined.h
 52  	@echo NOTE: you may have to manually edit Makefile to optimize for your CPU \(especially if you compile on ARM, please edit PARAMS_NEON\).
 53  	@echo Auto-detected optimization parameters: $(PARAMS_SIMD)
 54  	@echo
 55  	rm -f dumpvect*.vect
 56  	gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) $(LIBSOURCES) $(PARAMS_LIBS) $(PARAMS_MISC) -fpic -shared -Wl,-soname,libcsdr.so.$(SOVERSION) -o libcsdr.so.$(SOVERSION)
 57  	@ln -fs libcsdr.so.$(SOVERSION) libcsdr.so
 58  ifeq ($(PARSEVECT),yes)
 59  	-./parsevect dumpvect*.vect
 60  endif
 61  csdr: csdr.c libcsdr.so
 62  	gcc -std=gnu99 $(PARAMS_LOOPVECT) $(PARAMS_SIMD) csdr.c $(PARAMS_LIBS) -L. -lcsdr $(PARAMS_MISC) -o csdr
 63  ddcd: ddcd.cpp libcsdr.so ddcd.h
 64  	g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) ddcd.cpp $(PARAMS_LIBS) -L. -lcsdr -lpthread $(PARAMS_MISC) -o ddcd
 65  nmux: nmux.cpp libcsdr.so nmux.h tsmpool.cpp tsmpool.h
 66  	g++ $(PARAMS_LOOPVECT) $(PARAMS_SIMD) nmux.cpp tsmpool.cpp $(PARAMS_LIBS) -L. -lcsdr -lpthread $(PARAMS_MISC) -o nmux
 67  arm-cross: clean-vect
 68  	#note: this doesn't work since having added FFTW
 69  	arm-linux-gnueabihf-gcc -std=gnu99 -O3 -fshort-double -ffast-math -dumpbase dumpvect-arm -fdump-tree-vect-details -mfloat-abi=softfp -march=armv7-a -mtune=cortex-a9 -mfpu=neon -mvectorize-with-neon-quad -Wno-unused-result -Wformat=0 $(SOURCES) -lm -o ./csdr
 70  clean-vect:
 71  	rm -f dumpvect*.vect
 72  clean: clean-vect
 73  	rm -f libcsdr.so.$(SOVERSION) csdr ddcd nmux *.o *.so
 74  install: all 
 75  	install -m 0755 libcsdr.so.$(SOVERSION) $(PREFIX)/lib
 76  	install -m 0755 csdr $(PREFIX)/bin
 77  	install -m 0755 csdr-fm $(PREFIX)/bin
 78  	install -m 0755 nmux $(PREFIX)/bin
 79  	#-install -m 0755 ddcd $(PREFIX)/bin
 80  	@ldconfig || echo please run ldconfig
 81  uninstall:
 82  	rm $(PREFIX)/lib/libcsdr.so.$(SOVERSION) $(PREFIX)/bin/csdr $(PREFIX)/bin/csdr-fm
 83  	ldconfig
 84  disasm:
 85  	objdump -S libcsdr.so.$(SOVERSION) > libcsdr.disasm
 86  emcc-clean:
 87  	-rm sdr.js/sdr.js
 88  	-rm sdr.js/sdrjs-compiled.js
 89  	-rm -rf sdr.js/$(FFTW_PACKAGE)
 90  emcc-get-deps:
 91  	echo "getting and compiling fftw3 with emscripten..."
 92  	cd sdr.js; \
 93  	wget http://fftw.org/$(FFTW_PACKAGE).tar.gz; \
 94  	tar -xvf $(FFTW_PACKAGE).tar.gz; \
 95  	rm $(FFTW_PACKAGE).tar.gz; \
 96  	cd $(FFTW_PACKAGE); \
 97  	emconfigure ./configure --enable-float --disable-fortran --prefix=`pwd`/emscripten-install --libdir=`pwd`/emscripten-lib; \
 98  	emmake make; \
 99  	emmake make install
100  emcc:
101  	emcc -O3 -Isdr.js/$(FFTW_PACKAGE)/api -Lsdr.js/$(FFTW_PACKAGE)/emscripten-lib -o sdr.js/sdrjs-compiled.js fft_fftw.c libcsdr_wrapper.c -s TOTAL_MEMORY=67108864 -DLIBCSDR_GPL -DUSE_IMA_ADPCM -DUSE_FFTW -lfftw3f -s EXPORTED_FUNCTIONS="`python sdr.js/exported_functions.py`"
102  	cat sdr.js/sdrjs-header.js sdr.js/sdrjs-compiled.js sdr.js/sdrjs-footer.js > sdr.js/sdr.js
103  emcc-beautify:
104  	bash -c 'type js-beautify >/dev/null 2>&1; if [ $$? -eq 0 ]; then js-beautify sdr.js/sdr.js >sdr.js/sdr.js.beautiful; mv sdr.js/sdr.js.beautiful sdr.js/sdr.js; fi'
105  codequality:
106  	@bash -c 'if [ `cat csdr.c | grep badsyntax | grep -v return | wc -l` -ne 1 ]; then echo "error at code quality check: badsyntax() used in csdr.c without return."; exit 1; else exit 0; fi'
107  checkdocs:
108  	@cat csdr.c | grep strcmp | egrep 'argv\[1\]' | awk -F'"' '$$0=$$2' > /tmp/csdr-list-of-functions
109  	@cat /tmp/csdr-list-of-functions | xargs -I{} bash -c 'if ! cat csdr.c | grep \"\ \ \ \ {} >/dev/null ; then echo "warning: \"{}\"  is in csdr.c code, but not in usage string"; fi'
110  	@cat /tmp/csdr-list-of-functions | xargs -I{} bash -c 'if ! cat README.md | grep {} >/dev/null ; then echo "warning: \"{}\"  is in csdr.c code, but not in README.md"; fi'
111  	@rm /tmp/csdr-list-of-functions
112  v:
113  	vim csdr.c libcsdr.c