star-cad

Geometric operators for computer-aided design
git clone git://git.meso-star.fr/star-cad.git
Log | Files | Refs | README | LICENSE

Makefile (5973B)


      1 # Copyright (C) 2022-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 = libscad.a
     22 LIBNAME_SHARED = libscad.so
     23 LIBNAME = $(LIBNAME_$(LIB_TYPE))
     24 
     25 ################################################################################
     26 # Library building
     27 ################################################################################
     28 SRC =\
     29  src/scad.c\
     30  src/scad_device.c\
     31  src/scad_geometry.c
     32 OBJ = $(SRC:.c=.o)
     33 DEP = $(SRC:.c=.d)
     34 
     35 build_library: .config $(DEP)
     36 	@$(MAKE) -fMakefile $$(for i in $(DEP); do echo -f $${i}; done) \
     37 	$$(if [ -n "$(LIBNAME)" ]; then\
     38 	     echo "$(LIBNAME)";\
     39 	   else\
     40 	     echo "$(LIBNAME_SHARED)";\
     41 	   fi)
     42 
     43 $(DEP) $(OBJ): config.mk
     44 
     45 $(LIBNAME_SHARED): $(OBJ)
     46 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS_SO) $(DPDC_LIBS)
     47 
     48 $(LIBNAME_STATIC): libscad.o
     49 	$(AR) -rc $@ $?
     50 	$(RANLIB) $@
     51 
     52 libscad.o: $(OBJ)
     53 	$(LD) -r $(OBJ) -o $@
     54 	$(OBJCOPY) $(OCPFLAGS) $@
     55 
     56 .config: config.mk
     57 	@if ! $(PKG_CONFIG) --atleast-version $(GMSH_VERSION) gmsh; then \
     58 	  echo "gmsh $(GMSH_VERSION) not found" >&2; exit 1; fi
     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 $(SENC3D_VERSION) senc3d; then \
     62 	  echo "senc3d $(SENC3D_VERSION) not found" >&2; exit 1; fi
     63 	@if ! $(PKG_CONFIG) --atleast-version $(SG3D_VERSION) sg3d; then \
     64 	  echo "sg3d $(SG3D_VERSION) not found" >&2; exit 1; fi
     65 	@echo "config done" > $@
     66 
     67 .SUFFIXES: .c .d .o
     68 .c.d:
     69 	@$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -MM -MT "$(@:.d=.o) $@" $< -MF $@
     70 
     71 .c.o:
     72 	$(CC) $(CFLAGS_SO) $(DPDC_CFLAGS) -DSCAD_SHARED_BUILD -c $< -o $@
     73 
     74 ################################################################################
     75 # Installation
     76 ################################################################################
     77 pkg:
     78 	sed -e 's#@PREFIX@#$(PREFIX)#g'\
     79 	    -e 's#@VERSION@#$(VERSION)#g'\
     80 	    -e 's#@GMSH_VERSION@#$(GMSH_VERSION)#g'\
     81 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     82 	    -e 's#@SENC3D_VERSION@#$(SENC3D_VERSION)#g'\
     83 	    -e 's#@SG3D_VERSION@#$(SG3D_VERSION)#g'\
     84 	    scad.pc.in > scad.pc
     85 
     86 scad-local.pc: scad.pc.in
     87 	sed -e '1d'\
     88 	    -e 's#^includedir=.*#includedir=./src/#'\
     89 	    -e 's#^libdir=.*#libdir=./#'\
     90 	    -e 's#@VERSION@#$(VERSION)#g'\
     91 	    -e 's#@GMSH_VERSION@#$(GMSH_VERSION)#g'\
     92 	    -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
     93 	    -e 's#@SENC3D_VERSION@#$(SENC3D_VERSION)#g'\
     94 	    -e 's#@SG3D_VERSION@#$(SG3D_VERSION)#g'\
     95 	    scad.pc.in > $@
     96 
     97 install: build_library pkg
     98 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
     99 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" scad.pc
    100 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include/star" src/scad.h
    101 	@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/star-cad" COPYING README.md
    102 
    103 uninstall:
    104 	rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
    105 	rm -f "$(DESTDIR)$(PREFIX)/lib/pkgconfig/scad.pc"
    106 	rm -f "$(DESTDIR)$(PREFIX)/include/star/scad.h"
    107 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cad/COPYING"
    108 	rm -f "$(DESTDIR)$(PREFIX)/share/doc/star-cad/README.md"
    109 
    110 ################################################################################
    111 # Miscellaneous targets
    112 ################################################################################
    113 all: build_library build_tests
    114 
    115 clean: clean_test
    116 	rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
    117 	rm -f .config .test libscad.o scad.pc scad-local.pc
    118 
    119 distclean: clean
    120 	rm -f $(DEP) $(TEST_DEP)
    121 
    122 lint:
    123 	shellcheck -o all make.sh
    124 
    125 ################################################################################
    126 # Tests
    127 ################################################################################
    128 TEST_SRC =\
    129  src/test_api.c\
    130  src/test_export.c\
    131  src/test_export2.c\
    132  src/test_lifetime.c\
    133  src/test_partition.c\
    134  src/test_periodic.c\
    135  src/test_sync.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 SCAD_CFLAGS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --cflags scad-local.pc)
    141 SCAD_LIBS = $$($(PKG_CONFIG_LOCAL) $(PCFLAGS) --libs scad-local.pc)
    142 
    143 build_tests: build_library $(TEST_DEP) .test
    144 	@$(MAKE) -fMakefile -f.test \
    145 	$$(for i in $(TEST_DEP); do echo -f"$${i}"; done) \
    146 	test_bin
    147 
    148 test: build_tests
    149 	@$(SHELL) make.sh run_test $(TEST_SRC)
    150 
    151 .test: Makefile
    152 	@$(SHELL) make.sh config_test $(TEST_SRC) > $@
    153 
    154 clean_test:
    155 	$(SHELL) make.sh clean_test $(TEST_SRC)
    156 	rm -f bin_fused.stl
    157 	rm -f bin_cube.stl
    158 	rm -f bin_rectangle.stl
    159 	rm -f cube.stl
    160 	rm -f cube_quasi.stl
    161 	rm -f different_names_0.stl
    162 	rm -f fused.stl
    163 	rm -f fused_quasi.stl
    164 	rm -f not-a-volume.stl.stl
    165 	rm -f part_0.9_1o.stl
    166 	rm -f part_0.9_2o.stl
    167 	rm -f part_1.1_1.stl
    168 	rm -f part_1.1_2.stl
    169 	rm -f part_1_1.stl
    170 	rm -f part_1_2.stl
    171 	rm -f rectangle.stl
    172 	rm -f rectangle_quasi.stl
    173 	rm -f "sphere 1_0.stl"
    174 	rm -f "sphere 1.stl"
    175 
    176 $(TEST_DEP): config.mk scad-local.pc
    177 	@$(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SCAD_CFLAGS) \
    178 	-MM -MT "$(@:.d=.o) $@" $(@:.d=.c) -MF $@
    179 
    180 $(TEST_OBJ): config.mk scad-local.pc
    181 	$(CC) $(CFLAGS_EXE) $(RSYS_CFLAGS) $(SCAD_CFLAGS) -c $(@:.o=.c) -o $@
    182 
    183 test_api \
    184 test_export \
    185 test_export2 \
    186 test_lifetime \
    187 test_partition \
    188 test_periodic \
    189 test_sync \
    190 : config.mk scad-local.pc $(LIBNAME)
    191 	$(CC) $(CFLAGS_EXE) -o $@ src/$@.o $(LDFLAGS_EXE) $(SCAD_LIBS) $(RSYS_LIBS) -lm