d2f921934665faaa057542ec8af804580aa5ad0f
[sven/jattach.git] / Makefile
1 JATTACH_VERSION=1.5
2
3 ifneq ($(findstring Windows,$(OS)),)
4   CL=cl.exe
5   CFLAGS=/O2 /D_CRT_SECURE_NO_WARNINGS
6   JATTACH_EXE=jattach.exe
7 else 
8   UNAME_S:=$(shell uname -s)
9   ifneq ($(findstring FreeBSD,$(UNAME_S)),)
10     CC=cc
11     CFLAGS=-O2
12     JATTACH_EXE=jattach
13   else
14     ROOT_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
15     RPM_ROOT=$(ROOT_DIR)/build/rpm
16     SOURCES=$(RPM_ROOT)/SOURCES
17     SPEC_FILE=jattach.spec
18     CC=gcc
19     JATTACH_EXE=jattach
20   endif
21 endif
22
23 all: build build/$(JATTACH_EXE)
24
25 build:
26         mkdir -p build
27
28 build/jattach: src/jattach_posix.c
29         $(CC) $(CFLAGS) -DJATTACH_VERSION=\"$(JATTACH_VERSION)\" -o $@ $^
30
31 build/jattach.exe: src/jattach_windows.c
32         $(CL) $(CFLAGS) /DJATTACH_VERSION=\"$(JATTACH_VERSION)\" /Fobuild/jattach.obj /Fe$@ $^ advapi32.lib /link /SUBSYSTEM:CONSOLE,5.02
33
34 clean:
35         rm -rf build
36
37 $(RPM_ROOT):
38         mkdir -p $(RPM_ROOT)
39
40 rpm-dirs: $(RPM_ROOT)
41         mkdir -p $(RPM_ROOT)/SPECS
42         mkdir -p $(SOURCES)/bin
43         mkdir -p $(RPM_ROOT)/BUILD
44         mkdir -p $(RPM_ROOT)/SRPMS
45         mkdir -p $(RPM_ROOT)/RPMS
46         mkdir -p $(RPM_ROOT)/tmp
47
48 rpm: rpm-dirs build build/$(JATTACH_EXE)
49         cp $(SPEC_FILE) $(RPM_ROOT)/
50         cp build/jattach $(SOURCES)/bin/
51         rpmbuild -bb \
52                 --define '_topdir $(RPM_ROOT)' \
53                 --define '_tmppath $(RPM_ROOT)/tmp' \
54                 --clean \
55                 --rmsource \
56                 --rmspec \
57                 --buildroot $(RPM_ROOT)/tmp/build-root \
58                 $(RPM_ROOT)/jattach.spec