Skip to content

Commit 48fb500

Browse files
committed
Refactor Makefile
1 parent 8ac9582 commit 48fb500

File tree

9 files changed

+178
-65
lines changed

9 files changed

+178
-65
lines changed

.gitignore

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

Makefile

+53-41
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,69 @@
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)
10-
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))
5+
DESTDIR=$(PREFIX)/$(goboPrograms)/$(PROGRAM)/$(VERSION)
136

14-
all: python $(exec_files) manuals
7+
INSTALL_FILE = install
8+
INSTALL_DIR = install -d
159

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

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
12+
all:
13+
@$(MAKE) -C src
14+
@$(MAKE) -C bin
2815

2916
clean:
17+
@$(MAKE) -C src clean
18+
@$(MAKE) -C lib clean
19+
@$(MAKE) -C bin clean
3020
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
3621

37-
manuals: $(man_files)
22+
install_data:
23+
@echo "Installing Data"
24+
@$(INSTALL_DIR) -d -m 755 $(DESTDIR)/Data
25+
@cp -r Data $(DESTDIR)
26+
27+
uninstall_data:
28+
@echo "Uninstalling Data"
29+
@rm -rf $(DESTDIR)/Data
30+
31+
install_resources:
32+
@echo "Installing Resources"
33+
@cp -r Resources $(DESTDIR)
34+
35+
uninstall_resources:
36+
@echo "Uninstalling Resources"
37+
@rm -rf $(DESTDIR)/Resources
38+
39+
install_share_data:
40+
@echo "Installing share data"
41+
@cp -rf share $(DESTDIR)
42+
43+
uninstall_share_data:
44+
@echo "Uninstalling share data"
45+
@rm -rf $(DESTDIR)/share
3846

39-
$(man_files): share/man/man1/%.1: bin/%
40-
@mkdir -p share/man/man1
41-
help2man --name=" " --source="GoboLinux" --no-info $< --output $@
47+
install_functions:
48+
@echo "Installing Functions"
49+
@cp -rf Functions $(DESTDIR)
4250

43-
$(exec_files): bin/%: src/%
44-
cp -f $< $@
45-
chmod a+x $@
51+
uninstall_functions:
52+
@echo "Uninstalling Functions"
53+
@rm -rf $(DESTDIR)/Functions
4654

47-
src/%: src/%.c
48-
$(MAKE) -C src
55+
prepare_install:
56+
@echo "Installing $(PROGRAM) into $(DESTDIR)"
57+
@$(INSTALL_DIR) -m 755 $(DESTDIR)
4958

50-
.PHONY: all python manuals debug clean
59+
install: all prepare_install install_data install_resources install_share_data install_functions
60+
@$(MAKE) DESTDIR=$(DESTDIR) -C bin install
61+
@$(MAKE) DESTDIR=$(DESTDIR) -C src install
62+
@$(MAKE) DESTDIR=$(DESTDIR) -C lib install
63+
@echo "Installed $(PROGRAM) into $(DESTDIR)"
5164

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)
65+
uninstall: uninstall_data uninstall_resources uninstall_share_data uninstall_functions
66+
@$(MAKE) DESTDIR=$(DESTDIR) -C bin uninstall
67+
@$(MAKE) DESTDIR=$(DESTDIR) -C src uninstall
68+
@$(MAKE) DESTDIR=$(DESTDIR) -C lib uninstall
69+
@echo "Uninstalled Scripts from $(DESTDIR)"

bin/Makefile

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
DESTDIR?=
2+
INSTALL_FILE = install
3+
INSTALL_DIR = install -d
4+
5+
man_files = $(shell grep -l Parse_Options * | grep -v Makefile | xargs -i echo {}.1)
6+
scripts = 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 Makefile RemoveProgram SymlinkProgram UpgradeSystem Alien-PIP Corrections FilterColors GenBuildInformation HasCompatiblePackage MergeTree Rename SystemFind UseFlags Alien-RubyGems CreatePackage FilterLines GetAvailable Hashes NamingConventions RescueInstallPackage SystemInfo VerifyProgram
7+
8+
.PHONY: all clean install manuals
9+
10+
all: manuals
11+
12+
manuals: $(man_files)
13+
14+
$(man_files): %.1: %
15+
@echo "Generating man page $@"
16+
@help2man --name=" " --source="GoboLinux" --no-info $< --output $@
17+
18+
clean:
19+
@echo "Cleaning man pages"
20+
@echo $(man_files) | tr '\n' ' ' | xargs -d ' ' -n 1 rm -f
21+
22+
install_manuals: manuals
23+
ifndef DESTDIR
24+
$(error DESTDIR is not set)
25+
endif
26+
@$(INSTALL_DIR) -d -m 755 $(DESTDIR)/share/man/man1
27+
@echo $(man_files) | tr '\n' ' ' | xargs -d ' ' -n 1 -i \
28+
$(INSTALL_FILE) -m 644 {} $(DESTDIR)/share/man/man1
29+
30+
install_scripts:
31+
@echo "Installing scripts"
32+
ifndef DESTDIR
33+
$(error DESTDIR is not set)
34+
endif
35+
@$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
36+
@echo $(scripts) | tr '\n' ' ' | xargs -d ' ' -n 1 -i \
37+
$(INSTALL_FILE) -m 755 {} $(DESTDIR)/bin
38+
39+
install: install_manuals install_scripts
40+
41+
uninstall:
42+
@echo $(scripts) | tr '\n' ' ' | xargs -d ' ' -n 1 -i rm -f $(DESTDIR)/bin/{}
43+
@echo $(man_files) | tr '\n' ' ' | xargs -d ' ' -n 1 -i rm -f $(DESTDIR)/share/man/man1/{}
44+
45+

