# 
# This make file is intended to build the code under Linux
# To create everything
#
# make -f makeall.linux
#

BUILDEXE := linux
BUILDSO  := linux_so

COPTS := -Wall -O2 -c

DLL1 := stm_print
OBJ1 := pipeproto stm_print mypipe

APP2 := create_fake_tpiu
OBJ2 := create_fake_tpiu twp

APP3 := pipe_read
OBJ3 := pipe_read mypipe

DLL4 := itm_print
OBJ4 := pipeproto itm_print mypipe

DLL5 := stpv1_print
OBJ5 := pipeproto stpv1_print mypipe


OBJ1 := $(patsubst %,$(BUILDSO)/%.o,$(OBJ1))
DLL1 := $(patsubst %,$(BUILDSO)/%.so,$(DLL1))

OBJ2 := $(patsubst %,$(BUILDEXE)/%.o,$(OBJ2))
APP2 := $(patsubst %,$(BUILDEXE)/%,$(APP2))

OBJ3 := $(patsubst %,$(BUILDEXE)/%.o,$(OBJ3))
APP3 := $(patsubst %,$(BUILDEXE)/%,$(APP3))

OBJ4 := $(patsubst %,$(BUILDSO)/%.o,$(OBJ4))
DLL4 := $(patsubst %,$(BUILDSO)/%.so,$(DLL4))

OBJ5 := $(patsubst %,$(BUILDSO)/%.o,$(OBJ5))
DLL5 := $(patsubst %,$(BUILDSO)/%.so,$(DLL5))

all: $(DLL1) $(APP2) $(APP3) $(DLL4) $(DLL5)

$(OBJ1) $(OBJ4) $(OBJ5): | $(BUILDSO)

$(OBJ2) $(OBJ3): | $(BUILDEXE)

$(BUILDSO):
	mkdir $(BUILDSO)

$(BUILDEXE):
	mkdir $(BUILDEXE)

$(DLL1): $(OBJ1)
	gcc -shared -o $@ $^
	strip $@

$(APP2): $(OBJ2)
	gcc -o $@ $^
	strip $@

$(APP3): $(OBJ3)
	gcc -o $@ $^
	strip $@

$(DLL4): $(OBJ4)
	gcc -shared -o $@ $^
	strip $@

$(DLL5): $(OBJ5)
	gcc -shared -o $@ $^
	strip $@

$(BUILDEXE)/%.o: src/%.c
	gcc $(COPTS) -o $@ $<

$(BUILDSO)/%.o: src/%.c
	gcc $(COPTS) -fPIC -o $@ $<

clean:
	rm -rf $(BUILDEXE) $(BUILDSO)
	
cleanmost:
	rm -f $(BUILDEXE)/*.o $(BUILDSO)/*.o

