star-uniq

Filter out repeated triangles
git clone git://git.meso-star.fr/star-uniq.git
Log | Files | Refs | README | LICENSE

Makefile (4795B)


      1 # Copyright (C) 2025 |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 
     18 include config.mk
     19 
     20 LIBNAME_STATIC = libsuniq.a
     21 LIBNAME_SHARED = libsuniq.so
     22 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     23 
     24 default: library
     25 all: default tests
     26 
     27 ################################################################################
     28 # Library
     29 ################################################################################
     30 SRC = src/suniq.c
     31 OBJ = $(SRC:.c=.o)
     32 DEP = $(SRC:.c=.d)
     33 
     34 CFLAGS_LIB = $(CFLAGS_SO) $(INCS) -DSUNIQ_SHARED_BUILD
     35 LDFLAGS_LIB = $(LDFLAGS_SO) $(LIBS)
     36 
     37 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_LIB) -o $@ $(OBJ) $(LDFLAGS_LIB)
     49 
     50 $(LIBNAME_STATIC): libsuniq.o
     51 	$(AR) -rc $@ $?
     52 	$(RANLIB) $@
     53 
     54 libsmsh.o: $(OBJ)
     55 	$(LD) -r $(OBJ) -o $@
     56 	$(OBJCOPY) $(OCPFLAGS) $@
     57 
     58 .config: config.mk
     59 	$(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys
     60 	@echo "config done" > $@
     61 
     62 .SUFFIXES: .c .d .o
     63 .c.d:
     64 	@$(CC) $(CFLAGS_LIB) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     65 
     66 .c.o:
     67 	$(CC) $(CFLAGS_LIB) -c $< -o $@
     68 
     69 ################################################################################
     70 # Miscellaneous
     71 ################################################################################
     72 pkg:
     73 	sed -e 's#@PREFIX@#$(PREFIX)#g' \
     74 	    -e 's#@VERSION@#$(VERSION)#g' \
     75 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
     76 	    suniq.pc.in > suniq.pc
     77 
     78 suniq-local.pc: suniq.pc.in
     79 	sed -e '1d'\
     80 	    -e 's#^includedir=.*#includedir=./src/#'\
     81 	    -e 's#^libdir=.*#libdir=./#'\
     82 	    -e 's#@VERSION@#$(VERSION)#g'\
     83 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     84 	    suniq.pc.in > $@
     85 
     86 install: library pkg
     87 	install() { mode="$$1"; prefix="$$2"; shift 2; \
     88 	  mkdir -p "$${prefix}"; \
     89 	  cp "$$@" "$${prefix}"; \
     90 	  chmod "$${mode}" "$$@"; \
     91 	}; \
     92 	install 755 "$(DESTDIR)$(LIBPREFIX)" $(LIBNAME); \
     93 	install 644 "$(DESTDIR)$(LIBPREFIX)/pkgconfig" suniq.pc; \
     94 	install 644 "$(DESTDIR)$(INCPREFIX)/star" src/suniq.h; \
     95 	install 644 "$(DESTDIR)$(PREFIX)/share/doc/star-uniq" COPYING README.md
     96 
     97 uninstall:
     98 	rm -f "$(DESTDIR)$(LIBPREFIX)/$(LIBNAME)"
     99 	rm -f "$(DESTDIR)$(LIBPREFIX)/pkgconfig/suniq.pc"
    100 	rm -f "$(DESTDIR)$(INCPREFIX)/star/suniq.h"
    101 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uniq/COPYING"
    102 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-uniq/README.md"
    103 
    104 clean: clean_test
    105 	rm -f $(DEP) $(OBJ) $(LIBNAME)
    106 	rm -f .config libsuniq.o suniq.pc suniq-local.pc
    107 
    108 ################################################################################
    109 # Tests
    110 ################################################################################
    111 TEST_SRC = src/test_suniq.c
    112 TEST_OBJ = $(TEST_SRC:.c=.o)
    113 TEST_DEP = $(TEST_SRC:.c=.d)
    114 TEST_TGT = $(TEST_SRC:.c=.t)
    115 
    116 PKG_CONFIG_LOCAL = PKG_CONFIG_PATH="./:$${PKG_CONFIG_PATH}" $(PKG_CONFIG)
    117 INCS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags rsys suniq-local)
    118 LIBS_TEST = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs rsys suniq-local)
    119 
    120 CFLAGS_TEST = -std=c89 $(CFLAGS_EXE) $(INCS_TEST)
    121 LDFLAGS_TEST = $(LDFLAGS_EXE) $(LIBS_TEST)
    122 
    123 tests: library $(TEST_DEP) $(TEST_TGT)
    124 	@$(MAKE) -fMakefile \
    125 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    126 	$$(for i in $(TEST_TGT); do echo -f"$${i}"; done) \
    127 	test_list
    128 
    129 $(TEST_TGT):
    130 	@{ \
    131 	  exe="$$(basename "$@" ".t")"; \
    132 	  printf '%s: %s\n' "$${exe}" $(@:.t=.o); \
    133 	  printf 'test_list: %s\n' "$${exe}"; \
    134 	} > $@
    135 
    136 $(TEST_DEP): config.mk suniq-local.pc
    137 	@$(CC) $(CFLAGS_TEST) -MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    138 
    139 $(TEST_OBJ): config.mk suniq-local.pc
    140 	$(CC) $(CFLAGS_TEST) -c $(@:.o=.c) -o $@
    141 
    142 test_suniq \
    143 : config.mk suniq-local.pc $(LIBNAME)
    144 	$(CC) $(CFLAGS_TEST) -o $@ src/$@.o $(LDFLAGS_TEST)
    145 
    146 clean_test:
    147 	rm -f $(TEST_DEP) $(TEST_OBJ) $(TEST_TGT)
    148 	for i in $(TEST_SRC); do rm -f "$$(basename "$${i}" ".c")"; done
    149 
    150 test: tests
    151 	@err=0; \
    152 	for i in $(TEST_SRC); do \
    153 	  test="$$(basename "$${i}" ".c")"; \
    154 	  if "./$${test}" > /dev/null 2>&1; then \
    155 	    printf '%s\n' "$${test}"; \
    156 	  else \
    157 	    >&2 printf '%s: error %s\n' "$${test}" "$$?"; \
    158 	    err=$$((err+1)); \
    159 	  fi \
    160 	done; \
    161 	[ "$${err}" -eq 0 ]