star-phor-input

File format for describing photoreactor configurations
git clone https://www.edstar.cnrs.fr/git/star-phor-input.git
Log | Files | Refs | README | LICENSE

Makefile (8237B)


      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 = libsphin.so
     31 
     32 default: library
     33 
     34 all: library tool tests
     35 
     36 ################################################################################
     37 # Library building
     38 ################################################################################
     39 SRC =\
     40  src/sphin.c\
     41  src/sphin_brdf.c\
     42  src/sphin_btdf.c\
     43  src/sphin_config.c\
     44  src/sphin_geometry.c\
     45  src/sphin_prop_rad.c\
     46  src/sphin_refractive_index.c\
     47  src/sphin_scatterer.c\
     48  src/sphin_sensor.c\
     49  src/sphin_sensor_surface.c\
     50  src/sphin_sensor_volume.c\
     51  src/sphin_source_surface.c\
     52  src/sphin_spectral_property.c\
     53  src/sphin_surface.c\
     54  src/sphin_volume.c
     55 OBJ = $(SRC:.c=.o)
     56 DEP = $(SRC:.c=.d)
     57 
     58 # Compiler and linker options to build the library
     59 CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DSPHIN_SHARED_BUILD
     60 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS)
     61 
     62 library: .config $(DEP)
     63 	@$(MAKE) -fMakefile \
     64 	$$(for i in $(DEP); do echo -f "$${i}"; done) \
     65 	$(LIBNAME)
     66 
     67 $(DEP) $(OBJ): config.mk
     68 
     69 $(LIBNAME): $(OBJ)
     70 	$(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB)
     71 
     72 .config: config.mk
     73 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     74 	$(PKG_CONFIG) --atleast-version $(SSTL_VERSION) sstl
     75 	echo "config done" > $@
     76 
     77 .SUFFIXES: .c .d .o
     78 .c.d:
     79 	@$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     80 
     81 .c.o:
     82 	$(CC) $(CFLAGS_LIB) -c $< -o $@
     83 
     84 ################################################################################
     85 # Executable building
     86 ################################################################################
     87 SRC_TOOL = src/sphin_lint.c
     88 OBJ_TOOL = $(SRC_TOOL:.c=.o)
     89 DEP_TOOL = $(SRC_TOOL:.c=.d)
     90 
     91 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
     92 INCS_TOOL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sphin-local)
     93 LIBS_TOOL = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sphin-local)
     94 
     95 # Compiler and linker options for the executable
     96 CFLAGS_TOOL = -std=c99 $(CFLAGS_EXE) $(INCS_TOOL)
     97 LDFLAGS_TOOL = $(LDFLAGS_EXE) $(LIBS_TOOL)
     98 
     99 tool: $(DEP_TOOL) library
    100 	@$(MAKE) -fMakefile $$(for i in $(DEP_TOOL); do echo -f $${i}; done) \
    101 	sphin-lint
    102 
    103 sphin-lint: .config $(OBJ_TOOL) sphin-local.pc
    104 	$(CC) $(CFLAGS_TOOL) -o $@ $(OBJ_TOOL) $(LDFLAGS_TOOL)
    105 
    106 $(DEP_TOOL) $(OBJ_TOOL): .config sphin-local.pc
    107 
    108 $(DEP_TOOL):
    109 	@$(CC) $(CFLAGS_TOOL) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    110 
    111 $(OBJ_TOOL):
    112 	$(CC) $(CFLAGS_TOOL) -c $(@:.o=.c) -o $@
    113 
    114 clean_tool:
    115 	rm -f $(DEP_TOOL) $(OBJ_TOOL) sphin-lint
    116 
    117 ################################################################################
    118 # Installation
    119 ################################################################################
    120 pkg:
    121 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
    122 	    -e 's#@VERSION@#$(VERSION)#g'\
    123 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    124 	    -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\
    125 	    sphin.pc.in > sphin.pc
    126 
    127 sphin-lint.1: doc/sphin-lint.1.scd
    128 sphin.3: doc/sphin.3.scd.in
    129 star-phor-input.5: doc/star-phor-input.5.scd
    130 
    131 sphin-lint.1 star-phor-input.5:
    132 	scdoc < doc/$@.scd > $@
    133 
    134 sphin.3:
    135 	sed -e 's;@INCPREFIX@;$(DESTDIR)$(INCPREFIX);g' doc/$@.scd.in | scdoc > $@
    136 
    137 sphin-local.pc: sphin.pc.in
    138 	sed -e '1d'\
    139 	    -e 's#^includedir=.*#includedir=./src/#'\
    140 	    -e 's#^libdir=.*#libdir=./#'\
    141 	    -e 's#@PREFIX@#$(PREFIX)#g'\
    142 	    -e 's#@VERSION@#$(VERSION)#g'\
    143 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    144 	    -e 's#@SSTL_VERSION@#$(SSTL_VERSION)#g'\
    145 	    sphin.pc.in > $@
    146 
    147 install: library tool pkg star-phor-input.5 sphin.3 sphin-lint.1
    148 	install() { mode="$$1"; prefix="$$2"; shift 2; \
    149 	  mkdir -p "$${prefix}"; \
    150 	  cp "$$@" "$${prefix}"; \
    151 	  printf '%s\n' "$${@}" | while read -r i; do \
    152 	    chmod "$${mode}" "$${prefix}/$${i##*/}"; \
    153 	  done; \
    154 	}; \
    155 	install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
    156 	install 755 "$(DESTDIR)$(BINPREFIX)" sphin-lint; \
    157 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" sphin.pc; \
    158 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/sphin.h; \
    159 	install 644 "$(DESTDIR)$(MANPREFIX)/man1" sphin-lint.1; \
    160 	install 644 "$(DESTDIR)$(MANPREFIX)/man3" sphin.3; \
    161 	install 644 "$(DESTDIR)$(MANPREFIX)/man5" star-phor-input.5; \
    162 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-phor-input" COPYING; \
    163 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-phor-input" README.md
    164 
    165 uninstall:
    166 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
    167 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/sphin.pc"
    168 	rm -f "$(DESTDIR)$(BINPREFIX)/sphin-lint"
    169 	rm -f "$(DESTDIR)$(INCPREFIX)/star/sphin.h"
    170 	rm -f "$(DESTDIR)$(MANPREFIX)/man1/sphin-lint.1"
    171 	rm -f "$(DESTDIR)$(MANPREFIX)/man3/sphin.3"
    172 	rm -f "$(DESTDIR)$(MANPREFIX)/man5/star-phor-input.5"
    173 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-phor-input/COPYING"
    174 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-phor-input/README.md"
    175 
    176 clean: clean_test clean_tool
    177 	rm -f $(DEP) $(OBJ) $(LIBNAME)
    178 	rm -f .config sphin-local.pc sphin.pc
    179 	rm -f sphin-lint.1 sphin.3 star-phor-input.5
    180 
    181 ################################################################################
    182 # Tests
    183 ################################################################################
    184 TEST_SRC =\
    185  src/test_sphin.c\
    186  src/test_sphin_load_brdf_btdf.c\
    187  src/test_sphin_load_geometry.c\
    188  src/test_sphin_load_prop_rad.c\
    189  src/test_sphin_load_source.c\
    190  src/test_sphin_load_surface.c\
    191  src/test_sphin_load_volume.c
    192 TEST_OBJ = $(TEST_SRC:.c=.o)
    193 TEST_DEP = $(TEST_SRC:.c=.d)
    194 TEST_TGT = $(TEST_SRC:.c=.t)
    195 
    196 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys sphin-local)
    197 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys sphin-local) -lm
    198 
    199 # Compiler and linker options to build the tests
    200 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST)
    201 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST)
    202 
    203 test: tests
    204 	@err=0; \
    205 	for i in $(TEST_SRC); do \
    206 	  test="$$(basename "$${i}" ".c")"; \
    207 	  printf '%s' "$${test}"; \
    208 	  if "./$${test}" > /dev/null 2>&1; then \
    209 	    printf '\n'; \
    210 	  else \
    211 	    printf ': error %s\n' "$$?"; \
    212 	    err=$$((err+1)); \
    213 	  fi \
    214 	done; \
    215 	[ "$${err}" -eq 0 ]
    216 
    217 
    218 tests: library $(TEST_DEP) $(TEST_TGT)
    219 	@$(MAKE) -f Makefile \
    220 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    221 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    222 	test_list
    223 
    224 $(TEST_TGT):
    225 	@{ \
    226 	  exe="$$(basename "$@" ".t")"; \
    227 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    228 	  printf 'test_list: %s\n' "$${exe}"; \
    229 	} > $@
    230 
    231 $(TEST_DEP): config.mk sphin-local.pc
    232 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    233 
    234 $(TEST_OBJ): config.mk sphin-local.pc
    235 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    236 
    237 test_sphin \
    238 test_sphin_load_brdf_btdf \
    239 test_sphin_load_geometry \
    240 test_sphin_load_prop_rad \
    241 test_sphin_load_source \
    242 test_sphin_load_surface \
    243 test_sphin_load_volume \
    244 : config.mk sphin-local.pc $(LIBNAME)
    245 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    246 
    247 clean_test:
    248 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
    249 	rm -f file.txt test_0.stl test_1.stl test_2.stl test_3.stl\
    250 	      source_spec.txt abs_cross_sec.txt spectral_property.txt\
    251 	      abs_cross_sec_0.txt abs_cross_sec_1.txt abs_cross_sec_2.txt\
    252 	      abs_cross_sec_3.txt abs_cross_sec_4.txt
    253 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done