#!/usr/bin/make -f

##############
# Legal stuff
##############

# Build script for Texttools examples.
# Copyright (c) 2009 Nicolas Boulenguez <nicolas.boulenguez@free.fr>

# This build script is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 3 of the
# License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
# USA

#####################

# do no use parallel builds; we want explicit logs.
# neither Make
.NOTPARALLEL:
# neither gnatmake
CPUS := 1


EXAMPLES := $(patsubst %.adb,%,$(wildcard *.adb))
C_OBJECTS := $(patsubst ../C_code/%.c,%.o,$(wildcard ../C_code/*.c))

.PHONY: examples clean

examples: $(EXAMPLES)

.PHONY: $(EXAMPLES)
# phony so that gnatmake will choose wether rebuild
$(EXAMPLES): $(C_OBJECTS)
	gnatmake -j$(CPUS) $@ \
          -cargs -I.. -g -O0 -gnatafno -gnatVa -gnatwa -gnata \
          -largs -lm -lncurses $(C_OBJECTS)

%.o: ../C_code/%.c
	$(CC) -c $(CPPFLAGS) $(CFLAGS) -g -O0 -Wall -D_Bool=char -I ../C_code $< -o $@
# -fstack-check temporarily disabled due to http://gcc.gnu.org/PR20548.

clean:
	$(RM) *.o *.ali b~*.ad[sb] *~ $(EXAMPLES)