lib/Makefile

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
PYTHON_VERSION=2.7
2+
PYTHON_LIBS=FindPackage,GetAvailable,GuessLatest,CheckDependencies,DescribeProgram,UseFlags,Corrections,Alien
3+
PYTHON_SITE=python$(PYTHON_VERSION)/site-packages
4+
DESTDIR?=
5+
6+
all:
7+
8+
install: python_install
9+
10+
uninstall: python_uninstall
11+
ifndef DESTDIR
12+
$(error DESTDIR is not set)
13+
endif
14+
@echo "Uninstalling libraries"
15+
@rm -rf $(DESTDIR)/lib
16+
17+
python_install:
18+
@echo "Installing python libraries"
19+
ifndef DESTDIR
20+
$(error DESTDIR is not set)
21+
endif
22+
@mkdir -p $(DESTDIR)/lib/$(PYTHON_SITE)
23+
@echo $(PYTHON_LIBS) | tr '\n' '\0' | xargs -d, -I {} \
24+
ln -nfs $(DESTDIR)/bin/{} $(DESTDIR)/lib/$(PYTHON_SITE)
25+
@cp python/*.py $(DESTDIR)/lib/$(PYTHON_SITE)
26+
27+
python_uninstall:
28+
@echo "Uninstalling python libraries"
29+
ifndef DESTDIR
30+
$(error DESTDIR is not set)
31+
endif
32+
@echo $(PYTHON_LIBS) | tr '\n' '\0' | xargs -d, -I {} \
33+
rm -f $(DESTDIR)/lib/$(PYTHON_SITE)/{}
34+
rm -f $(DESTDIR)/lib/$(PYTHON_SITE)/GuessProgramCase.py
35+
rm -f $(DESTDIR)/lib/$(PYTHON_SITE)/PythonUtils.py
36+
37+
clean:

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

+41-22
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))
1526
dynamic_exec = SuperUserName IsExecutable usleep LinkOrExpandAll List CommandNotFound GetSupportedFilesystems
1627
static_exec = RescueSymlinkProgram
1728
other_exec = FindDependencies Runner
1829

1930
# first rule
20-
default: all
2131

22-
.PHONY: all default
32+
.PHONY: all clean static debug install
2333

2434
all: $(dynamic_exec) $(static_exec) $(other_exec)
2535

2636
$(dynamic_exec): %: %.c
27-
$(CC) $(MYCFLAGS) $< -o $@
37+
@echo "Compiling $@"
38+
@$(CC) $(CFLAGS) $< -o $@
2839
@if [ -e "$@.exe" ]; then \
2940
mv $@.exe $@; \
3041
fi
3142

3243
$(static_exec): %: %.c
33-
$(CC) $(MYCFLAGS) $< -o $@ $(STATIC)
44+
@echo "Compiling $@"
45+
@$(CC) $(STATIC_CFLAGS) $< -o $@
3446
@if [ -e "$@.exe" ]; then \
3547
mv $@.exe $@; \
3648
fi
3749

3850
FindDependencies: %: %.c
39-
$(CC) $(MYCFLAGS) $< -o $@ -DBUILD_MAIN
51+
@echo "Compiling $@"
52+
@$(CC) $(CFLAGS) $< -o $@ -DBUILD_MAIN
4053

4154
Runner: Runner.c FindDependencies.c
42-
$(CC) $(MYCFLAGS) $^ -o $@
43-
chmod 4755 $@
55+
@echo "Compiling $@"
56+
@$(CC) $(CFLAGS) $^ -o $@
4457

45-
debug: MYCFLAGS = -g -DDEBUG -Wall
46-
debug: all
58+
clean:
59+
@echo "Cleaning sources"
60+
@rm -f $(dynamic_exec) $(static_exec) $(other_exec) lib*.so lib*.so.* *.o
61+
@$(RM_EXE)
4762

48-
static: MYCFLAGS = $(STATIC)
49-
static: all
63+
install: all
64+
@echo "Installing compiled binaries"
65+
ifndef DESTDIR
66+
$(error DESTDIR is not set)
67+
endif
68+
@$(INSTALL_DIR) -d -m 755 $(DESTDIR)/bin
69+
@echo $(exec_files) | tr '\n' ' ' | xargs -0 -d ' ' -i $(INSTALL_FILE) -m 755 {} $(DESTDIR)/bin
70+
@chmod 4755 $(DESTDIR)/bin/Runner
5071

51-
clean:
52-
rm -f $(dynamic_exec) $(static_exec) $(other_exec) lib*.so lib*.so.* *.o
53-
$(RM_EXE)
72+
uninstall:
73+
@echo $(exec_files) | tr '\n' ' ' | xargs -0 -d ' ' -i rm -f $(DESTDIR)/bin/{}
5474

55-
.PHONY: all clean static debug install

0 commit comments

Comments
 (0)