Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Makefile: Neukompilieren auch bei Änderungen in .hpp
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum
View previous topic :: View next topic  
Author Message
manuels
Advocate
Advocate


Joined: 22 Nov 2003
Posts: 2146
Location: Europe

PostPosted: Wed Aug 25, 2010 10:30 am    Post subject: Makefile: Neukompilieren auch bei Änderungen in .hpp Reply with quote

Moin,

ich schreibe ein C++-Programm, das stark auf Templates setzt.
Diese sind in .hpp-Dateien definiert.
Normalerweise kompiliert make ja nur .cpp Dateien automatisch neu, wenn diese sich geändert haben.
Ich möchte aber, dass dies auch bei Änderungen in .hpp-Dateien geschieht.

Da make aber keine Ahnung hat, welche .cpp-Datei es kompilieren muss, wenn sich eine .hpp-Datei geändert hat, ist dies wahrscheinlich so gar nicht möglich, oder?

Zur Not würde es auch ein automatisches "make clean" tun, wenn sich eine .hpp-Datei ändert.

Habt ihr ne Idee, wie das funktionieren könnte?
_________________
Build your own live cd with catalyst 2.0!
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4565

PostPosted: Wed Aug 25, 2010 10:52 am    Post subject: Reply with quote

Kannst du dein Header.hpp beim target als Abhängigkeit eintragen?
Ich hab bisher nur für ganz primitive Versuche ein eigenes Makefile geschrieben, sonst verwende ich cmake. In einem Makefile staht dann sowas drin:
Code:
CMakeFiles/test.dir/main.cpp.o: Header.hpp

Und es wird main.cpp neu kompiliert, wenn sich der Header ändert.
Back to top
View user's profile Send private message
manuels
Advocate
Advocate


Joined: 22 Nov 2003
Posts: 2146
Location: Europe

PostPosted: Wed Aug 25, 2010 11:04 am    Post subject: Reply with quote

Mist, merke gerade, dass es doch noch etwas komplizierter wird:
Die .hpp-Dateien liegen in anderen Verzeichnissen. Alle aufzulisten wäre zu mühsam.
Es gibt doch irgendein Tool, das die Include-Dateien auflistet. Wie ging das nochmal?
Wenn ich das mit deinem Ansatz verbinde, sollte es klappen.

Edit: es war "g++ -M file.cpp"
Nun muss ich allerdings noch für alle .cpp-Dateien die Dependencies quasi dynamisch über den o.g. Befehl erstellen lassen.
Wie stellt man denn das nun schon wieder an?
_________________
Build your own live cd with catalyst 2.0!
Back to top
View user's profile Send private message
Necoro
Veteran
Veteran


Joined: 18 Dec 2005
Posts: 1912
Location: Germany

PostPosted: Wed Aug 25, 2010 11:52 am    Post subject: Reply with quote

Google einfach mal ... vor diesem Problem steht jeder der Makefiles schreibt früher oder später :D.

Alternative wäre ein besseres Buildsystem. Scons sollte sowas direkt können ohne hacks. autotools denke ich mal auch. cmake weiß ich nicht.
_________________
Inter Deum Et Diabolum Semper Musica Est.
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4565

PostPosted: Wed Aug 25, 2010 11:57 am    Post subject: Reply with quote

Necoro wrote:
cmake weiß ich nicht.

Ja, tut es.
Back to top
View user's profile Send private message
manuels
Advocate
Advocate


Joined: 22 Nov 2003
Posts: 2146
Location: Europe

PostPosted: Wed Aug 25, 2010 12:27 pm    Post subject: Reply with quote

da das Programm auf verschiedensten Rechnern kompiliert werden soll, kann ich auf cmake nicht zurückgreifen.
_________________
Build your own live cd with catalyst 2.0!
Back to top
View user's profile Send private message
Necoro
Veteran
Veteran


Joined: 18 Dec 2005
Posts: 1912
Location: Germany

PostPosted: Wed Aug 25, 2010 1:23 pm    Post subject: Reply with quote

wie gesagt: google mal. gibt tausendundein programm/snippet was ein "dependency tracking" für normales make implementiert.

/edit: oder halt autotools :) ... das sollte bis auf windows überall lauffähig sein
_________________
Inter Deum Et Diabolum Semper Musica Est.
Back to top
View user's profile Send private message
franzf
Advocate
Advocate


Joined: 29 Mar 2005
Posts: 4565

PostPosted: Wed Aug 25, 2010 1:47 pm    Post subject: Reply with quote

Ich denke, cmake läuft auf (fast) allen Plattformen.
Aber wurscht :P
Hier mal ein erster Ansatz eines totalen Noobs ;)
Makefile:
Code:
all:    main

main: compile_dependencies
        g++ main.o -o main

compile_dependencies: create_dependencies
        make -f main_deps main.o

create_dependencies:
        ./create_dep_helper "main.o" "main.cpp" "main_deps"

create_dep_helper
Code:
#!/bin/bash
echo "write dependencies for $2 to target $1 in fil $3"

echo "$1:" > $3
echo "  g++ -o $1 -c $2" >> $3
echo $(g++ -MM $2) >> $3

Das kann man aber sicherlich noch verbessern...
Back to top
View user's profile Send private message
Necoro
Veteran
Veteran


Joined: 18 Dec 2005
Posts: 1912
Location: Germany

PostPosted: Wed Aug 25, 2010 2:37 pm    Post subject: Reply with quote

Wie gesagt ... googeln :P

Bringt zB diesen Abschnitt aus dem GNU Make Manual: http://www.gnu.org/software/automake/manual/make/Automatic-Prerequisites.html
_________________
Inter Deum Et Diabolum Semper Musica Est.
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6780

PostPosted: Wed Aug 25, 2010 5:36 pm    Post subject: Reply with quote

Wer ein Makefile für ein nichttriviales Projekt von Hand schreibt, ist selbst schuld: man autotools.
Back to top
View user's profile Send private message
manuels
Advocate
Advocate


Joined: 22 Nov 2003
Posts: 2146
Location: Europe

PostPosted: Thu Aug 26, 2010 10:22 am    Post subject: Reply with quote

franzf wrote:
Ich denke, cmake läuft auf (fast) allen Plattformen.

Ja, aber leider ist es auf vielen Rechnern, auf denen ich das Programm kompilieren muss nicht installiert.
Da sind nur die "Unix-Basics" drauf und Root-Rechte habe ich nicht (cmake ins Home-Verzeichnis zu installieren wäre eine Möglichkeit, aber auch ein bisschen umständlich dies für jeden Rechner zu machen).

Werde mir wohl mal die autotools anschauen müssen. Für mich war ./configure immer eine "magische Blackbox"...
_________________
Build your own live cd with catalyst 2.0!
Back to top
View user's profile Send private message
mv
Watchman
Watchman


Joined: 20 Apr 2005
Posts: 6780

PostPosted: Thu Aug 26, 2010 5:19 pm    Post subject: Reply with quote

manuels wrote:
Werde mir wohl mal die autotools anschauen müssen. Für mich war ./configure immer eine "magische Blackbox"...

Das ist inzwischen gar nicht schwer, weil die Dokumentation mittlerweile brauchbar ist. Wenn Du keine Spirenzchien brauchst, musst Du i.W. in automake.am nur einer Variable Deine Liste mit Source-Files zuweisen und in autoconf.ac eine Standard-Initialisierung benutzen.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Deutsches Forum (German) Diskussionsforum All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum