star-3d

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

Makefile (6023B)


      1 # Copyright (C) 2015-2023 |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 = libs3d.a
     22 LIBNAME_SHARED = libs3d.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Star-3D building
     27 ################################################################################
     28 SRC =\
     29  src/s3d_device.c\
     30  src/s3d_geometry.c\
     31  src/s3d_instance.c\
     32  src/s3d_mesh.c\
     33  src/s3d_primitive.c\
     34  src/s3d_scene.c\
     35  src/s3d_scene_view.c\
     36  src/s3d_scene_view_closest_point.c\
     37  src/s3d_scene_view_trace_ray.c\
     38  src/s3d_shape.c\
     39  src/s3d_sphere.c
     40 OBJ = $(SRC:.c=.o)
     41 DEP = $(SRC:.c=.d)
     42 
     43 build_library: .config $(DEP)
     44 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f "$${i}"; done)\
     45  $$(if [ -n "$(LIBNAME)" ]; then\
     46       echo "$(LIBNAME)";\
     47     else\
     48       echo "$(LIBNAME_SHARED)";\
     49     fi)
     50 
     51 $(DEP) $(OBJ): config.mk
     52 
     53 $(LIBNAME_SHARED): $(OBJ)
     54 	$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     55 
     56 $(LIBNAME_STATIC): libs3d.o
     57 	$(AR) -rc $@ $?
     58 	$(RANLIB) $@
     59 
     60 libs3d.o: $(OBJ)
     61 	$(LD) -r $(OBJ) -o $@
     62 	$(OBJCOPY) $(OCPFLAGS) $@
     63 
     64 .config: Makefile config.mk
     65 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then\
     66 		echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     67 	@if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then\
     68 		echo "embree $(EMBREE_VERSION) not found" >&2; exit 1; fi
     69 	@echo "config done" > $@
     70 
     71 .SUFFIXES: .c .d .o
     72 .c.d:
     73 	@$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     74 
     75 .c.o:
     76 	$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -DS3D_SHARED_BUILD -c $< -o $@
     77 
     78 ################################################################################
     79 # Installation
     80 ################################################################################
     81 pkg:
     82 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     83 	    -e 's#@VERSION@#$(VERSION)#g'\
     84 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     85 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\
     86 	    s3d.pc.in > s3d.pc
     87 
     88 s3d-local.pc: s3d.pc.in
     89 	sed -e '1d'\
     90 	    -e 's#^includedir=.*#includedir=./src/#'\
     91 	    -e 's#^libdir=.*#libdir=./#'\
     92 	    -e 's#@VERSION@#$(VERSION)#g'\
     93 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     94 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\
     95 	    s3d.pc.in > $@
     96 
     97 install: build_library pkg
     98 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     99 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" s3d.pc
    100 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/s3d.h
    101 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-3d"\
    102 		COPYING README.md
    103 
    104 uninstall:
    105 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
    106 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/s3d.pc"
    107 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/COPYING"
    108 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-3d/README.md"
    109 	rm -f "$(DESTDIR)$(PREFIX)/include/star/s3d.h"
    110 
    111 ################################################################################
    112 # Miscellaneous targets
    113 ################################################################################
    114 all: build_library build_tests
    115 
    116 clean: clean_test
    117 	rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
    118 	rm -f .config .test libs3d.o s3d.pc s3d-local.pc
    119 
    120 distclean: clean
    121 	rm -f $(DEP) $(TEST_DEP)
    122 
    123 lint:
    124 	shellcheck -o all make.sh
    125 
    126 ################################################################################
    127 # Tests
    128 ################################################################################
    129 TEST_SRC =\
    130  src/test_s3d_accel_struct_conf.c\
    131  src/test_s3d_closest_point.c\
    132  src/test_s3d_device.c\
    133  src/test_s3d_primitive.c\
    134  src/test_s3d_sampler.c\
    135  src/test_s3d_sample_sphere.c\
    136  src/test_s3d_scene.c\
    137  src/test_s3d_scene_view_aabb.c\
    138  src/test_s3d_scene_view.c\
    139  src/test_s3d_seams.c\
    140  src/test_s3d_shape.c\
    141  src/test_s3d_sphere_box.c\
    142  src/test_s3d_sphere.c\
    143  src/test_s3d_sphere_instance.c\
    144  src/test_s3d_trace_ray.c\
    145  src/test_s3d_trace_ray_instance.c\
    146  src/test_s3d_trace_ray_sphere.c
    147 TEST_OBJ = $(TEST_SRC:.c=.o)
    148 TEST_DEP = $(TEST_SRC:.c=.d)
    149 
    150 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    151 S3D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags s3d-local.pc)
    152 S3D_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs s3d-local.pc)
    153 
    154 build_tests: build_library $(TEST_DEP) .test
    155 	@$(MAKE) -fMakefile -f.test \
    156 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
    157 
    158 test: build_tests
    159 	@$(SHELL) make.sh run_test $(TEST_SRC)
    160 
    161 .test: Makefile
    162 	@$(SHELL) make.sh config_test $(TEST_SRC) > .test
    163 
    164 clean_test:
    165 	@$(SHELL) make.sh clean_test $(TEST_SRC)
    166 
    167 $(TEST_DEP): config.mk s3d-local.pc
    168 	@$(CC) -std=c89 $(CFLAGS_EXE) $(S3D_CFLAGS) \
    169 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    170 
    171 $(TEST_OBJ): config.mk s3d-local.pc
    172 	$(CC) -std=c89 $(CFLAGS_EXE) $(S3D_CFLAGS) -c $(@:.o=.c) -o $@
    173 
    174 test_s3d_device \
    175 test_s3d_primitive \
    176 test_s3d_sampler \
    177 test_s3d_scene \
    178 test_s3d_scene_view_aabb \
    179 test_s3d_scene_view \
    180 test_s3d_shape \
    181 : config.mk s3d-local.pc $(LIBNAME)
    182 	$(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(S3D_LIBS)
    183 
    184 test_s3d_accel_struct_conf \
    185 test_s3d_closest_point \
    186 test_s3d_sample_sphere \
    187 test_s3d_seams \
    188 test_s3d_sphere_box \
    189 test_s3d_sphere \
    190 test_s3d_sphere_instance \
    191 test_s3d_trace_ray \
    192 test_s3d_trace_ray_instance \
    193 test_s3d_trace_ray_sphere \
    194 : config.mk s3d-local.pc $(LIBNAME)
    195 	$(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(S3D_LIBS) -lm