star-phor

Radiative transfer solver for photoreactors.
git clone https://www.edstar.cnrs.fr/git/star-phor.git
Log | Files | Refs | README | LICENSE

Makefile (8330B)


      1 # Copyright (C) 2024-2026 Centre National de la Recherche Scientifique
      2 # Copyright (C) 2024-2026 Clermont Auvergne INP
      3 # Copyright (C) 2024-2026 INSA Lyon
      4 # Copyright (C) 2024-2026 Institut Mines Télécom Albi-Carmaux
      5 # Copyright (C) 2024-2026 Institut National Polytechnique de Toulouse
      6 # Copyright (C) 2024-2026 |Méso|Star> (contact@meso-star.com)
      7 # Copyright (C) 2024-2026 PhotonLyX (info@photonlyx.com)
      8 # Copyright (C) 2024-2026 Université de Lorraine
      9 # Copyright (C) 2024-2026 Université Paul Sabatier
     10 # Copyright (C) 2024-2026 Université Toulouse - Jean Jaurès
     11 #
     12 # This program is free software: you can redistribute it and/or modify
     13 # it under the terms of the GNU General Public License as published by
     14 # the Free Software Foundation, either version 3 of the License, or
     15 # (at your option) any later version.
     16 #
     17 # This program is distributed in the hope that it will be useful,
     18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     20 # GNU General Public License for more details.
     21 #
     22 # You should have received a copy of the GNU General Public License
     23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
     24 
     25 .POSIX:
     26 .SUFFIXES: # Clean up default inference rules
     27 
     28 include config.mk
     29 
     30 LIBNAME = libsphor.so
     31 
     32 default: executable
     33 
     34 all: executable library tests
     35 
     36 ################################################################################
     37 # Library building
     38 ################################################################################
     39 SRC_LIB =\
     40  src/sphor.c\
     41  src/sphor_accum.c\
     42  src/sphor_compute_mvrea.c\
     43  src/sphor_config.c\
     44  src/sphor_interface.c\
     45  src/sphor_ran_bsdf.c\
     46  src/sphor_ran_geometry.c\
     47  src/sphor_ran_source.c\
     48  src/sphor_sources.c
     49 OBJ_LIB = $(SRC_LIB:.c=.o)
     50 DEP_LIB = $(SRC_LIB:.c=.d)
     51 
     52 # Compiler and linker options to build the library
     53 CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DSPHOR_SHARED_BUILD
     54 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS)
     55 
     56 library: .config $(DEP_LIB)
     57 	@$(MAKE) -fMakefile \
     58 	$$(for i in $(DEP_LIB); do echo -f "$${i}"; done) \
     59 	$(LIBNAME)
     60 
     61 $(DEP_LIB) $(OBJ_LIB): config.mk
     62 
     63 $(LIBNAME): $(OBJ_LIB)
     64 	$(CC) $(CFLAGS_LIB) -o $@ $(OBJ_LIB) $(LDFLAGS_LIB)
     65 
     66 .config: config.mk
     67 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     68 	$(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d
     69 	$(PKG_CONFIG) --atleast-version $(SPHIN_VERSION) sphin
     70 	$(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp
     71 	$(PKG_CONFIG) --atleast-version $(SUNIQ_VERSION) suniq
     72 	$(PKG_CONFIG) --atleast-version $(SSF_VERSION) ssf
     73 	echo "config done" > $@
     74 
     75 .SUFFIXES: .c .d .o
     76 .c.d:
     77 	@$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     78 
     79 .c.o:
     80 	$(CC) $(CFLAGS_LIB) -c $< -o $@
     81 
     82 clean: clean_test clean_executable
     83 	rm -f $(DEP_LIB) $(OBJ_LIB) $(LIBNAME)
     84 	rm -f .config sphor-local.pc sphor.pc star-phor.1 star-phor-output.5
     85 
     86 ################################################################################
     87 # Executable building
     88 ################################################################################
     89 SRC_BUILD =\
     90       src/sphor_main.c
     91 OBJ_BUILD = $(SRC_BUILD:.c=.o)
     92 DEP_BUILD = $(SRC_BUILD:.c=.d)
     93 
     94 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
     95 INCS_BUILD = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sphor-local)
     96 LIBS_BUILD = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sphor-local)
     97 
     98 # Compiler and linker options for the executable
     99 CFLAGS_BUILD = -std=c99 $(CFLAGS_EXE) $(INCS_BUILD)
    100 LDFLAGS_BUILD = $(LDFLAGS_EXE) $(LIBS_BUILD)
    101 
    102 executable: $(DEP_BUILD) library
    103 	@$(MAKE) -fMakefile $$(for i in $(DEP_BUILD); do echo -f $${i}; done) star-phor
    104 
    105 star-phor: .config $(OBJ_BUILD) sphor-local.pc $(LIBNAME)
    106 	$(CC) $(CFLAGS_BUILD) -o $@ $(OBJ_BUILD) $(LDFLAGS_BUILD)
    107 
    108 $(DEP_BUILD) $(OBJ_BUILD): .config sphor-local.pc
    109 
    110 $(DEP_BUILD):
    111 	@$(CC) $(CFLAGS_BUILD) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    112 
    113 $(OBJ_BUILD):
    114 	$(CC) $(CFLAGS_BUILD) -c $(@:.o=.c) -o $@
    115 
    116 clean_executable:
    117 	rm -f $(DEP_BUILD) $(OBJ_BUILD) star-phor
    118 
    119 ################################################################################
    120 # Installation
    121 ################################################################################
    122 pkg:
    123 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
    124 	    -e 's#@VERSION@#$(VERSION)#g'\
    125 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    126 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
    127 	    -e 's#@SPHIN_VERSION@#$(SPHIN_VERSION)#g'\
    128 	    -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
    129 	    -e 's#@SUNIQ_VERSION@#$(SUNIQ_VERSION)#g'\
    130 	    -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\
    131 	    sphor.pc.in > sphor.pc
    132 
    133 star-phor.1: doc/star-phor.scd
    134 	scdoc < doc/star-phor.scd > $@
    135 
    136 star-phor-output.5: doc/star-phor-output.scd
    137 	scdoc < doc/star-phor-output.scd > $@
    138 
    139 sphor-local.pc: sphor.pc.in
    140 	sed -e '1d'\
    141 	    -e 's#^includedir=.*#includedir=./src/#'\
    142 	    -e 's#^libdir=.*#libdir=./#'\
    143 	    -e 's#@PREFIX@#$(PREFIX)#g'\
    144 	    -e 's#@VERSION@#$(VERSION)#g'\
    145 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    146 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
    147 	    -e 's#@SPHIN_VERSION@#$(SPHIN_VERSION)#g'\
    148 	    -e 's#@SSP_VERSION@#$(SSP_VERSION)#g'\
    149 	    -e 's#@SUNIQ_VERSION@#$(SUNIQ_VERSION)#g'\
    150 	    -e 's#@SSF_VERSION@#$(SSF_VERSION)#g'\
    151 	    sphor.pc.in > $@
    152 
    153 install: executable library pkg star-phor.1 star-phor-output.5
    154 	install() { mode="$$1"; prefix="$$2"; shift 2; \
    155 	  mkdir -p "$${prefix}"; \
    156 	  cp "$$@" "$${prefix}"; \
    157 	  printf '%s\n' "$${@}" | while read -r i; do \
    158 	    chmod "$${mode}" "$${prefix}/$${i##*/}"; \
    159 	  done; \
    160 	}; \
    161 	install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
    162 	install 755 "$(DESTDIR)$(BINPREFIX)" star-phor; \
    163 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" sphor.pc; \
    164 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/sphor.h; \
    165 	install 644 "$(DESTDIR)$(MANPREFIX)/man1" star-phor.1; \
    166 	install 644 "$(DESTDIR)$(MANPREFIX)/man5" star-phor-output.5; \
    167 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-phor" COPYING; \
    168 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-phor" README.md
    169 
    170 uninstall:
    171 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
    172 	rm -f "$(DESTDIR)$(BINPREFIX)/star-phor"
    173 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sphor.pc"
    174 	rm -f "$(DESTDIR)$(INCPREFIX)/star/sphor.h"
    175 	rm -f "$(DESTDIR)$(MANPREFIX)/man1/star-phor.1"
    176 	rm -f "$(DESTDIR)$(MANPREFIX)/man5/star-phor-output.5"
    177 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-phor/COPYING"
    178 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-phor/README.md"
    179 
    180 ################################################################################
    181 # Tests
    182 ################################################################################
    183 TEST_SRC =\
    184 	src/test_sphor_lib.c\
    185 	src/test_sphor_MVREA_analytical1.c\
    186 	src/test_sphor_MVREA_btdf_keep_current_dir.c\
    187 	src/test_sphor_MVREA_btdf_snell_dielectric.c\
    188 	src/test_sphor_MVREA_btdf_lambertian.c
    189 TEST_OBJ = $(TEST_SRC:.c=.o)
    190 TEST_DEP = $(TEST_SRC:.c=.d)
    191 TEST_TGT = $(TEST_SRC:.c=.t)
    192 
    193 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sphin sphor-local)
    194 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sphin sphor-local) -lm
    195 
    196 # Compiler and linker options to build the tests
    197 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST)
    198 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST)
    199 
    200 test: tests
    201 	@err=0; \
    202 	for i in $(TEST_SRC); do \
    203 	  test="$$(basename "$${i}" ".c")"; \
    204 	  printf '%s' "$${test}"; \
    205 	  if "./$${test}" > /dev/null 2>&1; then \
    206 	    printf '\n'; \
    207 	  else \
    208 	    printf ': error %s\n' "$$?"; \
    209 	    err=$$((err+1)); \
    210 	  fi \
    211 	done; \
    212 	[ "$${err}" -eq 0 ]
    213 
    214 
    215 tests: library $(TEST_DEP) $(TEST_TGT)
    216 	@$(MAKE) -f Makefile \
    217 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    218 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    219 	test_list
    220 
    221 $(TEST_TGT):
    222 	@{ \
    223 	  exe="$$(basename "$@" ".t")"; \
    224 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    225 	  printf 'test_list: %s\n' "$${exe}"; \
    226 	} > $@
    227 
    228 $(TEST_DEP): config.mk sphor-local.pc
    229 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    230 
    231 $(TEST_OBJ): config.mk sphor-local.pc
    232 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    233 
    234 test_sphor_lib\
    235 test_sphor_MVREA_analytical1\
    236 test_sphor_MVREA_btdf_keep_current_dir\
    237 test_sphor_MVREA_btdf_snell_dielectric\
    238 test_sphor_MVREA_btdf_lambertian\
    239 : config.mk sphor-local.pc $(LIBNAME)
    240 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    241 
    242 clean_test:
    243 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT) \
    244 		input output *.stl *.dat \
    245 		spec.txt rho.txt
    246 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done