polygon

Polygon triangulation
git clone git://git.meso-star.fr/polygon.git
Log | Files | Refs | README | LICENSE

Makefile (4778B)


      1 # Copyright (C) 2014-2017, 2021-2023 Vincent Forest (vaplv@free.fr)
      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 = libpolygon.a
     22 LIBNAME_SHARED = libpolygon.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Library building
     27 ################################################################################
     28 SRC = src/polygon.c
     29 OBJ = $(SRC:.c=.o)
     30 DEP = $(SRC:.c=.d)
     31 
     32 build_library: .config $(DEP)
     33 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     34 	$$(if [ -n "$(LIBNAME)" ]; then\
     35 	     echo "$(LIBNAME)";\
     36 	   else\
     37 	     echo "$(LIBNAME_SHARED)";\
     38 	   fi)
     39 
     40 $(DEP) $(OBJ): config.mk
     41 
     42 $(LIBNAME_SHARED): $(OBJ)
     43 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     44 
     45 $(LIBNAME_STATIC): libpolygon.o
     46 	$(AR) -rc $@ $?
     47 	$(RANLIB) $@
     48 
     49 libpolygon.o: $(OBJ)
     50 	$(LD) -r $(OBJ) -o $@
     51 	$(OBJCOPY) $(OCPFLAGS) $@
     52 
     53 .config: Makefile config.mk
     54 	@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
     55 	  echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
     56 	@echo "config done" > .config
     57 
     58 .SUFFIXES: .c .d .o
     59 .c.d:
     60 	@$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     61 
     62 .c.o:
     63 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DPOLYGON_SHARED_BUILD -c $< -o $@
     64 
     65 ################################################################################
     66 # Installation
     67 ################################################################################
     68 pkg:
     69 	sed -e 's#@PREFIX@#$(PREFIX)#g' \
     70 	    -e 's#@VERSION@#$(VERSION)#g' \
     71 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
     72 	    polygon.pc.in > polygon.pc
     73 
     74 polygon-local.pc: polygon.pc.in
     75 	sed -e '1d'\
     76 	    -e 's#^includedir=.*#includedir=./src/#'\
     77 	    -e 's#^libdir=.*#libdir=./#'\
     78 	    -e 's#@VERSION@#$(VERSION)#g'\
     79 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     80 	    polygon.pc.in > $@
     81 
     82 install: build_library pkg
     83 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     84 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" polygon.pc
     85 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include" src/polygon.h
     86 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/polygon" COPYING README.md
     87 
     88 uninstall:
     89 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
     90 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/polygon.pc"
     91 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/polygon/COPYING"
     92 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/polygon/README.md"
     93 	rm -f "$(DESTDIR)$(PREFIX)/include/polygon.h"
     94 
     95 ################################################################################
     96 # Miscellaneous targets
     97 ################################################################################
     98 all: build_library build_tests
     99 
    100 clean: clean_test
    101 	rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
    102 	rm -f .config .test libpolygon.o polygon.pc polygon-local.pc
    103 
    104 distclean: clean
    105 	rm -f $(DEP) $(TEST_DEP)
    106 
    107 lint:
    108 	shellcheck -o all make.sh
    109 
    110 ################################################################################
    111 # Tests
    112 ################################################################################
    113 TEST_SRC =\
    114  src/test_polygon.c\
    115  src/test_polygon1.c
    116 TEST_OBJ = $(TEST_SRC:.c=.o)
    117 TEST_DEP = $(TEST_SRC:.c=.d)
    118 
    119 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    120 POLYGON_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags polygon-local.pc)
    121 POLYGON_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs polygon-local.pc)
    122 
    123 build_tests: build_library $(TEST_DEP) .test
    124 	@$(MAKE) -fMakefile -f.test $$(for i in $(TEST_DEP); do echo -f"$${i}"; done) test_bin
    125 
    126 test: build_tests
    127 	@$(SHELL) make.sh run_test $(TEST_SRC)
    128 
    129 .test: Makefile make.sh
    130 	@$(SHELL) make.sh config_test $(TEST_SRC) > $@
    131 
    132 clean_test:
    133 	@$(SHELL) make.sh clean_test $(TEST_SRC)
    134 
    135 $(TEST_DEP) $(TEST_OBJ):  config.mk polygon-local.pc
    136 
    137 $(TEST_DEP):
    138 	@$(CC) $(CFLAGS_EXE) $(POLYGON_CFLAGS) $(RSYS_CFLAGS) \
    139 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    140 
    141 $(TEST_OBJ): config.mk polygon-local.pc
    142 	$(CC) $(CFLAGS_EXE) $(POLYGON_CFLAGS) $(RSYS_CFLAGS) -c $(@:.o=.c) -o $@
    143 
    144 test_polygon test_polygon1: config.mk polygon-local.pc $(LIBNAME)
    145 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(POLYGON_LIBS) $(RSYS_LIBS) -lm