Skip to content

Commit 0d104ff

Browse files
AitorATuinAitor Iturri
authored and
Aitor Iturri
committed
Refactor Makefile
1 parent 09324f5 commit 0d104ff

File tree

7 files changed

+106
-64
lines changed

7 files changed

+106
-64
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.swp
2+
*~

Makefile

+62-39
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,80 @@
1-
2-
PYTHON_VERSION=2.7
3-
PYTHON_LIBS=FindPackage GetAvailable GuessLatest CheckDependencies DescribeProgram UseFlags Corrections Alien
4-
PYTHON_SITE=lib/python$(PYTHON_VERSION)/site-packages
51
PROGRAM=Scripts
62
VERSION=git-$(shell date +%Y%m%d)
73
goboPrograms?=/Programs
84
PREFIX?=
9-
DESTDIR=$(goboPrograms)/$(PROGRAM)/$(VERSION)
5+
DESTDIR=$(PREFIX)/$(goboPrograms)/$(PROGRAM)/$(VERSION)
106

11-
man_files = $(shell cd bin; grep -l Parse_Options * | xargs -i echo share/man/man1/{}.1)
12-
exec_files = $(patsubst src/%.c,bin/%,$(wildcard src/*.c))
7+
INSTALL_FILE = install
8+
INSTALL_DIR = install -d
9+
10+
PYTHON_VERSION=2.7
11+
PYTHON_LIBS=FindPackage GetAvailable GuessLatest CheckDependencies DescribeProgram UseFlags Corrections Alien
12+
PYTHON_SITE=python$(PYTHON_VERSION)/site-packages
1313

14-
all: python $(exec_files) manuals
14+
MAN_FILES = $(shell grep -l Parse_Options bin/* | xargs -i echo {}.1)
15+
SCRIPT_FILES = AddUser AttachProgram DeduceName FindPackage GoboPath install PrioritiseUpdates ScriptFunctions UnversionExecutables VersionExecutables Alien AugmentCommandNotFoundDatabase Dependencies FindQuick GrepQuick InstallPackage ProblemReport SignProgram UpdateKdeRecipe which Alien-Cabal CheckDependants DescribeProgram FixAttributes GrepReplace KillProcess RemoveBroken SuggestDuplicates UpdateSettings xmlcatalog Alien-CPAN CheckDependencies DetachProgram FixDirReferences GuessLatest ListProgramFiles RemoveEmpty SuggestUpdates UpdateXorgRecipe Alien-LuaRocks CleanModules DisableProgram FixInfo GuessProgramCase RemoveProgram SymlinkProgram UpgradeSystem Alien-PIP Corrections FilterColors GenBuildInformation HasCompatiblePackage MergeTree Rename SystemFind UseFlags Alien-RubyGems CreatePackage FilterLines GetAvailable Hashes NamingConventions RescueInstallPackage SystemInfo VerifyProgram
1516

16-
debug: python
17-
cd src; $(MAKE) debug
17+
.PHONY: all clean install
1818

19-
python:
20-
for f in $(PYTHON_LIBS); \
21-
do libf=$(PYTHON_SITE)/$$f.py; \
22-
rm -f $$libf; ln -nfs ../../../bin/$$f $$libf; \
23-
done
24-
cd $(PYTHON_SITE) && \
25-
for f in *.py; \
26-
do python -c "import `basename $$f .py`"; \
27-
done
19+
all:
20+
@$(MAKE) -C src
2821

2922
clean:
23+
@$(MAKE) -C src clean
24+
@echo "Cleaning man pages"
25+
$(foreach MAN_FILE, $(MAN_FILES), \
26+
rm -f $(MAN_FILE) ; \
27+
)
3028
rm -rf Resources/FileHash*
31-
find * -path "*~" -or -path "*/.\#*" -or -path "*.bak" | xargs rm -f
32-
cd src && $(MAKE) clean
33-
cd $(PYTHON_SITE) && rm -f *.pyc *.pyo
34-
rm -f $(exec_files)
35-
rm -rf share/man/man1
3629

37-
manuals: $(man_files)
30+
python_install:
31+
@echo "Installing python libraries"
32+
mkdir -p $(DESTDIR)/lib/$(PYTHON_SITE)
33+
$(foreach PYTHON_LIB, $(PYTHON_LIBS), \
34+
ln -nfs $(DESTDIR)/bin/$(PYTHON_LIB) $(DESTDIR)/lib/$(PYTHON_SITE) ; \
35+
)
36+
cp lib/python/*.py $(DESTDIR)/lib/$(PYTHON_SITE)
37+
38+
manuals: $(MAN_FILES)
3839

39-
$(man_files): share/man/man1/%.1: bin/%
40-
@mkdir -p share/man/man1
40+
$(MAN_FILES): %.1: %
41+
@echo "Generating man page $@"
4142
help2man --name=" " --source="GoboLinux" --no-info $< --output $@
4243

43-
$(exec_files): bin/%: src/%
44-
cp -f $< $@
45-
chmod a+x $@
44+
install_manuals: manuals
45+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/share/man/man1
46+
$(foreach MAN_FILE, $(MAN_FILES), \
47+
$(INSTALL_FILE) -m 644 $(MAN_FILE) $(DESTDIR)/share/man/man1 ; \
48+
)
49+
50+
install_scripts:
51+
@echo "Installing scripts"
52+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
53+
$(foreach SCRIPT_FILE, $(SCRIPT_FILES), \
54+
$(INSTALL_FILE) -m 755 bin/$(SCRIPT_FILE) $(DESTDIR)/bin ; \
55+
)
56+
57+
install_data:
58+
@echo "Installing Data"
59+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/Data
60+
cp -r Data $(DESTDIR)
61+
62+
install_resources:
63+
@echo "Installing Resources"
64+
cp -r Resources $(DESTDIR)
65+
66+
install_share_data:
67+
@echo "Installing share data"
68+
cp -rf share $(DESTDIR)
4669

47-
src/%: src/%.c
48-
$(MAKE) -C src
70+
install_functions:
71+
@echo "Installing Functions"
72+
cp -rf Functions $(DESTDIR)
4973

50-
.PHONY: all python manuals debug clean
74+
prepare_install:
75+
@echo "Installing $(PROGRAM) into $(DESTDIR)"
76+
$(INSTALL_DIR) -m 755 $(DESTDIR)
5177

52-
install: python $(exec_files) manuals
53-
@echo "Installing Scripts into $(PREFIX)/$(DESTDIR)"
54-
@install -d -m 755 $(PREFIX)/$(DESTDIR)
55-
@echo "Copying files ..."
56-
@./bin/ListProgramFiles `pwd` | grep -v "^src" | grep -v "^Makefile" | \
57-
cpio --pass-through --quiet --verbose --unconditional $(PREFIX)/$(DESTDIR)
78+
install: all prepare_install install_scripts install_data install_resources install_share_data install_functions python_install install_manuals
79+
@$(MAKE) DESTDIR=$(DESTDIR) -C src install
80+
@echo "Installed $(PROGRAM) into $(DESTDIR)"

lib/python2.7/site-packages/Alien.py

-1
This file was deleted.

lib/python2.7/site-packages/Corrections.py

-1
This file was deleted.

src/Makefile

+42-23
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,74 @@
1-
2-
MYCFLAGS = -O2 -Wall
1+
DESTDIR?=
32
CC = gcc
3+
CFLAGS = -O2 -Wall
4+
INSTALL_FILE=install -s
5+
INSTALL_DIR=install -d
46

5-
STATIC=-static
6-
ifeq ($(shell uname -s),Darwin)
7-
STATIC=
8-
endif
9-
7+
# Running on windows
108
IS_CYGWIN=$(shell uname | grep -i cygwin &>/dev/null && echo yes || echo no)
119
ifeq ($(IS_CYGWIN),yes)
1210
RM_EXE=-rm -f *.exe
1311
endif
1412

13+
STATIC_CFLAGS = $(CFLAGS) -static
14+
ifneq ($(shell uname -s),Darwin)
15+
STATIC_CFLAGS = $(CFLAGS)
16+
endif
17+
18+
# Add compiler options
19+
ifdef DEBUG
20+
CFLAGS += -g -DDEBUG
21+
STATIC_CFLAGS += -g -DDEBUG
22+
INSTALL_FILE=install
23+
endif
24+
25+
exec_files = $(patsubst %.c,%,$(wildcard *.c))
26+
1527
dynamic_exec = BackgroundExec SuperUserName IsExecutable usleep LinkOrExpandAll List CommandNotFound GetSupportedFilesystems
1628
static_exec = RescueSymlinkProgram
1729
other_exec = FindDependencies Runner
1830

1931
# first rule
20-
default: all
2132

22-
.PHONY: all default
33+
.PHONY: all clean static debug install
2334

2435
all: $(dynamic_exec) $(static_exec) $(other_exec)
2536

2637
$(dynamic_exec): %: %.c
27-
$(CC) $(MYCFLAGS) $< -o $@
28-
@if [ -e "$@.exe" ]; then \
38+
@echo "Compiling $@"
39+
$(CC) $(CFLAGS) $< -o $@
40+
if [ -e "$@.exe" ]; then \
2941
mv $@.exe $@; \
3042
fi
3143

3244
$(static_exec): %: %.c
33-
$(CC) $(MYCFLAGS) $< -o $@ $(STATIC)
34-
@if [ -e "$@.exe" ]; then \
45+
@echo "Compiling $@"
46+
$(CC) $(STATIC_CFLAGS) $< -o $@
47+
if [ -e "$@.exe" ]; then \
3548
mv $@.exe $@; \
3649
fi
3750

3851
FindDependencies: %: %.c
39-
$(CC) $(MYCFLAGS) $< -o $@ -DBUILD_MAIN
52+
@echo "Compiling $@"
53+
$(CC) $(CFLAGS) $< -o $@ -DBUILD_MAIN
4054

4155
Runner: Runner.c FindDependencies.c
42-
$(CC) $(MYCFLAGS) $^ -o $@
43-
chmod 4755 $@
44-
45-
debug: MYCFLAGS = -g -DDEBUG -Wall
46-
debug: all
47-
48-
static: MYCFLAGS = $(STATIC)
49-
static: all
56+
@echo "Compiling $@"
57+
$(CC) $(CFLAGS) $^ -o $@
5058

5159
clean:
60+
@echo "Cleaning sources"
5261
rm -f $(dynamic_exec) $(static_exec) $(other_exec) lib*.so lib*.so.* *.o
5362
$(RM_EXE)
5463

55-
.PHONY: all clean static debug install
64+
install: all
65+
@echo "Installing compiled binaries"
66+
ifndef DESTDIR
67+
$(error DESTDIR is not set)
68+
endif
69+
$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
70+
$(foreach EXEC_FILE, $(exec_files), \
71+
$(INSTALL_FILE) -m 755 $(EXEC_FILE) $(DESTDIR)/bin ; \
72+
)
73+
chmod 4755 $(DESTDIR)/bin/Runner
74+

0 commit comments

Comments
 (0)