star-enclosures-3d

Extract enclosures from 3D geometry
git clone git://git.meso-star.fr/star-enclosures-3d.git
Log | Files | Refs | README | LICENSE

Makefile (8589B)


      1 # Copyright (C) 2018-2020, 2023, 2024 |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 = libsenc3d.a
     22 LIBNAME_SHARED = libsenc3d.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Library building
     27 ################################################################################
     28 SRC =\
     29  src/senc3d_descriptor.c\
     30  src/senc3d_device.c\
     31  src/senc3d_enclosure.c\
     32  src/senc3d_scene.c\
     33  src/senc3d_scene_analyze.c
     34 OBJ = $(SRC:.c=.o)
     35 DEP = $(SRC:.c=.d)
     36 
     37 build_library: .config $(DEP)
     38 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     39 	$$(if [ -n "$(LIBNAME)" ]; then \
     40 	     echo "$(LIBNAME)"; \
     41 	   else \
     42 	     echo "$(LIBNAME_SHARED)"; \
     43 	   fi)
     44 
     45 $(DEP) $(OBJ): config.mk
     46 
     47 $(LIBNAME_SHARED): $(OBJ)
     48 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     49 
     50 $(LIBNAME_STATIC): libsenc3d.o
     51 	$(AR) -rc $@ $?
     52 	$(RANLIB) $@
     53 
     54 libsenc3d.o: $(OBJ)
     55 	$(LD) -r $(OBJ) -o $@
     56 	$(OBJCOPY) $(OCPFLAGS) $@
     57 
     58 .config: config.mk
     59 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     60 	  echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     61 	@if ! $(PKG_CONFIG) --atleast-version $(S3D_VERSION) s3d; then \
     62 	  echo "s3d $(S3D_VERSION) not found" >&2; exit 1; fi
     63 	@echo "config done" > $@
     64 
     65 .SUFFIXES: .c .d .o
     66 .c.d:
     67 	@$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     68 
     69 .c.o:
     70 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DSENC3D_SHARED_BUILD -c $< -o $@
     71 
     72 ################################################################################
     73 # Installation
     74 ################################################################################
     75 pkg:
     76 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     77 	    -e 's#@VERSION@#$(VERSION)#g'\
     78 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     79 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
     80 	    senc3d.pc.in > senc3d.pc
     81 
     82 senc3d-local.pc: senc3d.pc.in
     83 	sed -e '1d'\
     84 	    -e 's#^includedir=.*#includedir=./src/#'\
     85 	    -e 's#^libdir=.*#libdir=./#'\
     86 	    -e 's#@VERSION@#$(VERSION)#g'\
     87 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     88 	    -e 's#@S3D_VERSION@#$(S3D_VERSION)#g'\
     89 	    senc3d.pc.in > $@
     90 
     91 install: build_library pkg
     92 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     93 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" senc3d.pc
     94 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" \
     95 	src/senc3d.h src/senc3d_sXd_helper.h src/sencX3d.h src/sencX3d_undefs.h
     96 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-3d" \
     97 	COPYING README.md
     98 
     99 uninstall:
    100 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
    101 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/senc3d.pc"
    102 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-3d/COPYING"
    103 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-enclosures-3d/README.md"
    104 	rm -f "$(DESTDIR)$(PREFIX)/include/star/senc3d.h"
    105 	rm -f "$(DESTDIR)$(PREFIX)/include/star/senc3d_sXd_helper.h"
    106 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sencX3d.h"
    107 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sencX3d_undefs.h"
    108 
    109 ################################################################################
    110 # Miscellaneous targets
    111 ################################################################################
    112 all: build_library build_tests
    113 
    114 clean: clean_test
    115 	rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_SSP) $(TEST_OBJ_S3DUT) $(LIBNAME)
    116 	rm -f .config .test libsenc3d.o senc3d.pc senc3d-local.pc
    117 
    118 distclean: clean
    119 	rm -f $(DEP) $(TEST_DEP) $(TEST_DEP_SSP) $(TEST_DEP_S3DUT)
    120 
    121 lint:
    122 	shellcheck -o all make.sh
    123 
    124 ################################################################################
    125 # Tests
    126 ################################################################################
    127 TEST_SRC =\
    128  src/test_senc3d_bad_grouping.c\
    129  src/test_senc3d_bad_grouping2.c\
    130  src/test_senc3d_bad_grouping3.c\
    131  src/test_senc3d_cube_behind_cube.c\
    132  src/test_senc3d_cube_in_cube.c\
    133  src/test_senc3d_cube_on_cube.c\
    134  src/test_senc3d_device.c\
    135  src/test_senc3d_enclosure.c\
    136  src/test_senc3d_glazing.c\
    137  src/test_senc3d_inconsistant_cube.c\
    138  src/test_senc3d_invalid_scenes.c\
    139  src/test_senc3d_multi_media.c\
    140  src/test_senc3d_scene.c\
    141  src/test_senc3d_some_enclosures.c\
    142  src/test_senc3d_some_triangles.c\
    143  src/test_senc3d_unspecified_medium.c\
    144  src/test_senc3d_zero_distance.c
    145 TEST_OBJ = $(TEST_SRC:.c=.o)
    146 TEST_DEP = $(TEST_SRC:.c=.d)
    147 
    148 # Tests that require Star-SP
    149 TEST_SRC_SSP = src/test_senc3d_sample_enclosure.c
    150 TEST_OBJ_SSP = $(TEST_SRC_SSP:.c=.o)
    151 TEST_DEP_SSP = $(TEST_SRC_SSP:.c=.d)
    152 SSP_FOUND = $(PKG_CONFIG) --atleast-version $(SSP_VERSION) star-sp
    153 
    154 # Tests that require Star-3DUT
    155 TEST_SRC_S3DUT =\
    156  src/test_senc3d_many_enclosures.c\
    157  src/test_senc3d_many_triangles.c
    158 TEST_OBJ_S3DUT = $(TEST_SRC_S3DUT:.c=.o)
    159 TEST_DEP_S3DUT = $(TEST_SRC_S3DUT:.c=.d)
    160 S3DUT_FOUND = $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut
    161 
    162 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    163 SENC3D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags senc3d-local.pc)
    164 SENC3D_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs senc3d-local.pc)
    165 
    166 build_tests: build_library $(TEST_DEP) .test
    167 	@if $(SSP_FOUND); then $(MAKE) $(TEST_DEP_SSP); fi; \
    168 	if $(S3DUT_FOUND); then $(MAKE) $(TEST_DEP_S3DUT); fi; \
    169 	$(MAKE) -fMakefile -f.test \
    170 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    171 	$$(if $(SSP_FOUND); then \
    172 	     for i in $(TEST_DEP_SSP); do echo -f"$${i}"; done; \
    173 	   fi) \
    174 	$$(if $(S3DUT_FOUND); then \
    175 	     for i in $(TEST_DEP_S3DUT); do echo -f"$${i}"; done; \
    176 	   fi) \
    177 	test_bin
    178 
    179 test: build_tests
    180 	@$(SHELL) make.sh run_test $(TEST_SRC)
    181 	@if $(SSP_FOUND); then $(SHELL) make.sh run_test $(TEST_SRC_SSP); fi
    182 	@if $(S3DUT_FOUND); then $(SHELL) make.sh run_test $(TEST_SRC_S3DUT); fi
    183 
    184 .test: Makefile
    185 	@{ $(SHELL) make.sh config_test $(TEST_SRC) ; \
    186 	   if $(SSP_FOUND); then $(SHELL) make.sh config_test $(TEST_SRC_SSP); fi; \
    187 	   if $(S3DUT_FOUND); then $(SHELL) make.sh config_test $(TEST_SRC_S3DUT); fi } \
    188 	> $@
    189 
    190 clean_test:
    191 	@$(SHELL) make.sh clean_test $(TEST_SRC) $(TEST_SRC_SSP) $(TEST_SRC_S3DUT)
    192 
    193 $(TEST_DEP): config.mk senc3d-local.pc
    194 	@$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) \
    195 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    196 
    197 $(TEST_DEP_SSP): config.mk senc3d-local.pc
    198 	@$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) \
    199 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    200 
    201 $(TEST_DEP_S3DUT): config.mk senc3d-local.pc
    202 	@$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) $(S3DUT_CFLAGS) \
    203 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    204 
    205 $(TEST_OBJ): config.mk senc3d-local.pc
    206 	$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) \
    207 	-c $(@:.o=.c) -o $@
    208 
    209 $(TEST_OBJ_SSP): config.mk senc3d-local.pc
    210 	$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) $(SSP_CFLAGS) \
    211 	-c $(@:.o=.c) -o $@
    212 
    213 $(TEST_OBJ_S3DUT): config.mk senc3d-local.pc
    214 	$(CC) $(CFLAGS_EXE) $(SENC3D_CFLAGS) $(RSYS_CFLAGS) $(S3DUT_CFLAGS) \
    215 	-c $(@:.o=.c) -o $@
    216 
    217 test_senc3d_bad_grouping \
    218 test_senc3d_bad_grouping2 \
    219 test_senc3d_bad_grouping3 \
    220 test_senc3d_cube_behind_cube \
    221 test_senc3d_cube_in_cube \
    222 test_senc3d_cube_on_cube \
    223 test_senc3d_device \
    224 test_senc3d_glazing \
    225 test_senc3d_inconsistant_cube \
    226 test_senc3d_invalid_scenes \
    227 test_senc3d_multi_media \
    228 test_senc3d_scene \
    229 test_senc3d_some_enclosures \
    230 test_senc3d_some_triangles \
    231 test_senc3d_unspecified_medium \
    232 test_senc3d_zero_distance \
    233 : config.mk senc3d-local.pc $(LIBNAME)
    234 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) \
    235 	$(SENC3D_LIBS) $(RSYS_LIBS)
    236 
    237 test_senc3d_enclosure: config.mk senc3d-local.pc $(LIBNAME)
    238 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) \
    239 	$(SENC3D_LIBS) $(RSYS_LIBS) $(S3D_LIBS)
    240 
    241 test_senc3d_many_enclosures \
    242 test_senc3d_many_triangles \
    243 : config.mk senc3d-local.pc $(LIBNAME)
    244 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) \
    245 	$(SENC3D_LIBS) $(RSYS_LIBS) $(S3DUT_LIBS) #-lm
    246 
    247 test_senc3d_sample_enclosure: config.mk senc3d-local.pc $(LIBNAME)
    248 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) \
    249 	$(SENC3D_LIBS) $(RSYS_LIBS) $(S3D_LIBS) $(SSP_LIBS)