atrstm

Load and structure a combustion gas mixture
git clone git://git.meso-star.fr/atrstm.git
Log | Files | Refs | README | LICENSE

Makefile (7372B)


      1 # Copyright (C) 2022, 2023 |Méso|Star> (contact@meso-star.com)
      2 # Copyright (C) 2020, 2021 Centre National de la Recherche Scientifique
      3 #
      4 # This program is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU General Public License as published by
      6 # the Free Software Foundation, either version 3 of the License, or
      7 # (at your option) any later version.
      8 #
      9 # This program is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     16 
     17 .POSIX:
     18 .SUFFIXES: # Clean up default inference rules
     19 
     20 include config.mk
     21 
     22 LIBNAME_STATIC = libatrstm.a
     23 LIBNAME_SHARED = libatrstm.so
     24 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     25 
     26 ################################################################################
     27 # Library building
     28 ################################################################################
     29 SRC_REGULAR =\
     30  src/atrstm.c\
     31  src/atrstm_cache.c\
     32  src/atrstm_dump_svx_octree.c\
     33  src/atrstm_log.c\
     34  src/atrstm_partition.c\
     35  src/atrstm_radcoefs.c\
     36  src/atrstm_rdgfa.c\
     37  src/atrstm_setup_octrees.c\
     38  src/atrstm_setup_uvm.c\
     39  src/atrstm_svx.c
     40 SRC_SIMD =\
     41  $(SRC_REGULAR)\
     42  src/atrstm_radcoefs_simd4.c
     43 SRC = $(SRC_$(INSTRUCTION_SET))
     44 OBJ = $(SRC:.c=.o)
     45 DEP = $(SRC:.c=.d)
     46 
     47 build_library: .config $(DEP)
     48 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     49 	$$(if $(RSIMD_EXISTS); then \
     50 	     echo "INSTRUCTION_SET=SIMD"; \
     51 	   else \
     52 	     echo "INSTRUCTION_SET=REGULAR"; \
     53 	   fi) \
     54 	$$(if [ -n "$(LIBNAME)" ]; then \
     55 	     echo "$(LIBNAME)"; \
     56 	   else \
     57 	     echo "$(LIBNAME_SHARED)"; \
     58 	   fi)
     59 
     60 $(DEP) $(OBJ): config.mk
     61 
     62 $(LIBNAME_SHARED): $(OBJ)
     63 	$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     64 
     65 $(LIBNAME_STATIC): libatrstm.o
     66 	$(AR) -rc $@ $?
     67 	$(RANLIB) $@
     68 
     69 libatrstm.o: $(OBJ)
     70 	$(LD) -r $(OBJ) -o $@
     71 	$(OBJCOPY) $(OCPFLAGS) $@
     72 
     73 .config: config.mk
     74 	@if ! $(PKG_CONFIG) --atleast-version $(ATRRI_VERSION) atrri; then \
     75 	  echo "atrri $(ATRRI_VERSION) not found" >&2; exit 1; fi
     76 	@if ! $(PKG_CONFIG) --atleast-version $(ATRTP_VERSION) atrtp; then \
     77 	  echo "atrtp $(ATRTP_VERSION) not found" >&2; exit 1; fi
     78 	@if $(RSIMD_EXISTS); then \
     79 	   if ! $(PKG_CONFIG) --atleast-version $(RSIMD_VERSION) rsimd; then \
     80 	    echo "rsimd $(RSIMD_VERSION) not found" >&2; exit 1; fi; fi
     81 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     82 	  echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     83 	@if ! $(PKG_CONFIG) --atleast-version $(SMSH_VERSION) smsh; then \
     84 	  echo "smsh $(SMSH_VERSION) not found" >&2; exit 1; fi
     85 	@if ! $(PKG_CONFIG) --atleast-version $(SUVM_VERSION) suvm; then \
     86 	  echo "suvm $(SUVM_VERSION) not found" >&2; exit 1; fi
     87 	@if ! $(PKG_CONFIG) --atleast-version $(SVX_VERSION) svx; then \
     88 	  echo "svx $(SVX_VERSION) not found" >&2; exit 1; fi
     89 	@echo "config done" > $@
     90 
     91 .SUFFIXES: .c .d .o
     92 .c.d:
     93 	@$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     94 
     95 .c.o:
     96 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DATRSTM_SHARED_BUILD -c $< -o $@
     97 
     98 ################################################################################
     99 # Installation
    100 ################################################################################
    101 pkg:
    102 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
    103 	    -e 's#@VERSION@#$(VERSION)#g'\
    104 	    -e 's#@ATRRI_VERSION@#$(ATRRI_VERSION)#g'\
    105 	    -e 's#@ATRTP_VERSION@#$(ATRTP_VERSION)#g'\
    106 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    107 	    -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\
    108 	    -e 's#@SUVM_VERSION@#$(SUVM_VERSION)#g'\
    109 	    -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\
    110 	    atrstm.pc.in | \
    111 	if $(RSIMD_EXISTS); then \
    112 	  sed 's#@RSIMD@#, rsimd >= $(RSIMD_VERSION)#g'; \
    113 	else \
    114 	  sed 's#@RSIMD@##g'; \
    115 	fi > atrstm.pc
    116 
    117 atrstm-local.pc: atrstm.pc.in
    118 	sed -e '1d'\
    119 	    -e 's#^includedir=.*#includedir=./src/#'\
    120 	    -e 's#^libdir=.*#libdir=./#'\
    121 	    -e 's#@VERSION@#$(VERSION)#g'\
    122 	    -e 's#@ATRRI_VERSION@#$(ATRRI_VERSION)#g'\
    123 	    -e 's#@ATRTP_VERSION@#$(ATRTP_VERSION)#g'\
    124 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    125 	    -e 's#@SMSH_VERSION@#$(SMSH_VERSION)#g'\
    126 	    -e 's#@SUVM_VERSION@#$(SUVM_VERSION)#g'\
    127 	    -e 's#@SVX_VERSION@#$(SVX_VERSION)#g'\
    128 	    atrstm.pc.in | \
    129 	if $(RSIMD_EXISTS); then \
    130 	  sed 's#@RSIMD@#, rsimd >= $(RSIMD_VERSION)#g'; \
    131 	else \
    132 	  sed 's#@RSIMD@##g'; \
    133 	fi > $@
    134 
    135 install: build_library pkg
    136 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
    137 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" atrstm.pc
    138 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/astoria" src/atrstm.h
    139 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/atrstm" COPYING README.md
    140 
    141 uninstall:
    142 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
    143 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/atrstm.pc"
    144 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/atrstm/COPYING"
    145 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/atrstm/README.md"
    146 	rm -f "$(DESTDIR)$(PREFIX)/include/astoria/atrstm.h"
    147 
    148 ################################################################################
    149 # Miscellaneous targets
    150 ################################################################################
    151 all: build_library build_tests
    152 
    153 clean: clean_test
    154 	rm -f $(SRC_COMMON:.c=.o) $(SRC_SIMD:.c=.o) $(TEST_OBJ) $(LIBNAME)
    155 	rm -f .config .test libatrstm.o atrstm.pc atrstm-local.pc
    156 
    157 distclean: clean
    158 	rm -f $(SRC_COMMON:.c=.d) $(SRC_SIMD:.c=.d) $(TEST_DEP)
    159 
    160 lint:
    161 	shellcheck -o all make.sh
    162 
    163 ################################################################################
    164 # Tests
    165 ################################################################################
    166 TEST_SRC =\
    167  src/test_atrstm.c\
    168  src/test_atrstm_radcoefs.c\
    169  src/test_atrstm_radcoefs_simd.c
    170 TEST_OBJ = $(TEST_SRC:.c=.o)
    171 TEST_DEP = $(TEST_SRC:.c=.d)
    172 
    173 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    174 ATRSTM_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags atrstm-local.pc)
    175 ATRSTM_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs atrstm-local.pc)
    176 
    177 test: build_tests
    178 	@$(SHELL) make.sh run_test \
    179 	src/test_atrstm_radcoefs.c \
    180 	$$($(RSIMD_EXISTS) && echo src/test_atrstm_radcoefs_simd.c)
    181 
    182 build_tests: build_library $(TEST_DEP) .test
    183 	@$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
    184 
    185 .test: Makefile make.sh
    186 	@$(SHELL) make.sh config_test \
    187 	src/test_atrstm.c \
    188 	src/test_atrstm_radcoefs.c \
    189 	$$($(RSIMD_EXISTS) && echo src/test_atrstm_radcoefs_simd.c)	\
    190 	> $@
    191 
    192 clean_test:
    193 	$(SHELL) make.sh clean_test $(TEST_SRC)
    194 
    195 $(TEST_DEP): config.mk atrstm-local.pc
    196 	@$(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(ATRSTM_CFLAGS) \
    197 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    198 
    199 src/test_atrstm.o src/test_atrstm_radcoefs.o: config.mk atrstm-local.pc
    200 	$(CC) $(CFLAGS_EXE) $(ATRSTM_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@
    201 
    202 src/test_atrstm_radcoefs_simd.o: config.mk atrstm-local.pc
    203 	$(CC) $(CFLAGS_EXE) $(ATRSTM_CFLAGS) $(RSYS_CFLAGS) $(RSIMD_CFLAGS) -c $(@:.o=.c) -o $@
    204 
    205 test_atrstm test_atrstm_radcoefs: config.mk atrstm-local.pc $(LIBNAME)
    206 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(ATRSTM_LIBS) $(RSYS_LIBS) -lm
    207 
    208 test_atrstm_radcoefs_simd: config.mk atrstm-local.pc $(LIBNAME)
    209 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(ATRSTM_LIBS) $(RSYS_LIBS) $(RSIMD_LIBS)