star-3d

Surface structuring for efficient 3D geometric queries
git clone git://git.meso-star.com/star-3d.git
Log | Files | Refs | README | LICENSE

Makefile (6409B)


      1 # Copyright (C) 2015-2023, 2026 |Méso|Star> (contact@meso-star.com)
      2 #
      3 # This file is part of Star-3D.
      4 #
      5 # Star-3D is free software: you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as published by
      7 # the Free Software Foundation, either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # Star-3D is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with Star-3D. If not, see <http://www.gnu.org/licenses/>.
     17 
     18 .POSIX:
     19 .SUFFIXES: # Clean up default inference rules
     20 
     21 include config.mk
     22 
     23 LIBNAME_STATIC = libs3d.a
     24 LIBNAME_SHARED = libs3d.so
     25 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     26 
     27 default: library
     28 all: library tests
     29 
     30 ################################################################################
     31 # Star-3D building
     32 ################################################################################
     33 SRC =\
     34  src/s3d_device.c\
     35  src/s3d_geometry.c\
     36  src/s3d_instance.c\
     37  src/s3d_mesh.c\
     38  src/s3d_primitive.c\
     39  src/s3d_scene.c\
     40  src/s3d_scene_view.c\
     41  src/s3d_scene_view_closest_point.c\
     42  src/s3d_scene_view_trace_ray.c\
     43  src/s3d_shape.c\
     44  src/s3d_sphere.c
     45 OBJ = $(SRC:.c=.o)
     46 DEP = $(SRC:.c=.d)
     47 
     48 CFLAGS_LIB = -std=c99 $(CFLAGS_SO) $(INCS) -DS3D_SHARED_BUILD
     49 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS)
     50 
     51 library: .config $(DEP)
     52 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done) \
     53 	$$(if [ -n "$(LIBNAME)" ]; then \
     54 	  echo "$(LIBNAME)"; \
     55 	else \
     56 	  echo "$(LIBNAME_SHARED)"; \
     57 	fi)
     58 
     59 $(DEP) $(OBJ): config.mk
     60 
     61 $(LIBNAME_SHARED): $(OBJ)
     62 	$(CC) $(CFLAGS_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB)
     63 
     64 $(LIBNAME_STATIC): libs3d.o
     65 	$(AR) -rc $@ $?
     66 	$(RANLIB) $@
     67 
     68 libs3d.o: $(OBJ)
     69 	$(LD) -r $(OBJ) -o $@
     70 	$(OBJCOPY) $(OCPFLAGS) $@
     71 
     72 .config: Makefile config.mk
     73 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     74 	$(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4
     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 # Installation
     86 ################################################################################
     87 pkg:
     88 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     89 	    -e 's#@VERSION@#$(VERSION)#g'\
     90 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     91 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\
     92 	    s3d.pc.in > s3d.pc
     93 
     94 s3d-local.pc: s3d.pc.in
     95 	sed -e '1d'\
     96 	    -e 's#^includedir=.*#includedir=./src/#'\
     97 	    -e 's#^libdir=.*#libdir=./#'\
     98 	    -e 's#@VERSION@#$(VERSION)#g'\
     99 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
    100 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\
    101 	    s3d.pc.in > $@
    102 
    103 install: library pkg
    104 	install() { mode="$$1"; prefix="$$2"; shift 2; \
    105 	  mkdir -p "$${prefix}"; \
    106 	  cp "$$@" "$${prefix}"; \
    107 	  printf '%s\n' "$${@}" | while read -r i; do \
    108 	    chmod "$${mode}" "$${prefix}/$${i##*/}"; \
    109 	  done; \
    110 	}; \
    111 	if [ "$(LIB_TYPE)" = "STATIC" ]; then mode=644; else mode=755; fi; \
    112 	install "$${mode}" "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
    113 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" s3d.pc; \
    114 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/s3d.h; \
    115 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-3d" COPYING README.md
    116 	
    117 uninstall:
    118 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
    119 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/s3d.pc"
    120 	rm -f "$(DESTDIR)$(INCPREFIX)/star/s3d.h"
    121 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING"
    122 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/README.md"
    123 
    124 clean: clean_test
    125 	rm -f $(OBJ) $(DEP) $(LIBNAME)
    126 	rm -f .config .test libs3d.o s3d.pc s3d-local.pc
    127 
    128 ################################################################################
    129 # Tests
    130 ################################################################################
    131 TEST_SRC =\
    132  src/test_s3d_accel_struct_conf.c\
    133  src/test_s3d_closest_point.c\
    134  src/test_s3d_device.c\
    135  src/test_s3d_primitive.c\
    136  src/test_s3d_sampler.c\
    137  src/test_s3d_sample_sphere.c\
    138  src/test_s3d_scene.c\
    139  src/test_s3d_scene_view.c\
    140  src/test_s3d_scene_view_aabb.c\
    141  src/test_s3d_scene_view_delayed_cache_update.c\
    142  src/test_s3d_seams.c\
    143  src/test_s3d_shape.c\
    144  src/test_s3d_sphere_box.c\
    145  src/test_s3d_sphere.c\
    146  src/test_s3d_sphere_instance.c\
    147  src/test_s3d_trace_ray.c\
    148  src/test_s3d_trace_ray_instance.c\
    149  src/test_s3d_trace_ray_sphere.c
    150 TEST_OBJ = $(TEST_SRC:.c=.o)
    151 TEST_DEP = $(TEST_SRC:.c=.d)
    152 TEST_TGT = $(TEST_SRC:.c=.t)
    153 
    154 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    155 
    156 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags s3d)
    157 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs s3d)
    158 
    159 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST)
    160 LDFLAGS_TEST  = $(LDFLAGS_EXE) $(LIBS_TEST)
    161 
    162 tests: library $(TEST_DEP) $(TEST_TGT)
    163 	@$(MAKE) -fMakefile \
    164 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    165 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    166 	test_list
    167 
    168 $(TEST_TGT):
    169 	@{ \
    170 	  exe="$$(basename "$@" ".t")"; \
    171 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    172 	  printf 'test_list: %s\n' "$${exe}"; \
    173 	} > $@
    174 
    175 
    176 $(TEST_DEP): config.mk s3d-local.pc
    177 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    178 
    179 $(TEST_OBJ): config.mk s3d-local.pc
    180 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    181 
    182 test_s3d_device \
    183 test_s3d_primitive \
    184 test_s3d_sampler \
    185 test_s3d_scene \
    186 test_s3d_scene_view \
    187 test_s3d_scene_view_aabb \
    188 test_s3d_scene_view_delayed_cache_update \
    189 test_s3d_shape \
    190 : config.mk s3d-local.pc $(LIBNAME)
    191 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    192 
    193 test_s3d_accel_struct_conf \
    194 test_s3d_closest_point \
    195 test_s3d_sample_sphere \
    196 test_s3d_seams \
    197 test_s3d_sphere_box \
    198 test_s3d_sphere \
    199 test_s3d_sphere_instance \
    200 test_s3d_trace_ray \
    201 test_s3d_trace_ray_instance \
    202 test_s3d_trace_ray_sphere \
    203 : config.mk s3d-local.pc $(LIBNAME)
    204 	$(CC) -std=c89 $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST) -lm
    205 
    206 clean_test:
    207 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
    208 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done
    209 
    210 test: tests
    211 	@err=0; \
    212 	for i in $(TEST_SRC); do \
    213 	  test="$$(basename "$${i}" ".c")"; \
    214 	  printf '%s' "$${test}"; \
    215 	  if "./$${test}" > /dev/null 2>&1; then \
    216 	    printf '\n'; \
    217 	  else \
    218 	    printf ': error %s\n' "$$?"; \
    219 	    err=$$((err+1)); \
    220 	  fi \
    221 	done; \
    222 	[ "$${err}" -eq 0 ]