star-sp

Random number generators and distributions
git clone git://git.meso-star.fr/star-sp.git
Log | Files | Refs | README | LICENSE

Makefile (6490B)


      1 # Copyright (C) 2015-2025 |Méso|Star> (contact@meso-star.com)
      2 #
      3 # This program is free software: you can redistribute it and/or modify
      4 # it under the terms of the GNU General Public License as published by
      5 # the Free Software Foundation, either version 3 of the License, or
      6 # (at your option) any later version.
      7 #
      8 # This program is distributed in the hope that it will be useful,
      9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     11 # GNU General Public License for more details.
     12 #
     13 # You should have received a copy of the GNU General Public License
     14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     15 
     16 .POSIX:
     17 .SUFFIXES: # Clean up default inference rules
     18 
     19 include config.mk
     20 
     21 LIBNAME_STATIC = libstar-sp.a
     22 LIBNAME_SHARED = libstar-sp.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 default: library
     26 all: library tests
     27 
     28 ################################################################################
     29 # Star-SP building
     30 ################################################################################
     31 SRC =\
     32  src/ssp_ran.c\
     33  src/ssp_ranst_discrete.c\
     34  src/ssp_ranst_gaussian.c\
     35  src/ssp_ranst_piecewise_linear.c\
     36  src/ssp_rng.c\
     37  src/ssp_rng_proxy.c
     38 
     39 OBJ = $(SRC:.c=.o)
     40 DEP = $(SRC:.c=.d)
     41 
     42 library: .config $(DEP)
     43 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     44 	$$(if [ -n "$(LIBNAME)" ]; then \
     45 	     echo "$(LIBNAME)"; \
     46 	   else \
     47 	     echo "$(LIBNAME_SHARED)"; \
     48 	   fi)
     49 
     50 $(DEP) $(OBJ): config.mk
     51 
     52 $(LIBNAME_SHARED): $(OBJ)
     53 	$(CXX) $(CXXFLAGS) $(INCS) -o $@ $(OBJ) $(LDFLAGS_SO) $(LIBS)
     54 
     55 $(LIBNAME_STATIC): libstar-sp.o
     56 	$(AR) -rc $@ $?
     57 	$(RANLIB) $@
     58 
     59 libstar-sp.o: $(OBJ)
     60 	$(LD) -r $(OBJ) -o $@
     61 	$(OBJCOPY) $(OCPFLAGS) $@
     62 
     63 .config: config.mk
     64 	$(PKG_CONFIG) --atleast-version $(RANDOM123_VERSION) random123
     65 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     66 	@echo "config done" > .config
     67 
     68 .SUFFIXES: .c .d .o
     69 .c.d:
     70 	@$(CXX) $(CXXFLAGS) $(INCS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     71 
     72 .c.o:
     73 	$(CXX) $(CXXFLAGS) $(INCS) -DSSP_SHARED_BUILD -c $< -o $@
     74 
     75 ################################################################################
     76 # Miscellaneous
     77 ################################################################################
     78 pkg:
     79 	sed -e 's#@PREFIX@#$(PREFIX)#g' \
     80 	    -e 's#@VERSION@#$(VERSION)#g' \
     81 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
     82 	    -e 's#@RANDOM123_VERSION@#$(RANDOM123_VERSION)#g' \
     83 	    star-sp.pc.in > star-sp.pc
     84 
     85 star-sp-local.pc: config.mk star-sp.pc.in
     86 	sed -e '1d'\
     87 	    -e 's#^includedir=.*#includedir=./src/#'\
     88 	    -e 's#^libdir=.*#libdir=./#'\
     89 	    -e 's#@PREFIX@#$(PREFIX)#g'\
     90 	    -e 's#@VERSION@#$(VERSION)#g'\
     91 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     92 	    -e 's#@RANDOM123_VERSION@#$(RANDOM123_VERSION)#g'\
     93 	    star-sp.pc.in > $@
     94 
     95 install: library pkg
     96 	install() { mode="$$1"; prefix="$$2"; shift 2; \
     97 	  mkdir -p "$${prefix}"; \
     98 	  cp "$$@" "$${prefix}"; \
     99 	  chmod "$${mode}" "$$@"; \
    100 	}; \
    101 	install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
    102 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" star-sp.pc; \
    103 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/ssp.h; \
    104 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-sp" COPYING README.md
    105 
    106 uninstall:
    107 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
    108 	rm -f "$(DESTDIR)$(INCPREFIX)/star/ssp.h"
    109 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/star-sp.pc"
    110 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-sp/COPYING"
    111 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-sp/README.md"
    112 
    113 clean: clean_test
    114 	rm -f $(DEP) $(OBJ) $(LIBNAME)
    115 	rm -f .config libstar-sp.o star-sp.pc star-sp-local.pc
    116 
    117 ################################################################################
    118 # Tests
    119 ################################################################################
    120 TEST_SRC =\
    121  src/test_ssp_ran_circle.c\
    122  src/test_ssp_ran_discrete.c\
    123  src/test_ssp_ran_gaussian.c\
    124  src/test_ssp_ran_hemisphere.c\
    125  src/test_ssp_ran_hg.c\
    126  src/test_ssp_ran_piecewise_linear.c\
    127  src/test_ssp_ran_sphere.c\
    128  src/test_ssp_ran_sphere_cap.c\
    129  src/test_ssp_ran_spherical_zone.c\
    130  src/test_ssp_ran_tetrahedron.c\
    131  src/test_ssp_ran_triangle.c\
    132  src/test_ssp_ran_uniform_disk.c\
    133  src/test_ssp_rng.c\
    134  src/test_ssp_rng_proxy.c
    135 TEST_OBJ = $(TEST_SRC:.c=.o)
    136 TEST_DEP = $(TEST_SRC:.c=.d)
    137 TEST_TGT = $(TEST_SRC:.c=.t)
    138 
    139 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    140 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys star-sp-local.pc)
    141 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys star-sp-local.pc)
    142 
    143 CFLAGS_TEST = $(CFLAGS) $(INCS_TEST)
    144 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST) -lm
    145 
    146 tests: library $(TEST_DEP) $(TEST_TGT)
    147 	@$(MAKE) -fMakefile \
    148 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    149 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    150 	test_list
    151 
    152 $(TEST_TGT):
    153 	@{ \
    154 	  exe="$$(basename "$@" ".t")"; \
    155 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    156 	  printf 'test_list: %s\n' "$${exe}"; \
    157 	} > $@
    158 
    159 $(TEST_DEP): config.mk star-sp-local.pc
    160 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    161 
    162 $(TEST_OBJ): config.mk star-sp-local.pc
    163 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    164 
    165 test_ssp_ran_circle \
    166 test_ssp_ran_discrete \
    167 test_ssp_ran_gaussian \
    168 test_ssp_ran_hemisphere \
    169 test_ssp_ran_hg \
    170 test_ssp_ran_piecewise_linear \
    171 test_ssp_ran_sphere \
    172 test_ssp_ran_sphere_cap \
    173 test_ssp_ran_spherical_zone \
    174 test_ssp_ran_tetrahedron \
    175 test_ssp_ran_triangle \
    176 test_ssp_ran_uniform_disk \
    177 test_ssp_rng \
    178 test_ssp_rng_proxy \
    179 : config.mk star-sp-local.pc $(LIBNAME)
    180 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    181 
    182 clean_test:
    183 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
    184 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done
    185 
    186 test: tests
    187 	@err=0; \
    188 	check() { name="$$1"; exe="$$2"; shift 2; \
    189 	  printf '%s %s' "$${name}" "$$@"; \
    190 	  if "./$${exe}" "$$@"> /dev/null 2>&1; then \
    191 	    printf '\n'; \
    192 	  else \
    193 	    printf ': error %s\n' "$$?"; \
    194 	    err=$$((err+1)); \
    195 	  fi \
    196 	}; \
    197 	for i in $(TEST_SRC); do \
    198 	  test="$$(basename "$${i}" ".c")"; \
    199 	  if [ "$${test}" != "test_ssp_rng" ]; then \
    200 	    check "$${test}" "$${test}"; \
    201 	  else \
    202 	    if [ -n "$(AES_CFLAGS)" ]; then \
    203 	      check test_ssp_rng_aes test_ssp_rng aes; \
    204 	    fi; \
    205 	    check test_ssp_rng_kiss test_ssp_rng kiss; \
    206 	    check test_ssp_rng_mt19937_64 test_ssp_rng mt19937_64; \
    207 	    check test_ssp_rng_ranlux48 test_ssp_rng ranlux48; \
    208 	    check test_ssp_rng_random_device test_ssp_rng random_device; \
    209 	    check test_ssp_rng_threefry test_ssp_rng threefry; \
    210 	  fi \
    211 	done; \
    212 	[ "$${err}" -eq 0 ]