star-2d

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

Makefile (5532B)


      1 # Copyright (C) 2016-2021, 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 = libs2d.a
     22 LIBNAME_SHARED = libs2d.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Star-2D building
     27 ################################################################################
     28 SRC =\
     29  src/s2d_device.c\
     30  src/s2d_geometry.c\
     31  src/s2d_line_segments.c\
     32  src/s2d_primitive.c\
     33  src/s2d_scene.c\
     34  src/s2d_scene_view.c\
     35  src/s2d_scene_view_closest_point.c\
     36  src/s2d_shape.c
     37 OBJ = $(SRC:.c=.o)
     38 DEP = $(SRC:.c=.d)
     39 
     40 build_library: .config $(DEP)
     41 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     42 	$$(if [ -n "$(LIBNAME)" ]; then\
     43 	     echo "$(LIBNAME)";\
     44 	   else\
     45 	     echo "$(LIBNAME_SHARED)";\
     46 	   fi)
     47 
     48 $(DEP) $(OBJ): config.mk
     49 
     50 $(LIBNAME_SHARED): $(OBJ)
     51 	$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     52 
     53 $(LIBNAME_STATIC): libs2d.o
     54 	$(AR) -rc $@ $?
     55 	$(RANLIB) $@
     56 
     57 libs2d.o: $(OBJ)
     58 	$(LD) -r $(OBJ) -o $@
     59 	$(OBJCOPY) $(OCPFLAGS) $@
     60 
     61 .config: Makefile config.mk
     62 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     63 	   echo "rsys $(RSYS_VERSION) not found" >&2; exit 1; fi
     64 	@if ! $(PKG_CONFIG) --atleast-version $(EMBREE_VERSION) embree4; then \
     65 	   echo "embree $(EMBREE_VERSION) not found" >&2; exit 1; fi
     66 	@echo "config done" > .config
     67 
     68 .SUFFIXES: .c .d .o
     69 .c.d:
     70 	@$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     71 
     72 .c.o:
     73 	$(CC) -std=c99 $(CFLAGS_SO) $(DPDC_CFLAGS) -DS2D_SHARED_BUILD -c $< -o $@
     74 
     75 ################################################################################
     76 # Installation
     77 ################################################################################
     78 pkg:
     79 	sed -e 's#@PREFIX@#$(PREFIX)#g' \
     80 	    -e 's#@VERSION@#$(VERSION)#g' \
     81 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
     82 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g' \
     83 	    s2d.pc.in > s2d.pc
     84 
     85 s2d-local.pc: s2d.pc.in
     86 	sed -e '1d'\
     87 	    -e 's#^includedir=.*#includedir=./src/#'\
     88 	    -e 's#^libdir=.*#libdir=./#'\
     89 	    -e 's#@VERSION@#$(VERSION)#g'\
     90 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     91 	    -e 's#@EMBREE_VERSION@#$(EMBREE_VERSION)#g'\
     92 	    s2d.pc.in > $@
     93 
     94 install: build_library pkg
     95 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     96 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" s2d.pc
     97 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/s2d.h
     98 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-2d" COPYING README.md
     99 
    100 uninstall:
    101 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
    102 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/s2d.pc"
    103 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-2d/COPYING"
    104 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-2d/README.md"
    105 	rm -f "$(DESTDIR)$(PREFIX)/include/star/s2d.h"
    106 
    107 ################################################################################
    108 # Miscellaneous targets
    109 ################################################################################
    110 all: build_library build_tests
    111 
    112 clean: clean_test
    113 	rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
    114 	rm -f .config .test libs2d.o s2d.pc s2d-local.pc
    115 
    116 distclean: clean
    117 	rm -f $(DEP) $(TEST_DEP)
    118 
    119 lint:
    120 	shellcheck -o all make.sh
    121 
    122 ################################################################################
    123 # Tests
    124 ################################################################################
    125 TEST_SRC =\
    126  src/test_s2d_closest_point.c\
    127  src/test_s2d_device.c\
    128  src/test_s2d_primitive.c\
    129  src/test_s2d_raytrace.c\
    130  src/test_s2d_sample.c\
    131  src/test_s2d_shape.c\
    132  src/test_s2d_scene.c\
    133  src/test_s2d_scene_view.c\
    134  src/test_s2d_scene_view2.c\
    135  src/test_s2d_trace_ray.c\
    136  src/test_s2d_trace_ray_3d.c
    137 TEST_OBJ = $(TEST_SRC:.c=.o)
    138 TEST_DEP = $(TEST_SRC:.c=.d)
    139 
    140 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    141 S2D_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags s2d-local.pc)
    142 S2D_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs s2d-local.pc)
    143 
    144 build_tests: build_library $(TEST_DEP) .test
    145 	@$(MAKE) -fMakefile -f.test \
    146 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
    147 
    148 test: build_tests
    149 	@$(SHELL) make.sh run_test $(TEST_SRC)
    150 
    151 .test: Makefile make.sh
    152 	@$(SHELL) make.sh config_test $(TEST_SRC) > .test
    153 
    154 clean_test:
    155 	@$(SHELL) make.sh clean_test $(TEST_SRC)
    156 
    157 $(TEST_DEP):  config.mk s2d-local.pc
    158 	@$(CC) -std=c89 $(CFLAGS_EXE) $(S2D_CFLAGS) \
    159 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    160 
    161 $(TEST_OBJ): config.mk s2d-local.pc
    162 	$(CC) -std=c89 $(CFLAGS_EXE) $(S2D_CFLAGS) -c $(@:.o=.c) -o $@
    163 
    164 test_s2d_closest_point \
    165 test_s2d_device \
    166 test_s2d_primitive \
    167 test_s2d_raytrace \
    168 test_s2d_sample \
    169 test_s2d_shape \
    170 test_s2d_scene \
    171 test_s2d_scene_view \
    172 test_s2d_scene_view2 \
    173 test_s2d_trace_ray \
    174 test_s2d_trace_ray_3d \
    175 : config.mk s2d-local.pc $(LIBNAME)
    176 	$(CC) -std=c89 $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(S2D_LIBS) -lm