# This is a sample makefile for generating a library
# of imported types and functions.
# Version 1.0 (19/01/98, ajw)

# This makefile is written for the GNU version of make.
# If you encounter any problems please feel free to contact us.
# Email your problem report to 
# 	progres@i3.informatik.rwth-aachen.de
#
# PLEASE CHECK THE FOLLOWING LINES!
#

# ----- User specific variables -----

# Note that the values of the following three variables 
# (PROGRESROOT, GENDIR, and IMPORTLIB) are taken from the 
# environment if set.

# Definition of the PROGRES environment's root directory
# which contains all installed PROGRES files.
ifndef PROGRESROOT
  PROGRESROOT = $(HOME)
endif

# GENDIR denotes to the directory where the code is
# located. Default is the current directory.
# Object files and library will be installed
# relative to this directory.
ifndef GENDIR
  GENDIR = $(shell pwd)
  export GENDIR
endif

# Name of the generated library. 
# Variable is also used in PROGRES and prototype
# start-up scripts and prototype makefile.
ifndef IMPORTLIB
  IMPORTLIB = libImportedFunctions.so
endif

# List of C source files to be compiled and linked.
# Default is all C files in GENDIR.
SOURCES = 
ifndef SOURCES 
  SOURCES = $(wildcard $(GENDIR)/*.c)
endif

# Directories with include files and libraries
# form compiling and linking.
IMPORTINCLUDES = -I.
IMPORTLIBS = -lm


# ----- Installation specific variables -----

# Determine the operating system's name and version
ossys=$(shell uname -s)
osver=$(shell uname -r)
ifeq (SunOS, $(ossys))
  ifeq ($(findstring 5.,$(osver)), 5.)
    OSVERSION=SOL2
  else
    OSVERSION=SUNOS4
  endif
else 
  ifeq (Linux, $(ossys))
    OSVERSION=LINUXELF
  else
    OSVERSION=UNKNOWN
  endif
endif


# ----- There should be no reason to change anything below this line -----

SHELL = /bin/sh
CC = gcc
LN = ln -sf

OBJDIR = $(GENDIR)/obj/$(OSVERSION)
LIBDIR = $(GENDIR)/lib/$(OSVERSION)

STDINCLUDE      = $(PROGRESROOT)/prototype/include
STDLIB          = $(PROGRESROOT)/lib/$(OSVERSION)


# ----- Environment variables are now set. Build compile and link flags.

# These options are at least needed for successful compilation.
CFLAGS    = -g -Wall -Wid-clash-31 -Wpointer-arith -Wcast-qual -Wtraditional -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wnested-externs -Winline -w -B -pipe -Wno-unused -Woverloaded-virtual -fpic -fdollars-in-identifiers -fshort-enums -DEPC_MODULA -D$(OSVERSION)

INCLUDES = $(IMPORTINCLUDES) -I$(STDINCLUDE)
OBJS = $(addprefix $(OBJDIR)/,$(addsuffix .o,$(basename $(notdir $(SOURCES)))))

LDFLAGS = -shared
LIBS = $(IMPORTLIBS) -L$(STDLIB)


# ----- Now everything should be all right, so we try to compile ... -----

all: $(LIBDIR)/$(IMPORTLIB)

$(LIBDIR)/$(IMPORTLIB): $(OBJS)
	@if [ ! -d $(LIBDIR) ] ; \
	   then \
	     mkdir -p $(LIBDIR) ; \
	 fi
	$(CC) $(LDFLAGS) $(OBJS) $(LIBS) -o $@

$(OBJDIR)/%.o: %.c %.h
	@if [ ! -d $(GENDIR) ] ; \
	   then \
	     mkdir $(GENDIR) ; \
	 fi
	@if [ ! -d $(OBJDIR) ] ; \
	   then \
	     mkdir -p $(OBJDIR) ; \
	 fi
	$(CC) -c $(CFLAGS) $(INCLUDES) $< -o $@

clean:
	rm -f $(OBJS) make.log Makefile.bak

depend:
	$(CC) -M $(INCLUDES) -D$(OSVERSION) $(SOURCES) > .depend

# Include dependencies (if a .depend file exist)
ifeq (.depend,$(wildcard .depend))
include .depend
endif

