stacinhtml

Static C in HTML - simple static site generator
git clone git://git.kocotian.pl/stacinhtml.git
Log | Files | Refs | README | LICENSE

Makefile (2409B)


      1 #
      2 # stacinhtml - STAtic C IN HTML - simple static site generator
      3 # Copyright (C) 2021  Kacper Kocot <kocotian@kocotian.pl>
      4 #
      5 # This program is free software; you can redistribute it and/or modify
      6 # it under the terms of the GNU General Public License as published by
      7 # the Free Software Foundation; either version 3 of the License, or
      8 # (at your option) any later version.
      9 #
     10 # This program is distributed in the hope that it will be useful,
     11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13 # GNU General Public License for more details.
     14 #
     15 # You should have received a copy of the GNU General Public License
     16 # along with this program; if not, write to the Free Software Foundation,
     17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
     18 #
     19 
     20 # == Section 0: Includes and basic dependencies ==
     21 
     22 include config.mk
     23 
     24 all: pages
     25 pages: generator
     26 
     27 .PHONY: all pages generator
     28 
     29 # == Section 1: Building a generator ==
     30 
     31 SRCLIB = util.c assemble.c str.c libstac/libstac.c
     32 OBJLIB = ${SRCLIB:.c=.o}
     33 
     34 SRC = compile.c
     35 EXE = ${SRC:.c=}
     36 
     37 generator: buildoptions ${EXE}
     38 
     39 buildoptions:
     40 	@echo build options:
     41 	@echo "CFLAGS       = ${CFLAGS}"
     42 	@echo "CPPFLAGS     = ${CPPFLAGS}"
     43 	@echo "LDFLAGS      = ${LDFLAGS}"
     44 	@echo "CC           = ${CC}"
     45 
     46 ${EXE}: ${SRC}
     47 
     48 ${EXE}: ${OBJLIB}
     49 
     50 ${OBJLIB}: ${SRCLIB}
     51 
     52 %.o: %.c
     53 	${CC} ${CCFLAGS} -c -o $@ $<
     54 
     55 %: %.c ${OBJLIB}
     56 	${CC} ${CCFLAGS} ${LDFLAGS} -o $@ $^
     57 
     58 # == Section 2: Generating pages ==
     59 
     60 INDIRS = $(sort $(shell find $(INDIR) -type d))
     61 IN = $(sort $(shell find $(INDIR) -type f -name '*.stac'))
     62 
     63 METADIRS = $(patsubst $(INDIR)%,$(METADIR)%,$(INDIRS))
     64 META = $(patsubst $(INDIR)%,$(METADIR)%,$(IN:.stac=.c))
     65 BIN = $(META:.c=.bin)
     66 
     67 OUTDIRS = $(patsubst $(METADIR)%,$(OUTDIR)%,$(METADIRS))
     68 OUT = $(patsubst $(METADIR)%,$(OUTDIR)%,$(BIN:.bin=.html))
     69 
     70 GENERATOR = ./compile
     71 
     72 pages:
     73 
     74 pages: ${OUT}
     75 
     76 ${OUT}: ${OUTDIRS}
     77 
     78 ${OUTDIRS}: ${METADIRS}
     79 	mkdir -p $(OUTDIRS)
     80 
     81 ${METADIRS}: ${INDIRS}
     82 	mkdir -p $(METADIRS)
     83 
     84 ${IN}: generator ${GENERATOR}
     85 
     86 ${METADIR}%.c: ${INDIR}%.stac
     87 	${GENERATOR} -o $@ $(patsubst $(METADIR)%,$(INDIR)%,$(@:.c=.stac))
     88 
     89 ${METADIR}%.bin: ${METADIR}%.c
     90 	${CC} -o $@ -I. $(@:.bin=.c) ${OBJLIB}
     91 
     92 ${OUTDIR}%.html: ${METADIR}%.bin
     93 	./$(patsubst $(OUTDIR)%,$(METADIR)%,$(@:.html=.bin)) > $@
     94 
     95 clean:
     96 	rm -f ${OBJLIB} ${EXE} *.o
     97 	rm -rf ${METADIR} ${OUTDIR}
     98 
     99 .PHONY: mkpagedirs clean