star-geometry-3d

Clean and decorate 3D geometries
git clone git://git.meso-star.fr/star-geometry-3d.git
Log | Files | Refs | README | LICENSE

Makefile (7781B)


      1 # Copyright (C) 2019, 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 = libsg3d.a
     22 LIBNAME_SHARED = libsg3d.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Library building
     27 ################################################################################
     28 SRC =\
     29  src/sg3d_device.c\
     30  src/sg3d_geometry.c
     31 OBJ = $(SRC:.c=.o)
     32 DEP = $(SRC:.c=.d)
     33 
     34 build_library: .config $(DEP)
     35 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     36 	$$(if [ -n "$(LIBNAME)" ]; then \
     37 	     echo "$(LIBNAME)"; \
     38 	   else \
     39 	     echo "$(LIBNAME_SHARED)"; \
     40 	   fi)
     41 
     42 $(DEP) $(OBJ): config.mk
     43 
     44 $(LIBNAME_SHARED): $(OBJ)
     45 	$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(RSYS_LIBS) -lm
     46 
     47 $(LIBNAME_STATIC): libsg3d.o
     48 	$(AR) -rc $@ $?
     49 	$(RANLIB) $@
     50 
     51 libsg3d.o: $(OBJ)
     52 	$(LD) -r $(OBJ) -o $@
     53 	$(OBJCOPY) $(OCPFLAGS) $@
     54 
     55 .config: config.mk
     56 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     57 	  echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     58 	@echo "config done" > $@
     59 
     60 .SUFFIXES: .c .d .o
     61 .c.d:
     62 	@$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     63 
     64 .c.o:
     65 	$(CC) $(CFLAGS_SO) $(RSYS_CFLAGS) -DSG3D_SHARED_BUILD -c $< -o $@
     66 
     67 ################################################################################
     68 # Installation
     69 ################################################################################
     70 pkg:
     71 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     72 	    -e 's#@VERSION@#$(VERSION)#g'\
     73 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     74 	    sg3d.pc.in > sg3d.pc
     75 
     76 sg3d-local.pc: sg3d.pc.in
     77 	sed -e '1d'\
     78 	    -e 's#^includedir=.*#includedir=./src/#'\
     79 	    -e 's#^libdir=.*#libdir=./#'\
     80 	    -e 's#@VERSION@#$(VERSION)#g'\
     81 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     82 	    sg3d.pc.in > $@
     83 
     84 install: build_library pkg
     85 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     86 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" sg3d.pc
     87 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d.h
     88 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sXd_helper.h
     89 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sencXd_helper.h
     90 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sg3d_sdisXd_helper.h
     91 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sgX3d.h
     92 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/sgX3d_undefs.h
     93 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d" \
     94 	COPYING README.md
     95 
     96 uninstall:
     97 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
     98 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/sg3d.pc"
     99 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d/COPYING"
    100 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-geometry-3d/README.md"
    101 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d.h"
    102 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sXd_helper.h"
    103 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sencXd_helper.h"
    104 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sg3d_sdisXd_helper.h"
    105 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sgX3d.h"
    106 	rm -f "$(DESTDIR)$(PREFIX)/include/star/sgX3d_undefs.h"
    107 
    108 ################################################################################
    109 # Miscellaneous targets
    110 ################################################################################
    111 all: build_library build_tests
    112 
    113 clean: clean_test
    114 	rm -f $(OBJ) $(TEST_OBJ) $(TEST_OBJ_S3DUT) $(LIBNAME)
    115 	rm -f .config .config_test .test libsg3d.o sg3d.pc sg3d-local.pc
    116 
    117 distclean: clean
    118 	rm -f $(DEP) $(TEST_DEP) $(TEST_DEP_S3DUT)
    119 
    120 lint:
    121 	shellcheck -o all make.sh
    122 
    123 ################################################################################
    124 # Tests
    125 ################################################################################
    126 TEST_SRC =\
    127  src/test_sg3d_cube_behind_cube.c\
    128  src/test_sg3d_cube_in_cube.c\
    129  src/test_sg3d_cube_on_cube.c\
    130  src/test_sg3d_device.c\
    131  src/test_sg3d_geometry_2.c\
    132  src/test_sg3d_geometry.c\
    133  src/test_sg3d_invalid_models.c\
    134  src/test_sg3d_multi_media.c\
    135  src/test_sg3d_unspecified_properties.c
    136 TEST_OBJ = $(TEST_SRC:.c=.o)
    137 TEST_DEP = $(TEST_SRC:.c=.d)
    138 
    139 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    140 SG3D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags sg3d-local.pc)
    141 SG3D_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs sg3d-local.pc)
    142 
    143 # Regular Compiler and linker flags
    144 TEST_CFLAGS = $(CFLAGS_EXE) $(SG3D_CFLAGS) $(RSYS_CFLAGS)
    145 TEST_LIBS = $(LDFLAGS_EXE) $(SG3D_LIBS) $(RSYS_LIBS)
    146 
    147 build_tests: .config_test build_library $(TEST_DEP) .test
    148 	@$(MAKE) -fMakefile -f.test \
    149 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    150 	test_bin
    151 
    152 .config_test: config.mk
    153 	@if ! $(PKG_CONFIG) --atleast-version $(S3DUT_VERSION) s3dut; then \
    154 	  echo "s3dut $(S3DUT_VERSION) not found" >&2; exit 1; fi
    155 	@echo "config done" > $@
    156 
    157 test: build_tests
    158 	@$(SHELL) make.sh run_test $(TEST_SRC)
    159 
    160 .test: Makefile
    161 	@$(SHELL) make.sh config_test $(TEST_SRC) > $@
    162 
    163 clean_test:
    164 	@$(SHELL) make.sh clean_test $(TEST_SRC)
    165 
    166 ################################################################################
    167 # Regular tests
    168 ################################################################################
    169 src/test_sg3d_cube_behind_cube.d \
    170 src/test_sg3d_cube_in_cube.d \
    171 src/test_sg3d_cube_on_cube.d \
    172 src/test_sg3d_device.d \
    173 src/test_sg3d_geometry_2.d \
    174 src/test_sg3d_geometry.d \
    175 src/test_sg3d_invalid_models.d \
    176 src/test_sg3d_multi_media.d \
    177 src/test_sg3d_unspecified_properties.d \
    178 : config.mk sg3d-local.pc
    179 	@$(CC) $(TEST_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    180 
    181 src/test_sg3d_cube_behind_cube.o \
    182 src/test_sg3d_cube_in_cube.o \
    183 src/test_sg3d_cube_on_cube.o \
    184 src/test_sg3d_device.o \
    185 src/test_sg3d_geometry_2.o \
    186 src/test_sg3d_geometry.o \
    187 src/test_sg3d_invalid_models.o \
    188 src/test_sg3d_multi_media.o \
    189 src/test_sg3d_unspecified_properties.o \
    190 : config.mk sg3d-local.pc
    191 	$(CC) $(TEST_CFLAGS) -c $(@:.o=.c) -o $@
    192 
    193 test_sg3d_cube_behind_cube \
    194 test_sg3d_cube_in_cube \
    195 test_sg3d_cube_on_cube \
    196 test_sg3d_device \
    197 test_sg3d_geometry_2 \
    198 test_sg3d_geometry \
    199 test_sg3d_invalid_models \
    200 test_sg3d_multi_media \
    201 test_sg3d_unspecified_properties \
    202 : config.mk sg3d-local.pc $(LIBNAME)
    203 	$(CC) $(TEST_CFLAGS) -o $@ src/$@.o $(TEST_LIBS)
    204 
    205 ################################################################################
    206 # Test based on Star-3DUT
    207 ################################################################################
    208 src/test_sg3d_many_enclosures.d \
    209 src/test_sg3d_many_triangles.d \
    210 src/test_sg3d_some_enclosures.d \
    211 src/test_sg3d_some_triangles.d \
    212 : config.mk sg3d-local.pc
    213 	@$(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    214 
    215 src/test_sg3d_many_enclosures.o \
    216 src/test_sg3d_many_triangles.o \
    217 src/test_sg3d_some_enclosures.o \
    218 src/test_sg3d_some_triangles.o \
    219 : config.mk sg3d-local.pc
    220 	$(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -c $(@:.o=.c) -o $@
    221 
    222 test_sg3d_many_enclosures \
    223 test_sg3d_many_triangles \
    224 test_sg3d_some_enclosures \
    225 test_sg3d_some_triangles \
    226 : config.mk sg3d-local.pc $(LIBNAME)
    227 	$(CC) $(TEST_CFLAGS) $(S3DUT_CFLAGS) -o $@ src/$@.o $(TEST_LIBS) $(S3DUT_LIBS)